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

Use WeasyPrint: install it in the Python environment that will run the conversion, then pass the HTML filename to HTML and call write_pdf(). The basic conversion is one line; the important work is checking that the rendered pages contain the right resources, fonts, and page breaks.

Convert a local HTML file with WeasyPrint

For a local file named input.html, write the PDF to output.pdf like this:

from weasyprint import HTML

HTML(filename="input.html").write_pdf("output.pdf")

The explicit filename= argument makes it clear that the input is a file. The WeasyPrint Python API also accepts the filename positionally, as in HTML("input.html"). The write_pdf() call creates the PDF at the output path you provide. This is the documented basic pattern in WeasyPrint 70.0 First Steps.

Save the script in a location where it can access the input file, or supply paths that point to the files’ actual locations. The example uses relative filenames, so the paths must resolve correctly from the process’s working directory. If the script finishes without an error but the PDF is missing or incomplete, check the paths and inspect the rendered document before assuming the conversion succeeded as intended.

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.
#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.

Install WeasyPrint in the Python environment you will use

Install the package with pip through the intended Python interpreter:

python -m pip install weasyprint

Using python -m pip helps ensure that installation is associated with the Python command used to run the script. If your system uses a different executable name for the intended interpreter, use that executable consistently for both installation and conversion.

Installation is not necessarily just a Python-package step. The current WeasyPrint documentation identifies Python 3.10 or later and Pango 1.44 or later, alongside Python dependencies. On Linux, installing through the distribution’s package manager may be the easier route; a pip installation may still need native requirements to be present. Requirements and installation instructions can change, so consult the current WeasyPrint installation guidance for your operating system rather than assuming a command that works on one machine will work on another.

To diagnose the environment, the WeasyPrint documentation recommends checking the Python and Pango versions and running:

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

Run the check in the same environment where the conversion is expected to happen. A package installed in one virtual environment, container, or system Python installation will not automatically be available in a different one.

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.

Prepare HTML and its resources before converting

An HTML document may refer to stylesheets, images, and fonts separately from the HTML file. Those resources affect the final pages: missing CSS can change the layout, and missing images or fonts can alter or omit content. Confirm that the references point to the intended files and that the conversion environment can access them.

WeasyPrint’s documented Python example establishes that a filename can be passed to HTML; it does not establish that every relative-resource arrangement will work as expected. Therefore, do not infer that moving an HTML file into a script’s directory, or running the script from a different directory, preserves all its resource paths. Try the same directory structure and execution method you intend to use in production, then inspect the output.

  • Open the source HTML and identify its linked stylesheets, images, and fonts.
  • Check that each referenced resource exists and is accessible from the conversion environment.
  • Compare the PDF with the intended document, paying particular attention to page breaks, font appearance, image placement, and content near page edges.
  • Test representative files, not just the simplest page, before relying on the output for a recurring workflow.

Check layout and rendering limits

WeasyPrint is a document renderer, not a promise of pixel-for-pixel reproduction for every HTML page. Its Common Use Cases documentation says the validity of generated documents is not guaranteed for every combination of HTML, CSS, and PDF features: the chosen features must fit the relevant specifications and WeasyPrint’s implementation limits.

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

That qualification matters when a PDF is used as an official record, sent to customers, or generated in bulk. Browser-oriented HTML can contain combinations of styles or features that do not produce the layout you expect in a PDF renderer. Inspect representative outputs rather than judging the result solely by whether the conversion call completed.

Look specifically for unexpected page breaks, cut-off or displaced content, absent images, and font substitutions or differences. Adjust the source document or its print-oriented styling where needed, then convert it again and review the resulting PDF. The documentation supports testing against implementation limits; it does not establish universal compatibility for any particular site or CSS feature.

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.

Run repeated conversions efficiently

If a script converts many documents, consider keeping a Python API process alive rather than starting a fresh process for every file. WeasyPrint’s First Steps documentation says a long-lived process may avoid paying startup costs on each conversion. It does not provide a quantified speedup, so treat this as an operational option to evaluate with your own workload, not as a promised performance improvement.

Whichever execution model you choose, include a representative document in your routine checks. A process that stays alive does not remove the need to verify output quality, resource access, or the behavior of the HTML and CSS you are converting.

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

