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!
![]() |
AddTrueTypeFont Function throws Exception |
Post Reply
|
| Author | |
MoneyRan
Beginner
Joined: 11 Aug 11 Status: Offline Points: 15 |
Post Options
Thanks(0)
Quote Reply
Topic: AddTrueTypeFont Function throws ExceptionPosted: 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 |
|
![]() |
|
Wheeley
Senior Member
Joined: 30 Oct 05 Location: United States Status: Offline Points: 146 |
Post Options
Thanks(0)
Quote Reply
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 |
|
![]() |
|
AndrewC
Moderator Group
Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
Post Options
Thanks(0)
Quote Reply
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.
|
|
![]() |
|
MoneyRan
Beginner
Joined: 11 Aug 11 Status: Offline Points: 15 |
Post Options
Thanks(0)
Quote Reply
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 |
|
![]() |
|
MoneyRan
Beginner
Joined: 11 Aug 11 Status: Offline Points: 15 |
Post Options
Thanks(0)
Quote Reply
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.
|
|
![]() |
|
AndrewC
Moderator Group
Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
Post Options
Thanks(0)
Quote Reply
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.
|
|
![]() |
|
Wheeley
Senior Member
Joined: 30 Oct 05 Location: United States Status: Offline Points: 146 |
Post Options
Thanks(0)
Quote Reply
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 |
|
![]() |
|
MoneyRan
Beginner
Joined: 11 Aug 11 Status: Offline Points: 15 |
Post Options
Thanks(0)
Quote Reply
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.
|
|
![]() |
|
Post Reply
|
|
|
Tweet
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store