Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Mar 12, 2015 9:41 am

Hi,

I am not able to create multiple pdf font style with new version 3.2.102.5040 but with old version it was working fine,
PFB sample code

Please suggest any work around for this issue how to create multiple font style.

Thanks
Gaurav M.

Code: Select all
Dim pdf As New PdfDocument
        Dim page As PdfPageBase = pdf.Pages.Add()

        Dim font As String = "Arial"

        Dim BlackBrush As PdfBrush = PdfBrushes.Black
        Dim SmallestFont As New PdfTrueTypeFont(New Font(font, 5.0F, FontStyle.Regular))
        Dim x As Integer = 100
        Dim SmallFont As PdfTrueTypeFont = New PdfTrueTypeFont(New Font(font, 7, FontStyle.Regular))
        Dim y As Integer = 100
        Dim ContentFont As PdfTrueTypeFont = New PdfTrueTypeFont(New Font(font, 8, FontStyle.Regular))
        Dim HeadingFont As PdfTrueTypeFont = New PdfTrueTypeFont(New Font(font, 9, FontStyle.Regular))
        Dim HeaderFont As PdfTrueTypeFont = New PdfTrueTypeFont(New Font(font, 12, FontStyle.Regular))


        page.Canvas.DrawString("Spire 3.2.106 Test Application", SmallestFont, BlackBrush, x, y)
        y += SmallestFont.Height + 5

        page.Canvas.DrawString("Spire 3.2.106 Test Application", SmallFont, BlackBrush, x, y)
        y += SmallFont.Height + 5

        page.Canvas.DrawString("Spire 3.2.106 Test Application", ContentFont, BlackBrush, x, y)
        y += ContentFont.Height + 5

        page.Canvas.DrawString("Spire 3.2.106 Test Application", HeadingFont, BlackBrush, x, y)
        y += HeadingFont.Height + 5

        page.Canvas.DrawString("Spire 3.2.106 Test Application", HeaderFont, BlackBrush, x, y)
        y += HeaderFont.Height + 5

        y = y + 16.0F
        Dim trueTypeFont As New PdfTrueTypeFont(New Font(font, 5.0F, FontStyle.Regular))
        page.Canvas.DrawString("Spire 3.2.106 Test Application", trueTypeFont, BlackBrush, x, y)


        pdf.SaveToFile("Test.pdf")

        Process.Start("Test.pdf")

gauravmaheshwari57
 
Posts: 2
Joined: Wed Dec 17, 2014 5:21 am

Fri Mar 13, 2015 6:43 am

Hello,

Thanks for your inquiry.
When you create the "Arial" font at the first time, it will create the font cache. And when you create another "Arial" font in different size, it will take the font object from the cache and change the font cache size to the new size. That's the reason why you got the same font style in the first four paragraphs.

To prevent it, you must use "Arial" font before another "Arial" font is created. Here is the code snippet you can refer to :
Code: Select all
Dim pdf As New PdfDocument()
Dim page As PdfPageBase = pdf.Pages.Add()
Dim font As String = "Arial"
Dim x As Integer = 100
Dim y As Integer = 100
Dim BlackBrush As PdfBrush = PdfBrushes.Black
Dim SmallestFont As New PdfTrueTypeFont(New Font(font, 5F, FontStyle.Regular))
page.Canvas.DrawString("Spire 3.2.106 Test Application", SmallestFont, BlackBrush, x, y)
y += CInt(SmallestFont.Height) + 5

Dim SmallFont As New PdfTrueTypeFont(New Font(font, 7F, FontStyle.Regular))
page.Canvas.DrawString("Spire 3.2.106 Test Application", SmallFont, BlackBrush, x, y)
y += CInt(SmallFont.MeasureString("Spire 3.2.106 Test Application").Height) + 5

Dim ContentFont As New PdfTrueTypeFont(New Font(font, 10F, FontStyle.Regular))
page.Canvas.DrawString("Spire 3.2.106 Test Application", ContentFont, BlackBrush, x, y)
y += CInt(SmallFont.MeasureString("Spire 3.2.106 Test Application").Height) + 5

Dim HeadingFont As New PdfTrueTypeFont(New Font(font, 20F, FontStyle.Regular))
page.Canvas.DrawString("Spire 3.2.106 Test Application", HeadingFont, BlackBrush, x, y)
y += CInt(SmallFont.MeasureString("Spire 3.2.106 Test Application").Height) + 5

Dim HeaderFont As New PdfTrueTypeFont(New Font(font, 30F, FontStyle.Regular))
page.Canvas.DrawString("Spire 3.2.106 Test Application", HeaderFont, BlackBrush, x, y)
y += CInt(SmallFont.MeasureString("Spire 3.2.106 Test Application").Height) + 5
y = y + 16
Dim trueTypeFont As New PdfTrueTypeFont(New Font(font, 50F, FontStyle.Regular))
page.Canvas.DrawString("Spire 3.2.106 Test Application", trueTypeFont, BlackBrush, x, y)

pdf.SaveToFile("Test.pdf")
Process.Start("Test.pdf")

If there are any questions, welcome to get it back to us.

Best Regards,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Tue Mar 17, 2015 7:50 am

Hello,

Have you tried the codes I provided? Has your issue been resolved? Could you please give us some feedback at your convenience?

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Thu Mar 26, 2015 6:59 am

Hi,

Thanks for your information, I tried your method and its working fine.

Thanks
Gaurav M.

gauravmaheshwari57
 
Posts: 2
Joined: Wed Dec 17, 2014 5:21 am

Thu Mar 26, 2015 7:14 am

Hello,

Please feel free to contact us if you have any questions or needs.

Best Regards,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Tue Nov 01, 2016 10:13 pm

Hey Betsy, I know this question was posted a long time ago, but I have some additional questions regarding the topic. I am working on drawing a PDF that is created in sections whose content and order is dependent upon what the user decides should be in the document. Because of this, it isn't possible for me to write everything I need before moving on to the next font size as I each section uses multiple sizes and they are not necessarily in the same order every time.

Is there any workaround for this? I got by in the past by using PdfFonts instead of PdfTrueTypeFonts for my secondary fonts as that didn't have this cache issue but I'd really prefer to use different fonts than that will allow. Thanks!

D.R.

DR_404
 
Posts: 1
Joined: Tue Nov 01, 2016 9:59 pm

Wed Nov 02, 2016 3:01 am

Hi D.R.,

Thanks for your inquiry.
The cache issue of PdfTrueTypeFonts had been fixed in the latest version, please try to use Spire.PDF Pack(Hot Fix) Version:3.8.45. If there is still issue, please provide us the code snippet for investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Nov 04, 2016 8:06 am

Hi D.R.,

Did you test the hotfix ? Has your issue been resolved ?

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDF