pdfkit新行from_string或html不起作用

时间:2019-04-19 13:46:40

标签: 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')

0 个答案:

没有答案