【发布时间】:2020-01-19 21:31:22
【问题描述】:
我尝试使用 weasyprint Python 3 API 将“xhtml 网页”转换为“A4 肖像 pdf”。
Here 是页面。
但是最后的 pdf 文件不适合 A4 页面。
这是python代码:
#!/usr/bin/python3
from weasyprint import HTML, CSS
import subprocess
Page = HTML(url="https://educadhoc.hachette-livre.fr/extract/complet/9782401058705/show-page/page325.xhtml")
Style = CSS(string='''
@page {
size: A4 portrait;
max-height:100%;
max-width:100%;
}
''')
Page.write_pdf(target="Try.pdf", zoom=1, stylesheets=[Style])
subprocess.Popen(["evince", "Try.pdf"])
即使在 CSS 样式中使用“尺寸 A4 肖像”和在 write_pdf 方法中使用“zoom=1”,它也不适合 A4!
(pdf文件中也有换行!...)
你有什么建议?
【问题讨论】:
-
您找到解决方案了吗?我有类似的问题
标签: python pdf xhtml weasyprint