use*_*282 5 pdfkit python-pdfkit
我想找到一种在 pdfkit 中换行的方法。
我尝试了字符串和 html 文件,但它没有按预期工作。
以下两个最小的示例不是为我提供“a”(换行符)“b”,而是生成“a b”。我将不胜感激你的帮助。
# from_string example (html example follows)
import pdfkit
options = {
'page-size': 'A4',
'margin-top': '0.75in',
'margin-right': '0.75in',
'margin-bottom': '0.75in',
'margin-left': '0.75in',
'encoding': 'UTF-8',
'quiet': ''
}
s1 = 'a \n b'
pdfkit.from_string(s1, 'out.pdf', options=options)
# html example
import pdfkit
s2 = """
a
b
"""
h1 = """<html>
<head></head>
<body><p>"""
h2 = """</p></body>
</html>"""
content = h1 + s2 + h2
f = open('out.html', 'w')
f.write(content)
f.close()
options = {
'page-size': 'A4',
'margin-top': '0.75in',
'margin-right': '0.75in',
'margin-bottom': '0.75in',
'margin-left': '0.75in',
'encoding': 'UTF-8',
'quiet': ''
}
pdfkit.from_file('out.html', 'out.pdf')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
966 次 |
| 最近记录: |