Applying higher compression to PDF files

chrispitude
Posts: 328
Joined: Thu May 02, 2019 2:32 pm

Applying higher compression to PDF files

Post by chrispitude » Wed Jan 13, 2021 6:50 pm

Hi everyone,

This is a follow-up to

"Using a more recent PDF version for PDF production"
topic21147.html

I have a 1200 page book with many figures. When I compare -Dpdf.version=1.4 to -Dpdf.version=1.5, I see a definite size reduction:

Code: Select all

33036 -rw-rw-rw- 1 doc src 33688601 Jan 13 07:19 o14/ptug.pdf
21612 -rw-rw-rw- 1 doc src 22033988 Jan 13 07:23 o15/ptug.pdf
However, when I compress the PDF with Ghostscript (or any one of the many available PDF compression utilities):

Code: Select all

/depot/Ghostscript/ghostscript-9.53.3/bin/gs -sDEVICE=pdfwrite \
 -dPDFSETTINGS=/printer \
 -dPrinted=false \
 -dCompatibilityLevel=1.5 \
 -dEmbedAllFonts=true \
 -dSubsetFonts=true \
 -dFastWebView=true \
 -dNOPAUSE -dQUIET -dBATCH \
 -sOutputFile='FILE_opt.pdf' \
  'FILE.pdf'
I see that much more reduction is still available:

Code: Select all

33036 -rw-rw-rw- 1 doc src 33688601 Jan 13 07:19 o14/ptug.pdf
14640 -rw-rw-rw- 1 doc src 14925393 Jan 13 07:30 o14/ptug_opt.pdf

21612 -rw-rw-rw- 1 doc src 22033988 Jan 13 07:23 o15/ptug.pdf
14640 -rw-rw-rw- 1 doc src 14925393 Jan 13 07:30 o15/ptug_opt.pdf
Even starting from the PDF v1.5 file, I can still reduce the file size from 22MB to 15MB.

In an Adobe FrameMaker flow, Adobe PDF Distiller (the actual PDF generation engine) provides fine control over PDF compression options. Even with PDF version v1.5 (a big step forward!), PDF Chemistry PDFs are larger than the correspond FrameMaker PDFs.

In our production flow (linux), we have a bash shell batch file that runs Ghostscript as a post-processing operation to get the size reduction.

But when our writers create PDFs on their Windows laptops, there's no easy way of doing that.

There's a neat commercial pure-Java PDF compression utility here:

https://www.pdftron.com/documentation/s ... imizerTest

This would work across all platforms. Or maybe there's an open-source Java PDF compression utility floating around?

chrispitude
Posts: 328
Joined: Thu May 02, 2019 2:32 pm

Re: Applying higher compression to PDF files

Post by chrispitude » Thu Jan 14, 2021 3:29 pm

I also thought about pursuing better compression with the Apache FOP folks, but I wonder if they might want to stay focused on page layout and not get into the intricacies of optimizing PDF data structures. (Or maybe I'm wrong and they'd want to improve in this area too?)

Dan
Posts: 484
Joined: Mon Feb 03, 2003 10:56 am

Re: Applying higher compression to PDF files

Post by Dan » Fri Jan 15, 2021 11:24 am

I recorded an issue about trying to reduce the size of the PDF files. The PDF Box: https://pdfbox.apache.org/ library can handle PDF and can load and resave them with other compression settings, maybe you can try it.

Post Reply