Linux Server Install Instructions
pip install pdfkit
Special Requirements for PDFkit
pdfkit needs wkhtmltopdf
This is not a python package so you may want to deactivate your venv.
sudo apt-get install wkhtmltopdf
wkhtmltopdf requires an X server. If you’re running your application on a VPS, you probably don’t have one installed. The solution is install a “virtual” X server. xvfb is a “virtual X server.
sudo apt-get install xvfb
Setup PDFkit Dependencies
To setup wkhtmltopdf requires linux root access - sudo might not be sufficient. These instructions are for getting root access on Windows Subsystem for Linux.
1 Open a Windows CMD console as administrator: Windows+R to open the Run box. Type ‘cmd’ and then press Ctrl+Shift+Enter to run as admin.
2 Set the default Linux user to root from Windows CMD console: C:> ubuntu config —default-user root
3 Launch your Linux console (ubuntu). You will automatically login as root.
4 Do what you need to do as root.
5 Go back to Windows CMD console and reset your default user back to your normal Linux user account. C:> ubuntu config —default-user username
This is what we need to do as linux root (Setup a config file for wkhtmltopdf): printf ‘#!/bin/bash\nxvfb-run -a —server-args=”-screen 0, 1024x768x24” /usr/bin/wkhtmltopdf -q $*’ > /usr/bin/wkhtmltopdf.sh chmod a+x /usr/bin/wkhtmltopdf.sh ln -s /usr/bin/wkhtmltopdf.sh /usr/local/bin/wkhtmltopdf
test it:
wkhtmltopdf http://www.google.com output.pdf
Another option is to compile wkhtmltopdf from source so it does not require X server? (I think)
OR maybe install headless-pdfkit - see pypi pip install headless-pdfkit
extra info https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf https://wkhtmltopdf.org/ https://docs.microsoft.com/en-us/windows/wsl/user-support