Use untrusted HTML and CSS cautiously

WeasyPrint’s First Steps documentation warns: “Using WeasyPrint with untrusted HTML or untrusted CSS may lead to various security problems.” This is especially relevant if a conversion service accepts content from users or processes files that your team did not create.

Do not treat an HTML-to-PDF converter as a safe place to render arbitrary input by default. If you are building a service around it, consult the project’s security guidance and constrain both the input and the resources the rendering process can access. The appropriate controls depend on how and where your service runs; the basic local-file example is not a security design for accepting public submissions.

What can appear in the resulting PDF?

WeasyPrint’s API Reference lists hyperlinks, bookmarks, attachments, and forms among the types of content that PDFs can contain, in addition to text and raster or vector graphics. That is a capability statement, not a guarantee that every such feature in a particular source file will transfer exactly. Check the PDF itself if one of these elements is important to the document’s use.

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
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common conversion problems

The import fails or installation reports missing requirements

Check that WeasyPrint was installed into the Python environment running the script. Confirm the documented Python and Pango requirements for your operating system, and use the WeasyPrint information command to inspect the environment. On Linux, consider whether the needed native requirements are installed through the distribution’s package manager.

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

The script cannot find the HTML file

Check the spelling of the filename and the directory from which the process runs. The sample uses a relative path, which is interpreted in relation to the working directory; it is not automatically relative to the script file. Use a path that points to the actual input location.

The PDF exists but styles, images, or fonts are missing

Review the HTML’s references and the directory layout used during conversion. The input file being found does not by itself establish that every referenced resource is available. Test the resource paths in the real execution environment and inspect the result after correcting them.

The output looks different from the browser view

Review the PDF for page breaks, font appearance, image placement, and content near page edges. WeasyPrint documents implementation limits across HTML, CSS, and PDF features, so a successful conversion does not prove that every visual detail is supported. Simplify or adjust the source where appropriate and test again.

The job is slow when converting files one at a time

If each document starts a separate Python process, evaluate a long-lived API process for repeated conversions. The documentation identifies avoiding repeated startup costs as a possible benefit, but gives no speed figure. Measure the workflow you actually deploy rather than assuming a particular gain.

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.

The input comes from users or another untrusted source

Pause before exposing the renderer to that input. WeasyPrint explicitly warns about security problems with untrusted HTML or CSS. Consult its security guidance and constrain what the rendering process can receive and access before building a user-facing conversion service.

Or skip the browser setup

For a webpage that is already available at a URL, ScreenshotNeo offers a screenshot API; this is a different workflow from converting a local HTML file with WeasyPrint. The example below captures a webpage as an image, not a PDF:

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

See the ScreenshotNeo API documentation for the request details. Before capture, it can accept cookie or consent banners like a visitor and remove more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and responses include X-Page-Verdict and X-Billed headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots, and yearly billing gives two months free. Every feature is available on every plan.

To convert a local HTML file to a PDF, use the WeasyPrint workflow above; do not substitute this webpage screenshot example for that job. For URL-based capture, sign up for 1,000 free screenshots a month with no card.

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

Choose the route that matches your input

For a local HTML file that needs to become a PDF, WeasyPrint provides a direct Python API call, subject to its dependencies and rendering limits. If the source is a published webpage and you need an image capture instead, ScreenshotNeo is a separate URL-based option. In either workflow, verify the generated file against the document’s actual requirements before depending on it.

Frequently Asked Questions

Can WeasyPrint generate tagged or archival PDFs such as PDF/A?

The available guidance does not establish that every source document or configuration will meet a particular accessibility or archival standard. Check the relevant WeasyPrint documentation and validate the produced PDF against the standard required by your workflow.

Will a PDF retain every link or form from the HTML?

The API Reference lists hyperlinks, bookmarks, attachments, and forms as content a PDF can contain, but that does not guarantee exact transfer for every source file. Check the actual output when those elements matter.

Can I convert an HTML document hosted at a URL with the same filename example?

The example shown uses a local filename. The cited quickstart establishes that file-input pattern, not the behavior or configuration for remote URL input; consult the current WeasyPrint API documentation for the appropriate input form.

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

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.