PDF File Size Larger than Expected

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
rsb
I live to help wx-kind
I live to help wx-kind
Posts: 170
Joined: Fri May 29, 2015 7:26 pm

PDF File Size Larger than Expected

Post by rsb »

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
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: PDF File Size Larger than Expected

Post by ONEEYEMAN »

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.
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: PDF File Size Larger than Expected

Post by utelle »

ONEEYEMAN wrote: Tue Sep 24, 2019 2:28 pm Ulrich is not checking this forum frequently.
Well, I check the wxWidgets forum almost daily - unless I'm out of office, or on vacation, or whatever distracts me ...
ONEEYEMAN wrote: Tue Sep 24, 2019 2:28 pm Please either send something on wxCode forum or use GitHub and open an issue there.
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.
rsb
I live to help wx-kind
I live to help wx-kind
Posts: 170
Joined: Fri May 29, 2015 7:26 pm

Re: PDF File Size Larger than Expected

Post by rsb »

This is the wxCode forum. Isn't it?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: PDF File Size Larger than Expected

Post by ONEEYEMAN »

Ulrich,
utelle wrote: Tue Sep 24, 2019 6:47 pm
ONEEYEMAN wrote: Tue Sep 24, 2019 2:28 pm Ulrich is not checking this forum frequently.
Well, I check the wxWidgets forum almost daily - unless I'm out of office, or on vacation, or whatever distracts me ...
I am sorry to step in.
I just copy the advice from another thread in thread in the same sub-forum.

Thank you.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: PDF File Size Larger than Expected

Post by ONEEYEMAN »

Hi,
rsb wrote: Tue Sep 24, 2019 7:00 pm This is the wxCode forum. Isn't it?
No, this is wxWidgets forum.
You should check here.

Thank you.
Last edited by ONEEYEMAN on Tue Sep 24, 2019 7:16 pm, edited 1 time in total.
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: PDF File Size Larger than Expected

Post by utelle »

rsb wrote: Tue Sep 24, 2019 1:29 pm We're getting file sizes larger than when printing using the wxPrinter class.
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.
rsb wrote: Tue Sep 24, 2019 1:29 pm 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.
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.
rsb wrote: Tue Sep 24, 2019 1:29 pm 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.
Maybe the above hint (calling wxPdfDC::SetImageType(xBITMAP_TYPE_JPEG)) already solves your issue sufficiently well.
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: PDF File Size Larger than Expected

Post by utelle »

ONEEYEMAN wrote: Tue Sep 24, 2019 7:02 pm Ulrich,
utelle wrote: Tue Sep 24, 2019 6:47 pm
ONEEYEMAN wrote: Tue Sep 24, 2019 2:28 pm Ulrich is not checking this forum frequently.
Well, I check the wxWidgets forum almost daily - unless I'm out of office, or on vacation, or whatever distracts me ...
I am sorry to step in.
I just copy the advice from another thread in thread in the same sub-forum.
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.
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: PDF File Size Larger than Expected

Post by utelle »

ONEEYEMAN wrote: Tue Sep 24, 2019 7:05 pm Hi,
rsb wrote: Tue Sep 24, 2019 7:00 pm This is the wxCode forum. Isn't it?
No, this is wxWidgets forum.
You should check here.
The above link gets you a "page not found error", so I don't know to which forum you are referring.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: PDF File Size Larger than Expected

Post by ONEEYEMAN »

Sorry,
The correct link is here.

Original reply is also fixed.

Thank you.
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: PDF File Size Larger than Expected

Post by utelle »

ONEEYEMAN wrote: Tue Sep 24, 2019 7:17 pm The correct link is here.
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.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: PDF File Size Larger than Expected

Post by ONEEYEMAN »

Ulrich,
I simply posted your own suggestion from here which is dated 5 SEP 2019.

Thank you.
rsb
I live to help wx-kind
I live to help wx-kind
Posts: 170
Joined: Fri May 29, 2015 7:26 pm

Re: PDF File Size Larger than Expected

Post by rsb »

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.
Attachments
PDF_FILES.7z
(400.2 KiB) Downloaded 188 times
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: PDF File Size Larger than Expected

Post by utelle »

rsb wrote: Tue Sep 24, 2019 7:39 pm Ok, Thanks, I'll use GitHub in the future.
As you see I respond on this forum, too, and usually also in a rather timely fashion.
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)
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.

I will look into this issue. However, it may take some time to implement the necessary optimizations.
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: PDF File Size Larger than Expected

Post by utelle »

ONEEYEMAN wrote: Tue Sep 24, 2019 7:35 pm I simply posted your own suggestion from here which is dated 5 SEP 2019.
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.
Post Reply