Python Library to convert HTML to pdf

Imported the pdfkit module to generate the report.

import pdfkit
pdfkit.from_url('', 'out.pdf')

Getting error as below
Traceback (most recent call last):
File "input", line 2, in
File "C:\Users\John.ignition\cache\gwlocalhost_8088\C0\pylib\pdfkit\", line 24, in from_url
r = PDFKit(url, 'url', options=options, toc=toc, cover=cover,
File "C:\Users\John.ignition\cache\gwlocalhost_8088\C0\pylib\pdfkit\", line 45, in init
self.configuration = (Configuration() if configuration is None
File "C:\Users\John.ignition\cache\gwlocalhost_8088\C0\pylib\pdfkit\", line 28, in init
self.wkhtmltopdf = subprocess.Popen(
File "C:\Users\John.ignition\cache\gwlocalhost_8088\C0\pylib\pdfkit\", line 28, in init
self.wkhtmltopdf = subprocess.Popen(
File "C:\Users\John.ignition\cache\gwlocalhost_8088\C0\pylib\", line 859, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\John.ignition\cache\gwlocalhost_8088\C0\pylib\", line 1369, in _execute_child
raise OSError(errno.ENOENT, os.strerror(errno.ENOENT))
OSError: [Errno 2] No such file or directory.

Any other python library that can be used to convert html to pdf? Please suggest

press ctrl+p in your browser

1 Like

I have to use 3rd party pdfkit ( pdfkit · PyPI) python library to use in ignition (For vision project).
I have copied the library to the C:\Program Files\Inductive Automation\Ignition\user-lib\pylib folder.

But above error is coming.

It is trying to use subprocess to run an executable. Which means it isn't pure python (2.7) and won't work in jython. (Probably.)

1 Like

One of the libraries in pdfkit is Qt, which is written in C/C++. This won't be able to run in Ignition, which requires pure Python or Jython.

For what it's worth, I use pdfkit in Ignition all the time (I'm on v0.6.1 of pdfkit though, so take this with a grain of salt if you're using 1.0.0). It doesn't use any other libraries, but it does depend on having wkhtmltopdf installed somewhere on your system (that's why the call to subprocess) and that's why you're getting the error; you have to properly supply the path to wkhtmltopdf in the config structure of pdfkit. Once you get it configured properly, it works just fine (although there are some limitations to wkhtmltopdf that are not really pdfkit's fault).

We only really use it on Windows clients, so YMMV if you are trying to do this on Mac/Linux. I have spent only a few minutes attempting to get it to work on Mac (I have one Mac user), and I ran into some sandboxing issues and gave up, since it's not a super-critical feature for that user.


Good to know!

Downloaded the pdfbox.jar and added to the following folders

C:\Program Files\Inductive Automation\Ignition\lib\core\client
C:\Program Files\Inductive Automation\Ignition\lib\core\common
C:\Program Files\Inductive Automation\Ignition\lib\core\gateway

When i tried to import (import org.apache.pdfbox.pdmodel.PDDocument) getting error as ImportError: No module named pdfbox