200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > python 生成pdf页面大小 如何在reportlab python中创建具有不同页面大小的PDF文档...

python 生成pdf页面大小 如何在reportlab python中创建具有不同页面大小的PDF文档...

时间:2021-01-25 04:44:08

相关推荐

python 生成pdf页面大小 如何在reportlab python中创建具有不同页面大小的PDF文档...

Is it possible to create a PDF document with differing page sizes in reportlab?

I would like to create a document where the first page has a different size then the other pages. Can anyone help?

解决方案

Yes, this should be possible, since PDF supports this, it's just a question of how to make it happen in ReportLab. I've never done this, but the following should work:

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

# draw some stuff on c

c.showPage()

c.setPageSize((700, 500)) #some page size, given as a tuple in points

# draw some more stuff on c

c.showPage()

c.save()

And your document should now have two pages, one with a default size page and one with a page of size 700 pt by 500 pt.

If you are using PLATYPUS you should be able to achieve the same sort of thing, but will probably require getting fancy in a BaseDocTemplate subclass to handle changing page sizes, since I'm pretty sure the PageTemplate machinery doesn't already support this since each PageTemplate is mainly a way of changing the way frames are laid out on each page. But it is technically possible, it just isn't documented and you'll probably have to spend some time reading and understanding how PLATYPUS works internally.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。