2

So I want to set up a script that will take a web page and turn it into a pdf. It seems something is wrong with my configuration of wkhtmltopdf. This is the part I don't know how to do: "and add folder with wkhtmltopdf binary to PATH." I would appreciate some help with this script. Thank you!

This is my code:

import pdfkit
pdfkit.from_url('https://grapaes.com/282-newsletter/', 'news282.pdf')
print("I did it!")

This is my error message:

Traceback (most recent call last):
  File "C:/Users/Gittel/PycharmProjects/untitled1/website as pdf", line 2, in <module>
    pdfkit.from_url('https://grapaes.com/282-newsletter/', 'news282.pdf')
  File "C:\Users\Gittel\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pdfkit\api.py", line 23, in from_url
    r = PDFKit(url, 'url', options=options, toc=toc, cover=cover,
  File "C:\Users\Gittel\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pdfkit\pdfkit.py", line 42, in __init__
    self.configuration = (Configuration() if configuration is None
  File "C:\Users\Gittel\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pdfkit\configuration.py", line 24, in __init__
    raise IOError('No wkhtmltopdf executable found: "%s"\n'
OSError: No wkhtmltopdf executable found: "b''"
If this file exists please check that this process can read it. Otherwise please install wkhtmltopdf - https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf

Process finished with exit code 1
Unicorn_tech
  • 207
  • 1
  • 4
  • 18

1 Answers1

3
import pdfkit
from pdfkit.api import configuration

wkhtml_path = pdfkit.configuration(wkhtmltopdf = "C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe")  #by using configuration you can add path value.

pdfkit.from_url('https://stackoverflow.com/questions/33705368/unable-to-find-wkhtmltopdf-on-this-system-the-report-will-be-shown-in-html', 'C:/Users/Admin/Desktop/Trial1.pdf', configuration = wkhtml_path)
Robert
  • 7,394
  • 40
  • 45
  • 64
Artemis237
  • 31
  • 2
  • please can you help me make the TOC? i believe i need to pass `toc = {'xsl-style-sheet': 'toc.xsl'}`, but i don't know what is supposed to go in that file... – yishairasowsky Sep 23 '21 at 14:44