Re: wxPdfdocument

98 views
Skip to first unread message

utelle

unread,
Jul 2, 2012, 5:22:02 PM7/2/12
to wx-u...@googlegroups.com


On Monday, July 2, 2012 11:20:36 AM UTC+2, Svenne wrote:
We have an application that create a large number of pdf-documents. Suddenly the pdf-files get corrupt because fonts are missing (?). I attach a the last readable and the first corrupt pdf-file. Anyone who has an idea?

In the corrupt pdf file the font data for both used fonts are missing. In the corrupted pdf file the data lengths are given as 0 and the associated data streams are empty. Do you get any error message from wxPdfDocument?

Without seeing the code generating the pdf files it's hard to tell what's going wrong.

Regards,

Ulrich
 

Svenne

unread,
Jul 3, 2012, 2:35:04 AM7/3/12
to wx-u...@googlegroups.com

Thanks for the response!

Some background. We generate a lot of pdf from our application. I saw that
after about 4000-5000 files this phenomena appeared. So I did create a test
loop just to hunt the bug. In this case the 4651 first files are OK and then
suddenly all files are corrupt with the same pattern. What I do is that I
create a pdfDC and then send graphics (line and polygons) and texts to that
DC and when the drawing is complete I do a SaveAsFile on the corresponding
pdfDocument. I have spend a lot of time to make sure that font objects are
reused all the time. Are there any known problems with font hanling?

Some details: For each new font I use
wxPdfFontManager::GetFontManager()->RegisterFont(*_font); (where _font is a
normal font that I use for drawing on the screen)
then I create a wxpdfFont and set that font to the pdfDocument in this way
_pdf->GetPdfDocument()->AddFont(_pdffont->GetFamily());
and I also set (when changed) the font to the DC with the method SetFont()

Regards,
Sven-Eric
> --
> Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
>
> To unsubscribe, send email to wx-users+u...@googlegroups.com
> or visit http://groups.google.com/group/wx-users
>

--
View this message in context: http://old.nabble.com/wxPdfdocument-tp34100806p34105695.html
Sent from the wxWidgets - Users mailing list archive at Nabble.com.

Eric Jensen

unread,
Jul 3, 2012, 4:12:50 AM7/3/12
to Svenne
Hello Svenne,

Tuesday, July 3, 2012, 8:35:04 AM, you wrote:

S> after about 4000-5000 files this phenomena appeared. So I did create a test
S> loop just to hunt the bug. In this case the 4651 first files are OK and then
S> suddenly all files are corrupt with the same pattern.
Are you running on Windows? This almost sounds like you're running out
of GDI handles. Can you check that in the taskmanager while the
program is running?

Eric


Svenne

unread,
Jul 3, 2012, 4:20:40 AM7/3/12
to wx-u...@googlegroups.com

I think that might be the problem, so my question is how to use pdfDocument
and pdfDC without running out of GDI memory or how to use those classes so
they reuse GDI handles in the best way. Because I do more or less the same
operation with the normal DC (against the screen) without any problems.


Regards, Sven-Eric
> --
> Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
>
> To unsubscribe, send email to wx-users+u...@googlegroups.com
> or visit http://groups.google.com/group/wx-users
>
>

--
View this message in context: http://old.nabble.com/wxPdfdocument-tp34100806p34106166.html

Eric Jensen

unread,
Jul 3, 2012, 5:15:39 AM7/3/12
to Svenne
Hello Svenne,

Tuesday, July 3, 2012, 10:20:40 AM, you wrote:

S> I think that might be the problem, so my question is how to use pdfDocument
S> and pdfDC without running out of GDI memory or how to use those classes so
S> they reuse GDI handles in the best way. Because I do more or less the same
S> operation with the normal DC (against the screen) without any problems.

First you need to confirm that a GDI handle leak is indeed the
problem. In the taskmanager, enable the column for GDI handles and
check if the value keeps increasing while your program runs.

Then you need to find out where exactly the leak comes from, could be
in your code, in wxPDFDocument or even in wxWidgets itself.

