Print Page | Close Window

AddTrueTypeFont Function throws Exception

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2054
Printed Date: 08 Nov 25 at 4:26PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: AddTrueTypeFont Function throws Exception
Posted By: MoneyRan
Subject: AddTrueTypeFont Function throws Exception
Date Posted: 23 Nov 11 at 10:22PM
I get this error at the given line in the code:
 
System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception. at PDFWare.QuickPDFDLL0811.PDFLibrary.AddTrueTypeFont(String FontName, Int32 Embed)
 
QP.AddTrueTypeFont("Times New Roman", 1)
 
The weird thing is this line is inside a function that is being run iteratively and after about 180 iterations, it throws an error here.



Replies:
Posted By: Wheeley
Date Posted: 24 Nov 11 at 3:48AM
My first thought is why are you adding 180 fonts in the first place? It sounds like you need to restructure the routine. Maybe look for the font first before adding it. Lastly, I'm not 100% sure but I think Times New Romain is a standard font and doesn't need to be added.

Wheeley


Posted By: AndrewC
Date Posted: 24 Nov 11 at 1:31PM
System.Runtime.InteropServices.SEHException (0x80004005): is most likely running out of memory and causing QPL to crash.

Can you post some source code ?  180 fonts is a lot of fonts to embed in a PDF file.

Andrew.


Posted By: MoneyRan
Date Posted: 24 Nov 11 at 7:31PM

The function creates a new document in the beginning and adds the fonts, text size and origin in the beginning. Sorry if my initial question was not very clear. So I am only adding font in the beginning of the function and this function is called iteratively from outside. This is the function that's being called iteratively:

Public Function PrintApp(ByVal eid As Integer, ByVal cid As Integer, ByVal comments As String, ByVal filepath As String) As String
        Try
            Dim empsignature As String
            Dim currentyear As String = "2011"
            Using db = New BenefitsAdminDataContext
            '612 X 792
            QP.NewDocument()
            QP.SetOrigin(1)
            QP.SetTextAlign(1)
            QP.AddTrueTypeFont("Times New Roman", 1)
            QP.SetTextSize(12)
            QP.SetTextColor(0, 0, 139)
           
            Dim cdata = From c In db.Customers
                        Join e In db.Employees On e.CustomerID Equals c.CustomerID
                        Where e.EmployeeID = eid AndAlso e.CustomerID = cid
                        Select New With {.CustomerName = c.CustomerName}
            Dim cname As String = String.Empty
            For Each c In cdata
               ' code that prints all column information in given coordinates using DrawText function
            Next
                        QP.DrawText(306, 25, cname)
            QP.DrawLine(0, 45, 612, 45)
             QP.SaveToFile(filepath+"ApplicationConfirmation_"+c.Name+".pdf')
            End Using
           
        Catch ex As Exception
            SystemMessage.Text = ex.ToString()
        End Try

    End Function
 
So the calling function passes a new 'eid' parameter everytime it is called. There are about 400 eids in the table and after 180 eids are processed in the PrintApp function, I get this error on the AddTrueTypeFont line.


Posted By: MoneyRan
Date Posted: 24 Nov 11 at 7:57PM
Update: I commented out the line in the above function and it worked OK for all 400 eids. But what if I want to add a different font? Without the AddTrueTypeFont line, the documents got printed in Arial.


Posted By: AndrewC
Date Posted: 25 Nov 11 at 6:17AM
After the QP.SaveToFile you need to call QP.RemoveDocument(QP.SelectedDocument()); to free the document from memory.

You are creating hundreds of documents in memory but never releasing them.

Andrew.


Posted By: Wheeley
Date Posted: 26 Nov 11 at 2:40AM
Something else to try is using a standard font instead of adding a true type font. It will dramatically reduce your PDF size. In your case try AddStandardFont(8).

Wheeley


Posted By: MoneyRan
Date Posted: 05 Dec 11 at 11:04PM
Thanks for the suggestion. I replaced AddTrueTypeFont with AddStandardFont, and the exception disappeared. I also added the RemoveDocument line after SaveToFile. Works great now.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk