简体   繁体   English

使用reportLab生成的pdf大小

[英]Size of pdf generated with reportLab

I have a problem with the generation of my pdf. 我在生成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... 当我生成pdf并在几分钟后重新启动相同的脚本以生成相同的pdf时,我的第一个pdf和第二个pdf之间没有相同的大小...

this is my code : 这是我的代码:

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

The first pdf have : 1519 byte 第一个pdf有: 1519字节

And the second have 1531 byte 第二个有1531个字节

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: 我看不到您的PDF大小更改问题,但是其内容正在更改:

$ 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. 根据您的注释提示,设置invariant选项即可解决该问题。

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. 现在,内容不会更改,因为PDF没有获得生成的ID,并且时间戳记设置为2000 UTC Jan 01 UTC。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 reportlab 生成的 pdf 提供选项卡标题 - Provide tab title with reportlab generated pdf Unicode字符是Geraldo / ReportLab生成的PDF中的框 - Unicode characters are boxes in Geraldo/ReportLab generated PDF 是否可以在reportlab生成的pdf文档中插入pdf格式的图像? - Is it possible inserting pdf format image in a reportlab generated pdf document? 绘制到 reportlab pdf 的图像大于 pdf 纸张大小 - Image drawn to reportlab pdf bigger than pdf paper size 如何将生成的PDF与Reportlab附加到App Engine Python中的电子邮件中 - How to attach generated PDF with Reportlab to Email in App Engine Python Django / reportlab:将生成的pdf直接保存到AWS s3中的FileField - Django/reportlab: Save generated pdf directly to FileField in AWS s3 是否可以在ReportLab生成的PDF中包含OpenOffice Writer或MS Word数据? - Is it possible to include OpenOffice Writer or MS Word data in a ReportLab generated PDF? 使用reportlab生成的pdf文件,另存为纯文本 - pdf file generated using reportlab , getting saved as plain text 在reportlab中生成的pdf报告与原始文本数据不同 - Generated pdf report in reportlab is not similar to original text data 在ReportLab生成的PDF中包含base64编码的图像 - Including base64-encoded image in ReportLab-generated PDF
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM