PDF File Size Larger than Expected
PDF File Size Larger than Expected
Hello,
We're getting file sizes larger than when printing using the wxPrinter class.
We have a fairly simple one page design and the size of the file created using wxPdfPrinter and wxPdfDC is 312KB.
The size using wxPrinter and output to Adobe is 47KB and the size using wxPrinter and output to BullZip
is 80KB.
Is there anyway to reduce the PDF file size. We have a customer that is questioning us about this and I'm
wondering if we're doing something wrong and is there some way to reduce the size programmatically.
Thanks.
wxWidgets: Version 3.1.0
OS: Windows 7 Pro
Compiler: Visual Studio 14
We're getting file sizes larger than when printing using the wxPrinter class.
We have a fairly simple one page design and the size of the file created using wxPdfPrinter and wxPdfDC is 312KB.
The size using wxPrinter and output to Adobe is 47KB and the size using wxPrinter and output to BullZip
is 80KB.
Is there anyway to reduce the PDF file size. We have a customer that is questioning us about this and I'm
wondering if we're doing something wrong and is there some way to reduce the size programmatically.
Thanks.
wxWidgets: Version 3.1.0
OS: Windows 7 Pro
Compiler: Visual Studio 14
Re: PDF File Size Larger than Expected
Hi,
Ulrich is not checking this forum frequently.
Please either send something on wxCode forum or use GitHub and open an issue there.
Thank you.
Ulrich is not checking this forum frequently.
Please either send something on wxCode forum or use GitHub and open an issue there.
Thank you.
Re: PDF File Size Larger than Expected
Well, I check the wxWidgets forum almost daily - unless I'm out of office, or on vacation, or whatever distracts me ...
This is for sure a good advice. The advantage on GitHub is that I will get a note via e-mail if a new issue is opened or a post is added to an existing issue.
Re: PDF File Size Larger than Expected
This is the wxCode forum. Isn't it?
Re: PDF File Size Larger than Expected
Ulrich,
I just copy the advice from another thread in thread in the same sub-forum.
Thank you.
I am sorry to step in.
I just copy the advice from another thread in thread in the same sub-forum.
Thank you.
Re: PDF File Size Larger than Expected
Last edited by ONEEYEMAN on Tue Sep 24, 2019 7:16 pm, edited 1 time in total.
Re: PDF File Size Larger than Expected
wxPdfDC does not perform any active optimization. Therefore it can easily happen that the resulting PDF size is larger.
The best results can usually be achieved if a PDF document is created directly via wxPdfDocument instead of using wxPdfDC. However, I understand that reusing wxDC code for PDF output reduces the programming effort.
Without seeing at least the resulting PDF file (optimally both variants - wxPdfDC and wxPrinter) it is very difficult to judge why the difference in size is so large. The most likely cause is the image format used to save wxImage/wxBitmap objects to PDF. The default format is PNG. However, the method wxPdfDC::SetImageType can be used to change that behaviour by selecting image type wxBITMAP_TYPE_JPEG. Using JPEG over PNG usually reduces the resulting PDF size considerably.
Maybe the above hint (calling wxPdfDC::SetImageType(xBITMAP_TYPE_JPEG)) already solves your issue sufficiently well.
Re: PDF File Size Larger than Expected
Obviously the question is what frequently means.
As said, I check this forum almost daily. That is, sometimes it may take a few days, sometimes even weeks, before I get the chance to post an answer.
Re: PDF File Size Larger than Expected
Unfortunately the wxCode project on SourceForge is effectively dead.
On the page displayed when you follow the link you will see the note:
Note: As of January 2018 this project has been retired.
My former wxCode projects wxSQLite3 and wxPdfDocument were moved to GitHub long ago. Therefore the most timely response can be expected, if issues are opened on GitHub.
Re: PDF File Size Larger than Expected
Ok, Thanks, I'll use GitHub in the future.
Here's a 7z file with the three PDF files that we generated.
Two use the wxPrinter class and the third uses the wxPdfPrinter class along with the wxPdfDC class.
BOARD_wxpdfprinter.pdf (size: 312KB)
BOARD_wxprinter_adobe.pdf (size: 47KB)
BOARD_wxprinter_bullzip.pdf (size: 80KB)
Thanks.
Here's a 7z file with the three PDF files that we generated.
Two use the wxPrinter class and the third uses the wxPdfPrinter class along with the wxPdfDC class.
BOARD_wxpdfprinter.pdf (size: 312KB)
BOARD_wxprinter_adobe.pdf (size: 47KB)
BOARD_wxprinter_bullzip.pdf (size: 80KB)
Thanks.
- Attachments
-
- PDF_FILES.7z
- (400.2 KiB) Downloaded 189 times
Re: PDF File Size Larger than Expected
As you see I respond on this forum, too, and usually also in a rather timely fashion.
Thanks. Obviously you are not using lots of wxImage/wxBitmap objects as I had suspected as a possible cause in my previous post. However, you draw a large number of small elements. The problem is that wxPdfDC is not optimized for such a use case. Most drawing operations explicitly set the draw and fill colors in the PDF output, even if they were not changed. And as you see this has a noticable impact on the resulting PDF size.rsb wrote: ↑Tue Sep 24, 2019 7:39 pm Here's a 7z file with the three PDF files that we generated.
Two use the wxPrinter class and the third uses the wxPdfPrinter class along with the wxPdfDC class.
BOARD_wxpdfprinter.pdf (size: 312KB)
BOARD_wxprinter_adobe.pdf (size: 47KB)
BOARD_wxprinter_bullzip.pdf (size: 80KB)
I will look into this issue. However, it may take some time to implement the necessary optimizations.
Re: PDF File Size Larger than Expected
In that case the original post was done in the more general C++ subforum. Since many posts are posted to that subforum, the post did not stay long enough on top of the list to catch my attention. Therefore I recommended to post in the wxCode subforum (or on GitHub), which is less active. I did not mention wxCode on SourceForge. BTW, the link "wxCode forum" on the wxCode SourceForge page simply points back to the wxCode subforum of this wxWidgets forum.