Hi all, recently I created a project which required transforming an HTML output into a pdf file using python3. I faced several nuances while running the pdfkit util - from_file
in python which internally requires wkhtmltopdf
You might face an error like the one below when executing pdfkit utilities.
OSError: No wkhtmltopdf executable found: "b''"
If this file exists please check that this process can read it or you can pass path to it manually in method call, check README. Otherwise please install wkhtmltopdf - https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf
As stated above, we must install the package from the above source. Installing using apt-get install
or pip3 install
may not necessarily work for you.
For me it threw the following error
> sudo apt-get install wkhtmltopdf
> pdfkit.from_file('x.html', 'y.pdf')
OSError: wkhtmltopdf exited with non-zero code 1. error:
qt.qpa.screen: QXcbConnection: Could not connect to display localhost:0.0
Could not connect to any X display.
So the preferred way to get this is:
sudo wget -p ./ https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb
sudo dpkg -i wkhtmltox-0.12.1_linux-wheezy-amd64.deb
If after executing the second command you see the following error:
dpkg: dependency problems prevent configuration of wkhtmltox:
wkhtmltox depends on libpng12-0; however:
Package libpng12-0 is not installed.
Install the libpng12-0 not using apt-get install
but again the package itself
sudo wget http://se.archive.ubuntu.com/ubuntu/pool/main/libp/libpng/libpng12-0_1.2.54-1ubuntu1_amd64.deb
sudo dpkg -i libpng12-0_1.2.54-1ubuntu1_amd64.deb
sudo dpkg -i wkhtmltox-0.12.1_linux-wheezy-amd64.deb
Now your problem must get resolved. Upvote if this worked for you!
Also, the link to my project where I used pdfkit, which creates HTML and pdf of your Resume with the user providing the contents in a yaml.
Top comments (0)