wkhtmltopdf Installation Guide on Ubuntu (Step by Step)
Generating PDFs from HTML is one of those quietly essential tasks in modern web applications. Invoices, reports, resumes, tickets, receipts — the list goes on. wkhtmltopdf has become a long-standing favorite for this job because it renders HTML using a real browser engine rather than a fragile PDF library.
n this article, we’ll explore what wkhtmltopdf is, why developers still rely on it, and how to install wkhtmltopdf on Ubuntu step by step. We’ll also cover practical usage examples with PHP, Laravel, and WordPress.
What is wkhtmltopdf?
wkhtmltopdf is an open-source command-line tool that converts HTML pages into PDF documents. Under the hood, it uses the WebKit rendering engine — the same family of engines that power modern browsers.
This means your PDFs respect:
- CSS layouts (including flexbox and floats)
- Web fonts
- Images and SVGs
- Headers, footers, and page breaks
Unlike many pure-PHP PDF libraries, wkhtmltopdf renders HTML exactly as a browser would, which makes it ideal for pixel-perfect PDFs.
Common Use Cases of wkhtmltopdf
- Generating invoices and receipts
- Creating downloadable reports and analytics summaries
- Exporting resumes or job applications as PDF
- Generating tickets, certificates, or brochures
- Automated PDF generation in CI/CD pipelines
At a href=”https://codeboxr.com” target=”_blank” rel=”noopener”>Codeboxr, wkhtmltopdf is frequently used in Laravel and WordPress projects where layout accuracy matters.
Installing wkhtmltopdf on Ubuntu (Step by Step)
Step 1: Update Your System
sudo apt update
sudo apt upgrade -y
Step 2: Install Required Dependencies
wkhtmltopdf depends on several system libraries. Install them first:
sudo apt install -y fontconfig libxrender1 xfonts-75dpi xfonts-base
Step 3: Download the Official wkhtmltopdf Package
Ubuntu’s default repository often ships an outdated version. It’s best to install the official static build.
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb
Replace focal with your Ubuntu version if necessary
(e.g., jammy).
Step 4: Install the Package
sudo dpkg -i wkhtmltox_0.12.6-1.focal_amd64.deb
Step 5: Fix Missing Dependencies (If Needed)
sudo apt --fix-broken install -y
Step 6: Verify Installation
wkhtmltopdf --version
If installed correctly, you should see the wkhtmltopdf version printed in the terminal.
Basic Usage of wkhtmltopdf
Converting a simple HTML file to PDF:
wkhtmltopdf input.html output.pdf
Converting a live URL:
wkhtmltopdf https://example.com report.pdf
Adding margins and page size:
wkhtmltopdf --page-size A4 --margin-top 10mm --margin-bottom 10mm input.html output.pdf
Using wkhtmltopdf with PHP
In PHP, wkhtmltopdf is usually executed via shell_exec() or a process wrapper.
wkhtmltopdf /var/www/html/invoice.html /var/www/html/invoice.pdf
Example PHP snippet:
<?php
$html = '/var/www/html/invoice.html';
$pdf = '/var/www/html/invoice.pdf';
$command = "wkhtmltopdf $html $pdf";
shell_exec($command);
?>
Always sanitize paths and inputs when executing system commands.
Using wkhtmltopdf in Laravel
Laravel developers typically use wrappers like barryvdh/laravel-snappy, which internally relies on wkhtmltopdf.
Once wkhtmltopdf is installed on the server, Laravel can generate PDFs directly from Blade views. This is especially useful for invoices, payroll reports, and HR documents.
If you’re already working with Laravel-based tools and automation, you may find related guides on the Codeboxr Blog helpful for production setups.
Using wkhtmltopdf with WordPress
WordPress plugins often use wkhtmltopdf for exporting posts, invoices, or reports as PDF. In custom plugin development, wkhtmltopdf is typically triggered via PHP.
This approach is common in:
- Booking and reservation systems
- Accounting and invoicing plugins
- Resume or job application plugins
For WordPress-focused development tutorials and plugin engineering insights, explore the articles available on codeboxr.com.
Final Thoughts
wkhtmltopdf remains a powerful and reliable solution for HTML-to-PDF generation, especially when layout fidelity matters more than convenience.
With a proper Ubuntu installation and careful server configuration, it integrates cleanly into PHP, Laravel, and WordPress ecosystems. Despite its age, it still earns its place in modern production stacks.
Need to build a Website or Application?
Since 2011, Codeboxr has been transforming client visions into powerful, user-friendly web experiences. We specialize in building bespoke web applications that drive growth and engagement.
Our deep expertise in modern technologies like Laravel and Flutter allows us to create robust, scalable solutions from the ground up. As WordPress veterans,
we also excel at crafting high-performance websites and developing advanced custom plugins that extend functionality perfectly to your needs.
Let’s build the advanced web solution your business demands.