I create a simple PDF file using iTextSharp. Is working fine.
Now I want the user can change the style or theme. The user choose from a dialog box: Normal, Elegant, Modern and then some fonts of the PDF needs to change to suit the style or theme desired.
The PDF create Sub have something like:
'Define fontLetterSeparator
Dim fontLetterSeparator As New Font(BaseFont.CreateFont("c:/windows/fonts/comic.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED), 18)
'Define letter separator paragraph
Dim letterSeparator As New Chunk(ActualLetter, fontLetterSeparator)
Where ActualLetter is just a letter like A, B, C... (reading from the SQLite database, no problem whit this)
One way I think I can manage the 3 styles or themes is with code like
If PDFTheme = "Normal" Then
Dim fontLetterSeparator As New Font(BaseFont.CreateFont("c:/windows/fonts/arial.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED), 20)
End If
If PDFTheme = "Elegant" Then
Dim fontLetterSeparator As New Font(BaseFont.CreateFont("c:/windows/fonts/verdana.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED), 20)
End If
If PDFTheme = "Modern" Then
Dim fontLetterSeparator As New Font(BaseFont.CreateFont("c:/windows/fonts/comic.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED), 60)
End If
But this didn't work, I think is because of font immutable condition. So I think the solution is with 3 new fonts or new instances instead
Dim fontLetterSeparatorNormal As New fontLetterSeparator
fontLetterSeparatorNormal.Name = "Arial"
Dim fontLetterSeparatorElegant As New fontLetterSeparator
fontLetterSeparatorElegant.Name = "Verdana"
Dim fontLetterSeparatorModern As New fontLetterSeparator
fontLetterSeparatorModern.Name = "Comic"
and so on with the size condition but this makes the original line
'Define letter separator paragraph
'Dim letterSeparator As New Chunk(ActualLetter, fontLetterSeparator)
more complicated because now I need another block of 3 IF - Then to choose the right font for each style or theme...
I'm sure there's gonna be a more simple and clean solution but I can´t figure it out