Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Python’s pdfkit wrapper to call the separate wkhtmltopdf executable. Install both, verify that the executable works on your operating system, then choose pdfkit.from_string(), pdfkit.from_file() or pdfkit.from_url() for your input. This is a legacy rendering stack: the project’s downloads page lists 0.12.6, released June 11, 2020, as its stable series, and the Python wrapper README carries a deprecation warning.

What you need before generating a PDF

There are two separate components:

  • PDFKit, a Python package that provides a convenient API.
  • wkhtmltopdf, a command-line executable that renders the content and creates the PDF.

Installing the Python package alone is not sufficient. The executable must be installed separately and available to the Python process through PATH, or specified explicitly in PDFKit’s configuration. The project’s downloads page provides builds for particular distributions and platforms; system libraries, libc, fontconfig and installed fonts can affect whether a build works.

Install PDFKit in the environment that runs your script:

python -m pip install pdfkit

Then install an appropriate wkhtmltopdf build for your operating system and architecture. Verify the executable from the same environment or host where Python will run:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
wkhtmltopdf --version

The command should print the version. If the shell reports that the command is not found, install the executable or correct the environment’s PATH before debugging the Python code.

Generate a PDF from a string, file or URL

Once both dependencies are available, PDFKit’s three basic entry points cover the common input types. These examples follow the wrapper’s documented API; they are illustrative, not a claim of independent testing.

Convert an HTML string

import pdfkit

html = "<h1>Hello</h1><p>Generated from Python.</p>"
pdfkit.from_string(html, "out.pdf")

Convert a local HTML file

import pdfkit

pdfkit.from_file("report.html", "report.pdf")

Ensure that any images, stylesheets and other assets referenced by the file can be accessed by the renderer. Relative paths that resolve in a browser may not resolve from the renderer’s working directory.

Convert a web page

import pdfkit

pdfkit.from_url("https://example.com", "page.pdf")

This asks wkhtmltopdf to load and render the URL. The result depends on whether the executable can reach the page and load its resources; a page that relies on modern, dynamic JavaScript may not render as expected with this older WebKit-based stack.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Return PDF bytes instead of writing a file

The PDFKit README documents that omitting the output path returns the generated PDF as bytes. This is useful when another part of your program will store or send the result:

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
import pdfkit

pdf_bytes = pdfkit.from_string("<h1>Hello</h1>")
# Pass pdf_bytes to your storage or response layer.

Configure the executable and common PDF options

Point PDFKit at a specific binary

If the executable is not on the Python process’s PATH, or you need to select a particular installation, configure its full path:

import pdfkit

config = pdfkit.configuration(wkhtmltopdf="/path/to/wkhtmltopdf")
pdfkit.from_string("<h1>Hello</h1>", "out.pdf", configuration=config)

Use the actual path for your installation. In containers, services and scheduled jobs, check the environment of the running process rather than relying only on an interactive shell’s configuration.

Set page size, margins and encoding

PDFKit passes options through to wkhtmltopdf. Option names can be supplied without the leading --. For example:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import pdfkit

options = {
    "page-size": "Letter",
    "margin-top": "0.75in",
    "margin-right": "0.75in",
    "margin-bottom": "0.75in",
    "margin-left": "0.75in",
    "encoding": "UTF-8",
}

pdfkit.from_file("report.html", "report.pdf", options=options)

Choose a page size and margins that match the document’s intended use; these settings affect pagination and printable area. The official settings reference also documents orientation, output path, document title, image and JavaScript loading, print media, local-file access controls, headers and footers, and table-of-contents-related settings. Consult the executable’s help and the settings reference for exact option names and behavior.

Cookies and custom headers

For a page that requires a session or particular request headers, PDFKit can pass cookies and custom headers as options. Its README illustrates these options, along with disabling the outline:

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
import pdfkit

options = {
    "cookie": [
        ("session", "YOUR_SESSION_VALUE"),
    ],
    "custom-header": [
        ("X-Example", "value"),
    ],
    "no-outline": None,
}

pdfkit.from_url("https://example.com", "page.pdf", options=options)

Use only credentials you are authorized to send, and avoid logging sensitive cookie or header values. Not every option or patched-Qt feature is available in every binary build; if an option appears ignored, verify the build and reproduce the command outside Python.

Understand build differences and feature support

