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

For a one-off webpage or content that depends on browser JavaScript, use headless Chrome or Chromium: chromium --headless --print-to-pdf=page.pdf 'https://example.com/'. For repeatable application workflows, use Puppeteer or Playwright; for authored HTML/CSS documents, consider WeasyPrint. Prince is a commercial option for specialized publishing. The right renderer depends on the page, the CSS it uses, and how much control your workflow needs.

How do I choose an HTML-to-PDF converter on Linux?

Start with the input and the job, not a blanket claim that one engine is best. A live website that depends on JavaScript generally calls for a browser engine; a controlled report or document may suit a print-focused renderer. Also consider whether you need a shell command or application-level control, advanced page layout, and isolation for untrusted input.

Need Good starting point Key consideration
Save a live webpage once from a shell Chrome or Chromium headless CLI Simple URL-to-PDF command; capture timing may need adjustment.
Generate PDFs within Node.js browser automation Puppeteer Control navigation and page state; PDF output uses print media by default.
PDF generation is part of an existing browser automation workflow Playwright Provision its compatible browser build or headless shell on Linux.
Render authored HTML and CSS as a print document WeasyPrint It is not a full browser for JavaScript-dependent pages; check CSS support and dependencies.
Specialized paged publishing Prince Commercial software; verify current licensing and test your documents.

How do I save a webpage as a PDF from the Linux command line?

Chrome’s headless CLI can print a URL without a conversion script. Chrome documents that --print-to-pdf saves a PDF named output.pdf in the current working directory when no filename is supplied (Chrome Headless command-line reference).

  1. Check which executable your Linux package provides. Depending on the distribution and package, it may be chrome, chromium, or chromium-browser.
  2. Run a command such as chromium --headless --print-to-pdf=page.pdf --no-pdf-header-footer 'https://example.com/'.
  3. Open page.pdf and verify page breaks, fonts, images, and any content populated by JavaScript.

--no-pdf-header-footer suppresses the browser’s URL/date/page-number furniture. To allow delayed content more time, Chrome documents --timeout=5000; it also documents --virtual-time-budget=42000 for advancing time-dependent code. For example:

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.

chromium --headless --print-to-pdf=page.pdf --no-pdf-header-footer --timeout=5000 'https://example.com/'

These options affect capture timing; they do not prove that all network requests or application activity have finished. A delayed page may need app-specific readiness handling or a scripted browser workflow instead.

When should I use Puppeteer or Playwright?

Use browser automation when PDF generation is a repeated application task and you need to control navigation, authentication, page state, or output settings. Puppeteer provides a Node.js page.pdf() API. Its documented behavior uses print CSS by default and waits for fonts; call page.emulateMediaType('screen') before printing if the screen stylesheet is the desired output (Puppeteer PDF generation, Page.pdf() API).

Puppeteer: runnable starting point

Install Puppeteer in your Node project using its current installation guidance, then save this as a JavaScript file and run it with Node:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

const puppeteer = require('puppeteer');
async function main() {
  const browser = await puppeteer.launch();
  try {
    const page = await browser.newPage();
    await page.goto('https://example.com/', { waitUntil: 'networkidle2' });
    await page.pdf({ path: 'page.pdf' });
  } finally {
    await browser.close();
  }
}
main().catch(error => { console.error(error); process.exitCode = 1; });

networkidle2 is only a navigation choice, not a universal signal that a page is ready to print. Sites with long polling, lazy-loaded assets, login flows, or application-specific rendering may need explicit waits or setup. For screen styling, add await page.emulateMediaType('screen'); before page.pdf().

Playwright: use it when it fits your automation stack

Playwright is a sensible choice when your application already uses its browser automation APIs. On Linux, plan for its browser distribution model: its documentation distinguishes regular Chromium builds from a separate headless shell and describes installing only the shell for jobs that need it (Playwright browsers). Follow the installation instructions for the Playwright version and deployment environment you use; do not assume any arbitrary system browser will match.

When is WeasyPrint a better fit?

WeasyPrint is a print-oriented HTML/CSS renderer with command-line and Python interfaces. It accepts a local file or URL, but it should not be treated as a full browser for pages whose meaningful content depends on JavaScript. Its documentation says unsupported CSS properties can produce warnings, so inspect both logs and output (WeasyPrint 70.0 First Steps, WeasyPrint documentation).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

Command-line conversion

For a local document, run:

weasyprint report.html report.pdf

The same CLI accepts a URL as input. Ensure relative images, stylesheets, and fonts resolve from the input location and that the process can access any remote resources it needs.

Set page size and margins with CSS

WeasyPrint uses CSS @page rules for page geometry rather than command-line page-size flags. Put a rule in the document stylesheet or pass a stylesheet with -s print.css:

