简体   繁体   中英

Size of pdf generated with reportLab

I have a problem with the generation of my pdf.

When I generate a pdf and after few minute when I restart the same script to generate the same pdf I don't have the same size between my first pdf and the second...

this is my code :

c = reportlab.pdfgen.canvas.Canvas("test.pdf")
c.showPage()
c.save()

The first pdf have : 1519 byte

And the second have 1531 byte

Whenever I restart the same script and whenever I have differents value. Why? How can I resolve it?

I don't see your problem of the PDF changing size, but its contents are changing:

$ python make_pdf.py && md5sum test.pdf
9a1dbc5621622526b4411fb5f818246e  test.pdf
$ python make_pdf.py && md5sum test.pdf
b4c3ef4661c2a0f7d5c458757ac8a891  test.pdf
$

Following the hint from your comment, setting the invariant option solves that.

import reportlab.pdfgen.canvas
import reportlab.rl_config

reportlab.rl_config.invariant = 1
c = reportlab.pdfgen.canvas.Canvas("test.pdf")
c.showPage()
c.save()

Now the contents don't change, because the PDF doesn't get a generated id, and the timestamp is set to 0:00 01 Jan 2000 UTC.

$ python make_pdf.py && md5sum test.pdf
4a0ecf533e69fc2a91cda0a055cbec58  test.pdf
$ python make_pdf.py && md5sum test.pdf
4a0ecf533e69fc2a91cda0a055cbec58  test.pdf
$

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM