[reportlab-users] Reducing PDF File Size

91 views
Skip to first unread message

Joseph Dvorak

unread,
Mar 22, 2022, 5:36:01 PMMar 22
to reportl...@lists2.reportlab.com

 

I have a document with 4 pages, each having an image page .png background. There are 2 – 3 additional .png images of varying size on each page as well as a significant amount of text. The document also has 4 TT fonts beyond the built in fonts. I am using the open source version of ReportLab  version 3.6.5 and Python version 3.8.

 

ReportLab generates a document file of 3.4 MB.

 

How can I *significantly* reduce the size of the PDF file within ReportLab?

 

Thanks,

 

Joe

 

Lele Gaifax

unread,
Mar 23, 2022, 3:14:03 AMMar 23
to reportl...@lists2.reportlab.com
Joseph Dvorak <joseph...@cambiumassessment.com> writes:

> I have a document with 4 pages, each having an image page .png background.

> [...]


>
> ReportLab generates a document file of 3.4 MB.
>
> How can I *significantly* reduce the size of the PDF file within ReportLab?

Try converting those PNGs to JPGs: AFAICT, PDF has a specialized reader for
JPGs, while other formats are stored in base64/base85.

ciao, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
le...@metapensiero.it | -- Fortunato Depero, 1929.

_______________________________________________
reportlab-users mailing list
reportl...@lists2.reportlab.com
https://pairlist2.pair.net/mailman/listinfo/reportlab-users

Joseph Dvorak

unread,
Mar 23, 2022, 2:17:27 PMMar 23
to reportl...@lists2.reportlab.com

Lele,

 

Changing the images to JPG did it.

 

Thank you for the suggestion.

 

Joe Dvorak

Robin Becker

unread,
Mar 23, 2022, 2:27:27 PMMar 23
to reportl...@lists2.reportlab.com
On 23/03/2022 07:13, Lele Gaifax wrote:
> Joseph Dvorak <joseph...@cambiumassessment.com> writes:
>
>> I have a document with 4 pages, each having an image page .png background.
>> [...]
>>
>> ReportLab generates a document file of 3.4 MB.
>>
>> How can I *significantly* reduce the size of the PDF file within ReportLab?
>
> Try converting those PNGs to JPGs: AFAICT, PDF has a specialized reader for
> JPGs, while other formats are stored in base64/base85.
>
> ciao, lele.

In fact non-jpeg images are now mostly stored with 'Flate' compression

self.streamContent = zlib.compress(raw)

We used to use A85 to try and avoid lots of binary content in the file as old style mailers used to corrupt them.

The image sizes may dominate gilsize because people use high resolution images.
--
Robin Becker
Reply all
Reply to author
Forward
0 new messages