I'm currently attempting to render a pdf from a series of html files with Python pdfkit and PyPDF2. My goal is to render each html file into a single page with pdfkit before stitching them together with PyPDF2's PdfMerger class. However, each time I render the html, there's a blank page inserted before the actual content. How can I prevent this?
The issue occurs whether or not I have a cover page set- when I add a cover page, the blank page is before that as well. I've also tried changing my html; whether it's an image, a paragraph, a div, or something wrapped in a body, it still has the blank page.
Example:
import pdfkit
options = {
'page-height': '11in',
'page-width': '8.5in',
'enable-local-file-access': '',
'margin-bottom': '0in',
'margin-left': '0in',
'margin-right': '0in',
'margin-top': '0in',
'disable-smart-shrinking': 'true',
'load-error-handling': 'ignore'
}
pdfkit.from_string(
"<p>This should be on the first page</p>",
output_path='foo.pdf', options=options, verbose=True
)
This produces the output:
Loading pages (1/6)
Error: Failed to load http://true/, with network status code 3 and http status code 0 - Host true not found
Warning: Failed loading page http://true (ignored)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done
Exit with code 1 due to network error: HostNotFoundError
I'm running this inside a virtualenv with Python 3.7.16 on Ubuntu 18.04.6 LTS. My pdfkit is distribution 1.0.0 on pip. My wkhtmltopdf is version 0.12.6 with patched qt. (I have verbose set to True because otherwise wkhtmltopdf complains that --quiet is specified in an incorrect location.)