If you're looking to convert HTML to PDF on a Linux server, WKHTMLtoPDF is one of the most reliable open-source tools available. It allows developers to generate high-quality PDFs from HTML using the WebKit rendering engine.
In this step-by-step guide, you’ll learn how to install WKHTMLtoPDF on Ubuntu, configure it properly, and fix common installation issues.
What is WKHTMLtoPDF?
WKHTMLtoPDF is a command-line tool that converts HTML pages into PDF documents. It’s widely used in:
Laravel applications
PHP projects
Node.js backends
Server-side PDF generation
Automated reporting systems
You can download the official build from the WKHTMLtoPDF website:
https://wkhtmltopdf.com
Why Use WKHTMLtoPDF on Ubuntu?
Ubuntu servers are commonly used for web hosting and backend applications. Installing WKHTMLtoPDF on Ubuntu allows you to:
Generate invoices automatically
Create reports in PDF format
Convert dynamic web pages to downloadable PDFs
Automate document workflows
Step 1: Update Your Ubuntu System
Before installing any package, update your system:
sudo apt update && sudo apt upgrade -y
This ensures all dependencies are up to date.
Step 2: Install Required Dependencies
WKHTMLtoPDF requires some libraries to function properly.
Run:
sudo apt install -y fontconfig libxrender1 libxext6 xfonts-base xfonts-75dpi
These libraries ensure proper font rendering and display support.
Step 3: Download WKHTMLtoPDF for Ubuntu
It’s recommended to install the official .deb package instead of using the default Ubuntu repository (as it may be outdated).
Download the latest version:
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb
Step 4: Install the Package
Now install the downloaded file:
sudo dpkg -i wkhtmltox_0.12.6-1.focal_amd64.deb
If you see dependency errors, fix them using:
sudo apt --fix-broken install
Step 5: Verify Installation
Check if WKHTMLtoPDF is installed correctly:
wkhtmltopdf --version
If everything is correct, you’ll see the installed version number.
Step 6: Test HTML to PDF Conversion
Create a simple test file:
wkhtmltopdf https://example.com output.pdf
This will convert the webpage into a PDF file named output.pdf.
If the PDF generates successfully — installation is complete ✅
How to Install WKHTMLtoPDF on Ubuntu 22.04 (Special Note)
If you're using Ubuntu 22.04, ensure:
You install the correct .deb file version
Required dependencies are present
You avoid snap-based installations
Using the official release package is more stable for production environments.
Common Installation Errors & Fixes
Error 1: wkhtmltopdf command not found
Fix:
Make sure it’s installed in /usr/local/bin or /usr/bin.
Run:
which wkhtmltopdf
If not found, reinstall the package.
Error 2: Missing Shared Libraries
Fix:
sudo apt install -f
This installs missing dependencies automatically.
Error 3: Fonts Not Rendering Properly
Install additional fonts:
sudo apt install ttf-mscorefonts-installer
Using WKHTMLtoPDF with Laravel (Optional)
If you're using Laravel, you can integrate WKHTMLtoPDF with packages like:
barryvdh/laravel-snappy
It allows easy PDF generation directly from Blade templates.
Best Practices for Production Servers
✔ Always use the official stable release
✔ Avoid outdated Ubuntu repository versions
✔ Test on staging before deploying to live server
✔ Monitor memory usage during large PDF generation
Final Thoughts
Installing WKHTMLtoPDF on Ubuntu is straightforward if you follow the correct steps and install the proper dependencies.
Whether you’re building automated reports, invoices, or dynamic PDF systems — WKHTMLtoPDF remains a reliable solution for server-side HTML to PDF conversion.
If you found this guide helpful, feel free to share it with other developers who are setting up Ubuntu servers for PDF automation 🚀

Top comments (0)