Discover the precise steps to effortlessly learn how to install WKHTMLTOPDF on Rocky Linux 9. Follow our comprehensive guide to seamlessly integrate this powerful tool into your workflow, unlocking the ability to convert web pages into PDF documents with ease. #centlinux #linux #wkhtmltopdf
Table of Contents
What is WKHTMLTOPDF?
WKHTMLTOPDF is an open-source command-line tool that converts HTML pages to PDF documents using the WebKit rendering engine. It allows users to generate high-quality PDF files from web content, including dynamic HTML pages, by rendering them as they would appear in a web browser and then converting them into a PDF format.
WKHTMLTOPDF supports various features such as headers, footers, page numbering, table of contents, and more, making it a versatile tool for generating PDF documents from web content. It’s commonly used in web development, reporting, and document generation tasks.
What is WKHTMLTOX?
WKHTMLTOX is a combination of wkhtmltopdf and wkhtmltoimage, that are open source (LGPLv3) command line tools to render HTML into PDF and various image formats using the Qt WebKit rendering engine. These run entirely “headless” and do not require a display or display service.

WKHTMLTOX Alternatives?
“WKHTMLTOX” is a term that encompasses both “WKHTMLTOPDF” and “WKHTMLTOIMAGE.” These are open-source command-line tools that convert HTML pages to PDF documents and images, respectively, using the WebKit rendering engine.
Alternatives to WKHTMLTOX include:
- Headless Chrome or Chromium: These browsers can be run in headless mode to render HTML pages and capture screenshots or generate PDFs using built-in functionality. Tools like Puppeteer or Selenium can automate this process.
- PrinceXML: is a commercial tool known for high-quality PDF generation from HTML and CSS. It supports advanced features like CSS3, JavaScript, and XML-based formats.
- wkhtmltopdf (and wkhtmltoimage): These are the predecessors of WKHTMLTOX and are still used in some cases. They provide similar functionality for converting HTML to PDF and images.
- PhantomJS: Although PhantomJS is no longer actively maintained, it was popular for headless website testing and could be used to capture screenshots or render HTML to PDF.
- Puppeteer: is a Node.js library that provides a high-level API for controlling headless Chrome or Chromium. It can be used to capture screenshots or generate PDFs from web pages.
- WeasyPrint: is a visual rendering engine for HTML and CSS that outputs PDF files. It’s based on various web standards, including HTML5, CSS3, and JavaScript.
These alternatives offer varying features, performance, and ease of use, so you can choose the one that best fits your requirements and workflow.
Environment Specification
We are using a minimal Rocky Linux 9 operating system with following specifications.
- CPU – 3.4 Ghz (2 cores)
- Memory – 2 GB
- Storage – 20 GB
- Operating System – Rocky Linux release 9.1 (Blue Onyx)
- Hostname – rocky9.centlinux.com
- IP Address – 192.168.88.128/24
For those looking to set up a dedicated environment for experimenting with WKHTMLTOPDF on Rocky Linux 9, using a Mini PC or a VPS can be an excellent choice. A Mini PC offers a compact, energy-efficient home lab solution that you can keep running 24/7, perfect for testing Linux servers and automating PDF generation tasks.
[Power Your Projects with the Best Mini PC – Shop Now!]
Alternatively, a Bluehost VPS provides scalable, reliable cloud-based hosting, allowing you to access your Linux environment anytime from anywhere without needing physical hardware.
[Try Bluehost VPS Now – Perfect for Linux & DevOps Enthusiasts!]
Both options are great for hands-on learning and development with Linux servers. If you’re interested in these solutions, check out the Mini PC and Bluehost VPS links below, which are affiliate links helping support this blog at no extra cost to you.
Disclaimer: Some links in this post are affiliate links. If you choose to purchase through these links, I may earn a small commission at no additional cost to you. This helps support the blog and keeps the content free. Thank you for your support!
Prepare your Rocky Linux Server
Login as root user on your Rocky Linux server, with the help of a ssh client.
Update software packages in your Linux operating system by using dnf package manager.
dnf update -yOccasionally, above command also updates your Linux Kernel. If it happens, then you should reboot your Linux operating system before moving forward in this Linux tutorial.
rebootAfter reboot, check the Linux operating system version.
cat /etc/os-releaseOutput:
NAME="Rocky Linux"
VERSION="9.1 (Blue Onyx)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="9.1"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Rocky Linux 9.1 (Blue Onyx)"
ANSI_COLOR="0;32"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:rocky:rocky:9::baseos"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
ROCKY_SUPPORT_PRODUCT="Rocky-Linux-9"
ROCKY_SUPPORT_PRODUCT_VERSION="9.1"
REDHAT_SUPPORT_PRODUCT="Rocky Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="9.1"
Check Linux Kernel version.
uname -rOutput:
5.14.0-162.18.1.el9_1.x86_64
WKHTMLTOX is not available in standard yum repositories. But you can download the latest version of WKHTMLTOX from their official website.
To download WKHTMLTOX rpm you may need wget command. Therefore, install it now with the help of dnf command.
dnf install -y wgetUltrbeka Ultra-Thin Air Tag Wallet Tracker Card 0.07in IP68 Waterproof Bluetooth Tracker for Wallets, Passport, Work with Apple Find My, Wireless Charging, Card Locator [Apple MFi Certified] iOS Only
20% OffInstall WKHTMLTOPDF on Rocky Linux 9
Now, use wget command to download WKHTMLTOX rpm. You can either use the following commands to download WKHTMLTOX or get the URL of latest version from their website.
cd /tmp
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox-0.12.6.1-2.almalinux9.x86_64.rpmExecute following command to install WKHTMLTOX on your Rocky Linux server.
dnf localinstall -y wkhtmltox-0.12.6.1-2.almalinux9.x86_64.rpmAfter installation, check the versions of wkhtmltopdf and wkhtmltoimage commands.
wkhtmltopdf --version
wkhtmltoimage --versionOutput:
wkhtmltopdf 0.12.6.1 (with patched qt)
wkhtmltoimage 0.12.6.1 (with patched qt)
WKHTMLTOX has been installed successfully.
You can use –help switch as follows to get help on wkhtmltopdf and wkhtmltoimage commands.
wkhtmltopdf --help
wkhtmltoimage --helpWKHTMLTOX Examples
Basic WKHTMLTOPDF Example
Here’s a simple example of how you can use wkhtmltopdf to convert an HTML file to a PDF:
Let’s say you have an HTML file named example.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example HTML to PDF</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is a simple example HTML file.</p>
</body>
</html>To convert this HTML file to a PDF named output.pdf, you can use the wkhtmltopdf command like this:
wkhtmltopdf example.html output.pdfThis command will generate a PDF file named output.pdf based on the content of example.html.
You can also specify options to customize the PDF output, such as setting page size, margins, header, and footer. For example:
wkhtmltopdf --page-size A4 --margin-top 10mm --margin-bottom 10mm --margin-left 10mm --margin-right 10mm example.html output.pdfThis command will generate a PDF with A4 page size and 10mm margins on all sides.
Feel free to adjust the options according to your requirements!
Basic WKHTMLTOIMAGE Example
Certainly! Here’s an example of how you can use wkhtmltoimage to convert an HTML file to an image:
Let’s say you have an HTML file named example.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example HTML to Image</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is a simple example HTML file.</p>
</body>
</html>To convert this HTML file to an image, you can use the wkhtmltoimage command like this:
wkhtmltoimage example.html output.pngThis command will generate a PNG image file named output.png based on the content of example.html.
You can also specify options to customize the output, such as setting width and height, quality, and format. For example:
wkhtmltoimage --quality 90 --width 800 --format jpg example.html output.jpgThis command will generate a JPEG image file with a quality of 90, a width of 800 pixels, based on the content of example.html.
Feel free to adjust the options according to your requirements!
Use WKHTMLTOPDF in PHP
Sure! Here’s a simple PHP example demonstrating how you can use wkhtmltopdf library in PHP to convert HTML content to a PDF file:
<?php
// Define the HTML content to be converted to PDF
$htmlContent = '
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example HTML to PDF</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is a simple example HTML file.</p>
</body>
</html>';
// Set the path to the wkhtmltopdf executable
$wkhtmltopdfPath = '/usr/local/bin/wkhtmltopdf'; // Adjust this path according to your installation
// Define the input and output file paths
$inputFilePath = 'input.html';
$outputFilePath = 'output.pdf';
// Write the HTML content to a file
file_put_contents($inputFilePath, $htmlContent);
// Execute the wkhtmltopdf command to convert HTML to PDF
exec("$wkhtmltopdfPath $inputFilePath $outputFilePath");
// Check if the output PDF file was created successfully
if (file_exists($outputFilePath)) {
echo 'PDF file generated successfully!';
} else {
echo 'Error generating PDF file.';
}
// Remove the input HTML file after conversion
unlink($inputFilePath);
?>In this example:
- We define the HTML content that we want to convert to a PDF.
- We set the path to the
wkhtmltopdfexecutable. Make sure to adjust this path according to the location of thewkhtmltopdfbinary on your system. - We define the input HTML file path and the output PDF file path.
- We write the HTML content to a file named
input.html. - We execute the
wkhtmltopdfcommand usingexec()to convert the HTML file to a PDF file. - We check if the output PDF file was created successfully and provide appropriate feedback.
- We remove the input HTML file after the conversion process is completed.
You’ll need to adjust the paths and configurations according to your environment and requirements.
Pefei Tweezers Set – Professional Stainless Steel Tweezers for Eyebrows – Great Precision for Facial Hair, Splinter and Ingrown Hair Removal (Black)
$9.99 (as of November 1, 2025 20:42 GMT +00:00 – More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Use WKHTMLTOPDF in Python
Certainly! Below is a basic example of how you can use the pdfkit library in Python, which is a Python wrapper for wkhtmltopdf, to convert HTML content to a PDF file:
First, make sure you have installed the pdfkit library. You can install it via pip:
pip install pdfkitThen, you’ll need to have wkhtmltopdf installed on your system. Ensure it’s properly installed and accessible in your system’s PATH.
Here’s the Python code:
import pdfkit
# HTML content to be converted to PDF
html_content = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example HTML to PDF</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is a simple example HTML file.</p>
</body>
</html>
"""
# Save HTML content to a temporary file
with open('temp.html', 'w') as f:
f.write(html_content)
# Convert HTML to PDF
pdfkit.from_file('temp.html', 'output.pdf')
print("PDF file generated successfully!")
# Cleanup: Remove the temporary HTML file
import os
os.remove('temp.html')In this example:
- We define the HTML content that we want to convert to a PDF.
- We save the HTML content to a temporary HTML file named
temp.html. - We use
pdfkit.from_file()function to convert the HTML file to a PDF file namedoutput.pdf. - Finally, we print a message indicating that the PDF file has been generated successfully and remove the temporary HTML file.
Make sure to adjust paths and configurations according to your specific requirements.
Read Also: How to install FFmpeg on Rocky Linux 9
Video Tutorial
Final Thoughts
Master the installation process of WKHTMLTOPDF on Rocky Linux 9 with our comprehensive guide. Enhance your document generation capabilities by seamlessly integrating this powerful tool into your workflow. Empower yourself to effortlessly convert HTML pages into high-quality PDF documents, unlocking new possibilities for your projects.
From setting up scalable AWS solutions to managing complex Linux environments, I’ve got you covered. Visit my Freelancer profile to get started.
FAQs
Q1: Can WKHTMLTOPDF convert dynamic content with JavaScript on Rocky Linux 9?
A1: Yes, WKHTMLTOPDF supports JavaScript rendering, but you may need to enable specific options to ensure dynamic content loads correctly before conversion.
Q2: Is it possible to customize page margins and orientation during PDF conversion?
A2: Absolutely. WKHTMLTOPDF allows you to set margins, page size, and orientation through command-line options for precise PDF formatting.
Q3: How can I troubleshoot “QT library not found” errors during installation?
A3: This usually means missing dependencies. Installing the required Qt libraries and packages on Rocky Linux 9 typically resolves this issue.
Q4: Can I use WKHTMLTOPDF for batch converting multiple HTML files?
A4: Yes, by scripting commands in a loop (e.g., with Bash), you can automate converting many HTML files to PDF efficiently.
Q5: Are there security considerations when converting web pages with WKHTMLTOPDF?
A5: Since WKHTMLTOPDF downloads and renders HTML, avoid converting untrusted URLs to prevent potential security risks like malicious scripts.
What’s Next
Boost your Linux skills with the “Linux Command Line Basics” by Ahmed Alkabary—a perfect course for beginners who want to master the command line efficiently. Whether you’re aiming for a career in system administration, DevOps, or just want to manage your Linux systems like a pro, this course covers everything from essential commands to practical exercises.
Start learning at your own pace and transform the way you interact with Linux today. [Enroll here] to get started instantly!
Disclaimer: This post contains affiliate links. If you purchase through these links, I may earn a small commission at no extra cost to you. Your support helps me continue sharing helpful tech content.


Leave a Reply
Please log in to post a comment.