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

Python-PDFKit converts a URL, HTML file, or HTML string to PDF by calling the separate wkhtmltopdf program. Install both components: the Python package alone cannot render a PDF. For a new project, note that Python-PDFKit is deprecated, and review whether its older rendering engine meets your requirements before adopting it.

Install Python-PDFKit and wkhtmltopdf

Install the Python wrapper in your environment, then install the wkhtmltopdf executable separately. The executable must be available on your system PATH or configured explicitly. Follow the installation instructions for your operating system in the Python-PDFKit README. Distribution-packaged wkhtmltopdf builds can differ from builds that include the project’s Qt patches, so verify the binary and features actually available in your environment.

Check that the command-line program is discoverable before trying conversion. On Unix-like systems the wrapper uses which for automatic discovery; on Windows it uses where. If automatic discovery fails, configure the executable path as shown below.

Choose the right input method

Use the function that matches where your HTML comes from. Each function can write to a file; leave out the output path to get PDF bytes back for further processing.

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.
Input Function Example
A web page pdfkit.from_url pdfkit.from_url("https://example.com", "out.pdf")
An HTML file pdfkit.from_file pdfkit.from_file("input.html", "out.pdf")
An HTML string pdfkit.from_string pdfkit.from_string("<h1>Hello</h1>", "out.pdf")

Generate a PDF with runnable Python

After installing both components, this example converts an HTML string and shows the corresponding calls for a local HTML file and a URL:

import pdfkit

# Convert an HTML string to a PDF file.
pdfkit.from_string("<h1>Hello</h1>", "out.pdf")

# Or convert a local HTML file.
pdfkit.from_file("input.html", "out.pdf")

# Or render a web page.
pdfkit.from_url("https://example.com", "out.pdf")

To process the PDF in memory instead of writing it to disk, omit the destination argument and capture the returned bytes:

pdf_bytes = pdfkit.from_string("<h1>Hello</h1>")

Configure the wkhtmltopdf executable

If the binary is installed outside PATH or automatic discovery does not locate it, give PDFKit its full path through pdfkit.configuration:

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

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

Replace /path/to/wkhtmltopdf with the executable’s actual location on your machine. The configuration parameter is passed to the conversion call.

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

Set page size, margins, and other options

PDFKit passes an options dictionary through to wkhtmltopdf. Option names omit the leading --; values are strings. For example:

import pdfkit

options = {
    "page-size": "A4",
    "margin-top": "0.75in",
    "margin-right": "0.75in",
    "margin-bottom": "0.75in",
    "margin-left": "0.75in",
    "encoding": "UTF-8",
}
pdfkit.from_file("input.html", "out.pdf", options=options)

wkhtmltopdf documents controls for page size (including custom dimensions), orientation, margins, print media, JavaScript behavior, and local-file access. Consult its usage documentation for supported options and exact behavior. Availability can depend on the installed build, so an option documented upstream may not work in every packaged binary.

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.

Debug failed or unexpected conversions

Start with the converter’s own diagnostics. PDFKit supports verbose=True; if that is not enough, inspect the generated command and run it directly to separate a wrapper issue from a wkhtmltopdf issue.

import pdfkit

pdf = pdfkit.PDFKit("input.html", "file", options={"page-size": "A4"})
print(pdf.command())

For local images, stylesheets, or other resources, check wkhtmltopdf’s local-file access controls and allow only the files the conversion needs. Its available controls are described in the wkhtmltopdf usage documentation.

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

Common errors and fixes

  • “No wkhtmltopdf executable found”: install wkhtmltopdf, confirm its executable is on PATH, or pass its full path through pdfkit.configuration.
  • The command fails or the output is wrong: enable verbose output, inspect the generated command, then run that command directly. The failure may come from wkhtmltopdf rather than the Python wrapper.
  • A page-size or rendering option appears ignored: check the installed binary and its supported features, then test the equivalent command-line option directly. Some distribution builds do not include patched-Qt functionality.
  • Local CSS, images, or fonts are missing: check whether local-file access is permitted by the installed wkhtmltopdf version, and grant access only to necessary resources.

Security and maintenance considerations

The wkhtmltopdf project warns against using the converter with untrusted HTML and says to sanitize user-supplied HTML and JavaScript; otherwise, it can lead to a complete server takeover. Treat user-controlled markup and scripts as untrusted input. The PDFKit wrapper does not make them safe.

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

The Python-PDFKit README marks the library deprecated to match the status of the wkhtmltopdf project. That makes it important to assess maintenance and rendering requirements before choosing it for a new system. The documentation cited here does not establish a specific replacement recommendation.

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

Or skip the browser setup

If your task is to capture a web page as a PDF rather than run an HTML-to-PDF conversion locally, ScreenshotNeo provides a screenshot API and MCP server. A single request can return a PDF; the API also supports page ranges, paper size, margins, and landscape output. See the ScreenshotNeo API documentation for request options.

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

Cookie banners are accepted and removed before capture, along with known newsletter popups and chat widgets. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed. An MCP server lets AI agents use the screenshot tools. The Free plan includes 1,000 screenshots per month with no card required; paid plans start at $5 for 3,000 screenshots.

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

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

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.

Frequently Asked Questions

Can I get PDF data without creating a file?

Yes. Omit the output-path argument in a PDFKit conversion call and assign the returned PDF bytes to a variable.

Does installing pdfkit also install wkhtmltopdf?

No. PDFKit is a Python wrapper; wkhtmltopdf is a separate executable that must be installed and discoverable or explicitly configured.

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.