Python 使用reportLab生成的pdf大小
我的pdf生成有问题 当我生成一个pdf,几分钟后,当我重新启动相同的脚本生成相同的pdf时,我的第一个pdf和第二个pdf之间没有相同的大小 这是我的代码:Python 使用reportLab生成的pdf大小,python,pdf-generation,reportlab,Python,Pdf Generation,Reportlab,我的pdf生成有问题 当我生成一个pdf,几分钟后,当我重新启动相同的脚本生成相同的pdf时,我的第一个pdf和第二个pdf之间没有相同的大小 这是我的代码: c = reportlab.pdfgen.canvas.Canvas("test.pdf") c.showPage() c.save() 第一个pdf有:1519byte 第二个有1531字节 每当我重新启动同一个脚本时,每当我有不同的值时。 为什么?如何解决此问题?我看不出您的PDF更改大小的问题,但其内容正在更改: $ python
c = reportlab.pdfgen.canvas.Canvas("test.pdf")
c.showPage()
c.save()
第一个pdf有:1519
byte
第二个有1531
字节
每当我重新启动同一个脚本时,每当我有不同的值时。
为什么?如何解决此问题?我看不出您的PDF更改大小的问题,但其内容正在更改:
$ python make_pdf.py && md5sum test.pdf
9a1dbc5621622526b4411fb5f818246e test.pdf
$ python make_pdf.py && md5sum test.pdf
b4c3ef4661c2a0f7d5c458757ac8a891 test.pdf
$
根据注释中的提示,设置解决方案
import reportlab.pdfgen.canvas
import reportlab.rl_config
reportlab.rl_config.invariant = 1
c = reportlab.pdfgen.canvas.Canvas("test.pdf")
c.showPage()
c.save()
现在内容不会更改,因为PDF没有生成id,时间戳设置为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
$
我看不出您的PDF更改大小的问题,但其内容正在更改:
$ python make_pdf.py && md5sum test.pdf
9a1dbc5621622526b4411fb5f818246e test.pdf
$ python make_pdf.py && md5sum test.pdf
b4c3ef4661c2a0f7d5c458757ac8a891 test.pdf
$
根据注释中的提示,设置解决方案
import reportlab.pdfgen.canvas
import reportlab.rl_config
reportlab.rl_config.invariant = 1
c = reportlab.pdfgen.canvas.Canvas("test.pdf")
c.showPage()
c.save()
现在内容不会更改,因为PDF没有生成id,时间戳设置为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
$
差异是由于在生成的PDF文件的
尾部
部分中随机生成的ID
。@acw1668,有解决方案吗?@acw1668,我可以获取PDF的ID
?在保存pdf之前,我可以设置一个特定的ID
吗?@acw1668,没关系,我发现我添加了reportlab.rl\u config.invariant=1
,非常感谢您的帮助!!!差异是由于在生成的PDF文件的尾部
部分中随机生成的ID
。@acw1668,有解决方案吗?@acw1668,我可以获取PDF的ID
?在保存pdf之前,我可以设置一个特定的ID
吗?@acw1668,没关系,我发现我添加了reportlab.rl\u config.invariant=1
,非常感谢您的帮助!!!