D
D
Dmitry2020-07-13 16:55:38
Python
Dmitry, 2020-07-13 16:55:38

How to convert an image file in Python pdfkit?

there is a loop that receives a list of html files and then the loop should create pdf files, but the trouble is, it has a file blocking error and creates only the first pdf, but also the one without a picture, the pdf creation loop:

for i in list_svod:
    path_wkthmltopdf = b'C:\Program Files\wkhtmltopdf\\bin\wkhtmltopdf.exe'
    config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
    css = 'style.css'
    options = {
        'orientation': 'landscape',
        'margin-bottom': '0in',
        'margin-left': '0in',
        'margin-right': '0in',
        'margin-top': '0in',
        'page-size': 'a4',
        'page-height': '10in',
        'page-width': '7.12in',
    }
    pdfkit.from_file(str(i[1]) + ".html", str(i[1]) + ".pdf", configuration=config, options=options, css=css)


error text:

Traceback (most recent call last):
File "E:/PycharmProjects/untitled/pdf_to_cert/parser.py", line 40, in
pdfkit.from_file(str(i[1]) + ".html", str( i[1]) + ".pdf", configuration=config, options=options, css=css)
File "C:\Python3\lib\site-packages\pdfkit\api.py", line 49, in from_file
return r .to_pdf(output_path)
File "C:\Python3\lib\site-packages\pdfkit\pdfkit.py", line 156, in to_pdf
raise IOError('wkhtmltopdf reported an error:\n' + stderr)
OSError: wkhtmltopdf reported an error:
Loading pages (1/6)
Warning: Blocked access to file
Warning: Blocked access to file
Error: Failed to load about:blank, with network status code 301 and http status code 0 - Protocol "about" is unknown
Error: Failed to load about:blank, with network status code 301 and http status code 0 - Protocol "about" is unknown
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: ProtocolUnknownError

Process finished with exit code 1
in html the path is relative because the picture is in the root, I tried to write and full but the result is the same

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question