1

I can run the following comand under Win cmd box:

"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe" --header-html "C:\temp\Header.html" http://google.de "C:/temp/out_new1.pdf"

Output looks like expected and includes the Header.html

However, if I try to place it in Python it will return errors. I've tryed the following configruration:

path_wkthmltopdf = "'C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe' --header-html 'C:/temp/Header.html'"
config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)

I'm receiving the following error:

OSError: No wkhtmltopdf executable found: "'C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe' --header-html 'C:/temp/Header.html'"

Can u help please?

Thank you very much in advance

Andreas

Andreas
  • 147
  • 3
  • 17
  • binary path only, shold not add option strings: `pdfkit.configuration(wkhtmltopdf='C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe')` – georgexsh Dec 14 '17 at 11:25
  • https://stackoverflow.com/questions/27673870/cant-create-pdf-using-python-pdfkit-error-no-wkhtmltopdf-executable-found – Anup Yadav Dec 14 '17 at 11:27
  • How and where do I define than the options? – Andreas Dec 14 '17 at 11:34
  • like this `pdfkit.from_url(..., options=options)`, you should read doc first. – georgexsh Dec 14 '17 at 17:02
  • Hi @ I am a Python developer, and I am beginner at using wkhtmltopdf, and currently I have a html being converted into a pdf. But I want to automatically include a table of contents. The documentation says I should put a file called toc.xsl into the param toc. But I am not familiar with .xsl files, so I am not sure what that file should contain. I looked online for examples, but I think they are a little beyond me. Can you please help guide me? Thanks! – yishairasowsky Aug 14 '21 at 20:58

1 Answers1

2

thanks for the tips. I figured out how it works.

I try somesing like:

path_wkthmltopdf = r"'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe' options=pdf_options"
config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)

which is not working.

You have to put the option to the call like

pdfkit.from_string(data, outputfile_name, configuration=config, options=pdf_options)

Best regards Andreas

Andreas
  • 147
  • 3
  • 17