# Python Library to convert HTML to pdf

**URL:** <https://forum.inductiveautomation.com/t/python-library-to-convert-html-to-pdf/79569>\
**Category:** Ignition\
**Created:** [September 25, 2023, 6:19am UTC](https://forum.inductiveautomation.com/t/python-library-to-convert-html-to-pdf/79569 "2023-09-25T06:19:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_John](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@John\_John](https://forum.inductiveautomation.com/u/John_John)\
**Post date:** [September 25, 2023, 6:19am UTC](https://forum.inductiveautomation.com/t/python-library-to-convert-html-to-pdf/79569/1 "2023-09-25T06:19:01Z")

</div>

Imported the pdfkit module to generate the report.

import pdfkit  
pdfkit.from\_url('[http://google.com](http://google.com)', '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\api.py", 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\pdfkit.py", line 45, in **init**  
self.configuration = (Configuration() if configuration is None  
File "C:\Users\John.ignition\cache\gwlocalhost\_8088\C0\pylib\pdfkit\configuration.py", line 28, in **init**  
self.wkhtmltopdf = subprocess.Popen(  
File "C:\Users\John.ignition\cache\gwlocalhost\_8088\C0\pylib\pdfkit\configuration.py", line 28, in **init**  
self.wkhtmltopdf = subprocess.Popen(  
File "C:\Users\John.ignition\cache\gwlocalhost\_8088\C0\pylib\subprocess.py", line 859, in **init**  
self.\_execute\_child(args, executable, preexec\_fn, close\_fds,  
File "C:\Users\John.ignition\cache\gwlocalhost\_8088\C0\pylib\subprocess.py", 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

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [September 25, 2023, 6:46am UTC](https://forum.inductiveautomation.com/t/python-library-to-convert-html-to-pdf/79569/2 "2023-09-25T06:46:46Z")

</div>

press ctrl+p in your browser

---

<div class="post-metadata">

**Author:** ![John\_John](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@John\_John](https://forum.inductiveautomation.com/u/John_John)\
**Post date:** [September 25, 2023, 7:14am UTC](https://forum.inductiveautomation.com/t/python-library-to-convert-html-to-pdf/79569/3 "2023-09-25T07:14:36Z")

</div>

I have to use 3rd party pdfkit ( [pdfkit · PyPI](https://pypi.org/project/pdfkit/)) 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.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 25, 2023, 10:35am UTC](https://forum.inductiveautomation.com/t/python-library-to-convert-html-to-pdf/79569/4 "2023-09-25T10:35:29Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [September 25, 2023, 10:03pm UTC](https://forum.inductiveautomation.com/t/python-library-to-convert-html-to-pdf/79569/5 "2023-09-25T22:03:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![will\_d](https://avatars.discourse-cdn.com/v4/letter/w/3d9bf3/32.png) [@will\_d](https://forum.inductiveautomation.com/u/will_d)\
**Post date:** [September 25, 2023, 10:15pm UTC](https://forum.inductiveautomation.com/t/python-library-to-convert-html-to-pdf/79569/6 "2023-09-25T22:15:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [September 25, 2023, 11:12pm UTC](https://forum.inductiveautomation.com/t/python-library-to-convert-html-to-pdf/79569/7 "2023-09-25T23:12:35Z")

</div>

Good to know!

---

<div class="post-metadata">

**Author:** ![John\_John](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@John\_John](https://forum.inductiveautomation.com/u/John_John)\
**Post date:** [September 27, 2023, 7:30am UTC](https://forum.inductiveautomation.com/t/python-library-to-convert-html-to-pdf/79569/8 "2023-09-27T07:30:06Z")

</div>

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
