Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - AddTrueTypeFont Function throws Exception
  FAQ FAQ  Forum Search   Register Register  Login Login

AddTrueTypeFont Function throws Exception

 Post Reply Post Reply
Author
Message
MoneyRan View Drop Down
Beginner
Beginner


Joined: 11 Aug 11
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote MoneyRan Quote  Post ReplyReply Direct Link To This Post Topic: AddTrueTypeFont Function throws Exception
    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.


Edited by MoneyRan - 24 Nov 11 at 9:01PM
Back to Top
Wheeley View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 Oct 05
Location: United States
Status: Offline
Points: 146
Post Options Post Options   Thanks (0) Thanks(0)   Quote Wheeley Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
MoneyRan View Drop Down
Beginner
Beginner


Joined: 11 Aug 11
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote MoneyRan Quote  Post ReplyReply Direct Link To This Post 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.


Edited by MoneyRan - 24 Nov 11 at 7:36PM
Back to Top
MoneyRan View Drop Down
Beginner
Beginner


Joined: 11 Aug 11
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote MoneyRan Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Wheeley View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 Oct 05
Location: United States
Status: Offline
Points: 146
Post Options Post Options   Thanks (0) Thanks(0)   Quote Wheeley Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
MoneyRan View Drop Down
Beginner
Beginner


Joined: 11 Aug 11
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote MoneyRan Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store