E.g you could strip down your code to the absolute minimum so that it
only creates blank PDFs and check if the problem still exists.

Eric







Svenne

unread,
Jul 3, 2012, 6:37:54 AM7/3/12
to wx-u...@googlegroups.com

Thanks Eric,

You are absolutely right, when I look at the GDI objects they are increasing
very fast. When I do the operations on a normal DC (repaint the screen a lot
of times) the numbers are not increasing. So my conclusion is that
wxPdfdocument or wxpdfDC is not handling the GDI objects so good. Do you
know how to use these objects so that they are reusing or releasing GDI
handlers?

Regards,
Sven-Eric



Eric Jensen-10 wrote:
>
> --
> Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
>
> To unsubscribe, send email to wx-users+u...@googlegroups.com
> or visit http://groups.google.com/group/wx-users
>
>

--
View this message in context: http://old.nabble.com/wxPdfdocument-tp34100806p34106795.html

utelle

unread,
Jul 3, 2012, 7:08:50 AM7/3/12
to wx-u...@googlegroups.com
On Tuesday, July 3, 2012 12:37:54 PM UTC+2, Svenne wrote:

You are absolutely right, when I look at the GDI objects they are increasing
very fast. When I do the operations on a normal DC (repaint the screen a lot
of times) the numbers are not increasing. So my conclusion is that
wxPdfdocument or wxpdfDC is not handling the GDI objects so good. Do you
know how to use these objects so that they are reusing or releasing GDI
handlers?

wxPdfDC doesn't make use of GDI objects (to the best of my knowledge), but method wxPdfFontParserTrueType::LoadTrueTypeFontStream does. You'll see in the code of this method the comment:

  // TODO: check whether clean up is needed in addition to deleting hdc

According to your observations obviously something needs to be done here. But I have to find out which Windows system function has to be used to properly clean up.

One way to avoid the problem would be to register the font files (.ttf files) of the fonts you are using at the beginning of your application with the wxPdfFontManager. Then the font data will be loaded from the .ttf file instead of using GDI font objects to get hold of the font data.
 
Regards,

Ulrich

utelle

unread,
Jul 3, 2012, 2:32:25 PM7/3/12
to wx-u...@googlegroups.com


On Tuesday, July 3, 2012 1:08:50 PM UTC+2, utelle wrote:
On Tuesday, July 3, 2012 12:37:54 PM UTC+2, Svenne wrote:

You are absolutely right, when I look at the GDI objects they are increasing
very fast. When I do the operations on a normal DC (repaint the screen a lot
of times) the numbers are not increasing. So my conclusion is that
wxPdfdocument or wxpdfDC is not handling the GDI objects so good. Do you
know how to use these objects so that they are reusing or releasing GDI
handlers?

wxPdfDC doesn't make use of GDI objects (to the best of my knowledge), but method wxPdfFontParserTrueType::LoadTrueTypeFontStream does. You'll see in the code of this method the comment:

  // TODO: check whether clean up is needed in addition to deleting hdc

According to your observations obviously something needs to be done here. But I have to find out which Windows system function has to be used to properly clean up.

I added a call to DeleteObject to clean up the allocated font object. You may download the modified source from

http://wxcode.svn.sourceforge.net/viewvc/wxcode/trunk/wxCode/components/wxpdfdoc/src/pdffontparsertruetype.cpp

Please give it a try. It should solve the problem.

Regards,

Ulrich
 

Svenne

unread,
Jul 4, 2012, 2:56:06 AM7/4/12
to wx-u...@googlegroups.com

Fantastic!

Many thanks for this quick help/support/fix!

Regards,
Sven-Eric
> --
> Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
>
> To unsubscribe, send email to wx-users+u...@googlegroups.com
> or visit http://groups.google.com/group/wx-users
>

--
View this message in context: http://old.nabble.com/wxPdfdocument-tp34100806p34111554.html
Reply all
Reply to author
Forward
0 new messages