Reputation: 717
I am trying to convert some local html files to pdf. These should be in a format that is easy to read on mobile. As such, I want to set a custom pdf size, so that I can fit the contents on one long and narrow pdf. The documentation on creating a new pdf says you can set a custom size by using the constructor, but is there a way to set the size when creating a pdf from file? Or to first createa a pdf, and then add the contents from a file?
options = {
'page-size': [400,800],
'margin-top': '0.0in',
'margin-right': '0.0in',
'margin-bottom': '0.0in',
'margin-left': '0.0in',
'encoding': "UTF-8",
'custom-header' : [
('Accept-Encoding', 'gzip')
],
'no-outline': None
}
pdfkit.from_file('test1.html', 'out1.pdf',configuration = config, options = options)
Upvotes: 2
Views: 3113
Reputation: 31
for custom page size you can use 'page-height' and 'page-width' instead of 'page-size' in options:
options = {
'page-height': '400',
'page-width': '800'}
Upvotes: 3