The executable’s build matters, not just its version string. The Python PDFKit README warns that Debian and Ubuntu repository builds may omit patched Qt capabilities such as outlines, headers, footers and a table of contents. If you depend on one of these features, check the behavior of the specific binary installed on the target system rather than assuming every build supports it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The full option set is larger than the common examples above. For details available from your installed executable, inspect its command-line help, and compare with the project’s documentation and settings reference. These references do not make unsupported features available in a build that lacks them.

Troubleshoot missing, incomplete or unexpected PDFs

PDFKit cannot find wkhtmltopdf

Symptom: PDFKit raises an error indicating it could not find or run the executable.

  • Run wkhtmltopdf --version in the deployment environment.
  • Check that the Python process can see the executable on its PATH.
  • If necessary, pass the installed binary’s full path through pdfkit.configuration().
  • Confirm that the selected build matches the operating system, architecture and available system libraries.

The output is blank or missing images and styles

Check resource access first: confirm that remote URLs are reachable from the renderer and that local file paths resolve from the process’s working directory. Fonts and system libraries can also change rendering, so inspect them when output differs between development and deployment.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

An option has no effect or the layout differs

Enable verbose output to see wkhtmltopdf’s messages:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
pdfkit.from_file("report.html", "report.pdf", verbose=True)

The wrapper README recommends reproducing the generated command directly with the executable when diagnosing unexpected output. Use the command-line help to validate option spelling, check whether the installed build supports the feature, and inspect resource-loading errors before changing application code.

The page looks different from a modern browser

wkhtmltopdf uses an older Qt/WebKit rendering stack, so differences are especially relevant for pages built around newer browser behavior or dynamic JavaScript. First determine whether the source is controlled HTML or a live site, then check whether the page requires JavaScript, fonts or other resources the renderer cannot load. If it does, choose a renderer suited to that content rather than assuming a PDFKit option will make the older engine behave like a current browser.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use wkhtmltopdf safely

The project warns against using wkhtmltopdf with untrusted HTML and JavaScript: hostile input could compromise the server running the renderer. If your application converts user-controlled content, sanitize and constrain that input, run the process with least privilege, and use operating-system-level isolation appropriate to your service.

Disabling local file access can reduce exposure, but it is not a complete security boundary. The project’s AppArmor guidance explains that an attacker exploiting a vulnerability in a prebuilt binary might bypass that setting; AppArmor can add another confinement layer. Treat local-file restrictions as one control among several, not a substitute for isolation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Is wkhtmltopdf a suitable choice now?

Plan for a legacy dependency rather than assuming an actively modernized renderer. The project’s downloads page identifies 0.12.6, released June 11, 2020, as its stable series. Its status page is a maintainer essay with a snapshot dated June 10, 2020; it describes Qt 4 and its WebKit as outdated and unsupported in that context, discusses QtWebKit’s retirement, and recommends considering alternatives. That dated status essay does not establish present-day vulnerability status or independently verify the current release situation. The Python PDFKit README also includes a deprecation warning.

The status page suggests WeasyPrint or commercial Prince for reports generated from controlled HTML, and Puppeteer or a wrapper around it when output depends on dynamic JavaScript. These are the project maintainers’ recommendations, not a measured performance ranking or a current security comparison. Check current versions, platform support and suitability for your own documents before choosing.

  • Consider wkhtmltopdf when you have a compatible binary, controlled inputs and a rendering requirement you have verified against that build.
  • Evaluate another renderer when you need current browser behavior, depend on dynamic JavaScript, or cannot safely support the legacy executable in your deployment.
  • Test on the target platform when headers, footers, outlines, tables of contents, fonts or system libraries are material to the output.

Or skip the browser setup

If your goal is to capture a web page as a PDF rather than run a local wkhtmltopdf installation, ScreenshotNeo offers a one-call API. See the ScreenshotNeo documentation for request details.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.pdf

Cookie and consent banners are accepted like a visitor and removed before capture, along with known newsletter popups and chat widgets; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads and cache hits cost nothing, and response headers say which outcome occurred. ScreenshotNeo also provides an MCP server for AI agents, with tools including take_screenshot, get_page_info and capture_pdf. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Sign up free for ScreenshotNeo: 1,000 screenshots a month, no card.

Frequently Asked Questions

Can I install PDFKit without installing wkhtmltopdf?

No. PDFKit is a Python wrapper; it needs the separate wkhtmltopdf executable to render PDFs.

Can wkhtmltopdf render pages that use JavaScript?

It can render some JavaScript-driven content, but its older Qt/WebKit stack may not match modern browser behavior. Test the specific page; for output dependent on dynamic JavaScript, the project status page suggests considering Puppeteer or a wrapper around it.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.