5

I would like to find a way to line-break in pdfkit.

I tried both with strings and html files but it does not work as expected.

The following two minimal examples instead of providing me with 'a' (newline) 'b' generate 'a b'. I would appreciate your help.

# 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 Answers0