[reportlab-users] PDF Report size too large

Jean-Yves F. Barbier 12ukwn at gmail.com
Mon Jan 23 15:30:57 EST 2012

On Sat, 21 Jan 2012 05:15:14 +0000
Asif Jamadar <asif.jamadar at rezayat.net> wrote:

> I'm using Reportlab tool to generate dynamic PDF.

> The generated PDF consist of 1 or 2 pages but the size this PDF

> reached to 5 MB. How can I decrease the size of the generate PDF.


> I want to decrease the size to max 500 TB. IS there any way to

> accomplish this thing in reportlab?

This is finally a good question, indeed - so I made some tests.

Greping RL code shows that it use zlib; if it's a good &
fast compression technique for communications it is not
as good for file compression.

I didn't wanted to modify RL code, so I found this way:
* create an uncompressed PDF w/RL
* transform it to PostScript
* re-transform PS to PDF

It lowered an already RL compressed PDF from 258kB to 74kB
(3.5x less) - but the chances to lower to 500kB from 5 MB
are very low...

I do it with utilities included into the ghostscript package:
pdf2ps & ps2pdf - Total time taken by the following script is
~1.7s on my old AthlonXP-1600+:



# Transform a PDF to PS and rebuild a hi compression rate PDF from PS

# Efficiency: An already compressed PDF generated by Reportab was 258kB:
# one jpeg + ~1/3 page text, org jpeg size: 113kB
# After processing it is 74kB (3.5x less)

if [ -z $1 ]
echo ""
echo "PDF High rate recompression"
echo ""
echo " Usage: RECOMPRESS_PDF.sh myPDFtoRecompress.pdf"
echo ""
echo " NB: Destroy the original PDF."
echo ""
# PDF => PS
pdf2ps $1 ${PS}
# PS => PDF (org)
ps2pdf ${PS} $1
# Remove PS file
rm ${PS}

Incest, n:
Sibling revelry; a sport the whole family can enjoy.

More information about the reportlab-users mailing list