@page {
  size: A4 portrait;
  margin: 15mm;
}

Its version 70.0 documentation lists Python 3.10 or newer and Pango 1.44 or newer among dependencies. Recent Debian, Ubuntu, Fedora, Arch Linux, and Gentoo releases package WeasyPrint, but package availability and dependency handling vary by release. Check the current requirements for your Linux distribution before installing; where a distribution package is not suitable, use the documented Python installation route in an appropriately managed environment.

What about Prince and wkhtmltopdf?

Prince for specialized publishing

Prince documents HTML and XML conversion, CSS and JavaScript support, command-line operation, and advanced paged output. It is commercial software. Test representative documents and confirm current Linux licensing and product details before adopting it; available documentation does not establish a current price (Prince user guide, Prince version 12 reference).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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

wkhtmltopdf for an existing deployment

The official project describes wkhtmltopdf as an open-source command-line tool based on Qt WebKit (wkhtmltopdf). That description alone does not establish its current maintenance status or suitability for a new web application. Before choosing it, check releases, distribution packages, security maintenance, and output against your actual pages.

What should I check before choosing a renderer?

  • JavaScript: If scripts create the content you need, choose a browser-based engine and make readiness explicit. Do not assume a print-focused renderer will execute page JavaScript.
  • Print CSS and page layout: Check page size, margins, breaks, headers and footers, colors, fonts, and whether the engine supports the CSS your document uses.
  • Assets and access: Confirm the renderer can reach stylesheets, images, fonts, and authenticated content. Relative paths and inaccessible remote resources commonly produce incomplete PDFs.
  • Workflow: A CLI is convenient for a one-off conversion; Puppeteer, Playwright, or WeasyPrint’s Python interface can be integrated into repeatable jobs.
  • Untrusted input: Treat HTML and CSS supplied by users as a security boundary. WeasyPrint warns that untrusted content can access local files, consume excessive resources, run for a long time, or fetch network resources. Restrict filesystem and network access, filter fetches where appropriate, and cap runtime and memory; apply the chosen engine’s current security guidance.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How do I validate output and troubleshoot failures?

Before deploying a conversion workflow, test representative pages and inspect the actual PDFs. Check page breaks, print colors, fonts, headers and footers, images, links, and JavaScript-populated content. These checks help reveal mismatches in your own inputs; they are not a universal guarantee of fidelity.

Symptom Likely cause What to check
Command not found The executable name differs or the renderer is not installed. Check the package used on that distribution and the executable it provides.
Blank or incomplete page Navigation, scripts, or remote assets were not ready or accessible. Check network access, credentials, console or process errors, and app-specific readiness. A timeout alone does not establish that the page is ready.
Missing images, fonts, or styles Relative paths resolve differently, or resources cannot be reached. Use resolvable paths, check URL access and permissions, and inspect renderer warnings.
Unexpected layout or page breaks Print CSS differs from screen CSS, page geometry is not configured, or a CSS feature is unsupported. Review the rendered print styles; for WeasyPrint, configure @page and inspect warnings.
Linux automation browser fails to launch The automation package’s expected browser build or system dependencies are missing. Install the browser build required by that Puppeteer or Playwright version and deployment setup.
Conversion hangs or consumes too many resources Page activity does not settle, or input triggers expensive rendering or resource fetching. Set runtime and memory limits, restrict access for untrusted input, and define explicit readiness and fetch policies.

Or skip the browser setup

If your task is specifically to capture a webpage as a screenshot or PDF rather than manage a Linux PDF renderer, ScreenshotNeo is a website screenshot API and MCP server. A single GET request can return PNG, JPEG, WebP, or PDF. Its cleanup options accept cookie or consent banners like a visitor and remove more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, with response headers indicating page verdict and billing status. Developers can also connect its MCP server to Claude, Cursor, or another MCP client using take_screenshot, get_page_info, and capture_pdf.

For an HTML-to-PDF request, the API supports PDF output and parameters including paper size, margins, landscape orientation, and page ranges. Example using cURL (replace the URL with the page you want to capture):

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

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

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.

See the ScreenshotNeo API documentation for authentication and output options. The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Sign up for the free plan.

Frequently Asked Questions

Can I convert a local HTML file to PDF on Linux?

Yes. For example, run weasyprint report.html report.pdf; a browser-based renderer can also print a local page when its resources resolve correctly.

Does headless Chrome use print or screen CSS for PDF output?

Chrome’s PDF output follows the browser’s print behavior. In Puppeteer, PDF generation uses print media by default; call page.emulateMediaType('screen') first if you specifically need screen media.

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.