This is the exception being thrown:
OSError: No wkhtmltopdf executable found
Browsing the internet, I see it as a common problem. It requires you to download some sort of binaries and pass it in the parameter. Like so:
import markdown2
import pdfkit
filename = "sample.md"
mode = "r"
with open(filename, mode) as file:
markdown_text = file.read()
html_text = markdown2.markdown(markdown_text)
config = pdfkit.configuration(wkhtmltopdf="/path/to/wkhtmltopdf.exe")
pdfkit.from_string(html_text, "output.pdf", configuration=config)
Please, check this post for further information on how to download this wkhtmltopdf.exe
.
Plus, it looks like you can eventually use the pdfkit.from_file()
instead of .from_string()
. It may give you a more correct output with a lighter code, but it still requires you to download this wkhtmltopdf.exe
.
Something like this:
import pdfkit
filename = "sample.md"
mode = "r"
with open(filename, mode) as file:
config = pdfkit.configuration(wkhtmltopdf="/path/to/wkhtmltopdf.exe")
pdfkit.from_file(file, "output.pdf", configuration=config)
It should work, but I didn't test the output.