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

Use Playwright’s page.pdf() in Chromium to export a page to PDF. Keep links as ordinary HTML anchors with valid href attributes, then check the exported PDF in the viewer your readers will use: the Playwright API documents PDF generation, but does not expressly guarantee that every link will become a working PDF link annotation.

Convert a web page to PDF with Playwright

Install Playwright and its Chromium browser, then navigate to the page and call page.pdf(). This JavaScript example saves the returned PDF to disk:

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  try {
    const page = await browser.newPage();
    await page.goto('https://example.com', { waitUntil: 'networkidle' });
    await page.pdf({ path: 'page.pdf', format: 'A4', printBackground: true });
  } finally {
    await browser.close();
  }
})();

The networkidle wait condition is an example, not a universal choice. Pages that continually poll or load content on demand may need a different condition or an explicit wait for the content you need. For supplied HTML, finish setting the content and allow its required rendering or assets to load before exporting.

page.pdf() returns a PDF buffer. Supplying path writes the file; omit it if you want to handle the buffer in your own code. Check the current Playwright Page API for the options supported by your installed version.

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.

Keep links in the HTML and verify the PDF

Use standard anchors and preserve their destinations in the HTML you render:

<a href="https://example.org">Reference</a>
<a href="#details">Jump to details</a>

<h2 id="details">Details</h2>

An anchor with an href represents a hyperlink in HTML; that fact alone does not prove that a particular PDF export will create an active link annotation. After export, open the PDF in the intended viewer and test both an external link and an in-document link. If links are absent or inactive, confirm that the rendered source still contains the intended anchors and destinations, then inspect the PDF itself. The HTML Standard describes hyperlink markup, while the Playwright API reference does not explicitly promise preservation of clickable links in the PDF.

Choose print or screen styling deliberately

Playwright generates PDFs using print CSS media by default. As the Page API puts it, “page.pdf() generates a pdf of the page with print css media.” Rules in @media print can hide elements, alter colors, or change layout, so a PDF may differ substantially from what appears on screen.

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.

Use print styling for a document-oriented PDF

Leave the default media behavior in place when the PDF should follow the page’s print layout. Inspect the page’s @media print rules and @page settings if content is missing, breaks awkwardly, or uses unexpected paper dimensions.

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

Emulate screen media when the screen appearance is the goal

Set screen media before calling page.pdf() if you specifically want screen CSS to apply:

await page.emulateMedia({ media: 'screen' });
await page.pdf({ path: 'page.pdf', format: 'A4', printBackground: true });

This changes which CSS media rules apply; it does not make the PDF a screenshot or remove the need to choose paper layout settings. Verify the result, especially where the site’s screen layout is wider than the selected paper.

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.

Set paper size, margins, and page layout

The main layout options documented for page.pdf() are format or explicit dimensions, margins, page ranges, scale, background printing, and whether CSS page size takes precedence. The API documents Letter as the default format, scale as 1, and preferCSSPageSize, background printing, outline, and tagged output as false by default. Set important values explicitly rather than relying on defaults that may not match your intended output.

Option What to set or check
format Choose a named paper format, such as A4. The documented default is Letter.
width and height Use explicit dimensions when a named format is not appropriate. Consult the API reference for accepted values and option details.
margin Set top, right, bottom, and left margins to control the printable area.
pageRanges Request only the pages you need when exporting a long document.
scale Adjust the rendering scale if content does not fit as intended; the documented default is 1.
printBackground Enable it when backgrounds are part of the design; it defaults to false.
preferCSSPageSize Enable it when the page’s CSS @page size should take precedence over the PDF paper settings; it defaults to false.
outline and tagged These options default to false. Check the current API reference for their behavior and support in your installed version.

For example, the code above explicitly selects A4 and prints backgrounds. If the page defines an @page size, decide whether that CSS or your Playwright format should control the output; do not assume the two settings will be reconciled the way you intend.

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

Install the browser and understand the Chromium requirement

Playwright’s PDF export is Chromium-only. Playwright supports Chromium, WebKit, and Firefox for browser automation generally, but its PDF export capability is not uniform across those engines. Use chromium for this workflow. See Playwright’s PDF Export tool documentation and its browser installation guide.

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

Install the Playwright package and the matching browser binary in the environment where the script runs. On Linux or a fresh CI machine, install Chromium’s required operating-system dependencies using the commands in Playwright’s browser guide. Keep Playwright and its browser installation aligned, and update them regularly as recommended in that guide.

Troubleshoot missing links and layout problems

The PDF opens, but links do not work

  • Confirm that the HTML contains ordinary <a href="..."> elements and that their destinations are correct.
  • Test external and in-document destinations separately in the target PDF viewer.
  • Check the exported PDF in another viewer if behavior differs. The Playwright API reference does not make an explicit guarantee about clickable PDF annotations, so verify the actual file rather than inferring link support from the HTML alone.

The PDF looks different from the browser

  • Remember that PDF generation uses print media by default. Review the page’s @media print styles and switch to emulated screen media only if that is the intended result.
  • Inspect @page rules and choose intentionally between CSS page sizing and Playwright’s format or dimensions through preferCSSPageSize.
  • Adjust margins, scale, or paper size when content is clipped or breaks poorly. Enable printBackground if necessary backgrounds are missing.

The page is incomplete or the browser cannot launch

  • If content is missing, wait for the page-specific content or assets your export needs; a generic load condition may not cover a dynamic application.
  • If Chromium does not launch in a clean environment, install the browser binary and required OS dependencies using Playwright’s browser installation instructions.
  • If browser and package versions have drifted, update Playwright and reinstall or update its browser binaries following the same guide.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use Chrome’s command line only when you do not need Playwright control

Chrome’s headless command-line interface also documents printing a target page to PDF with --print-to-pdf. It provides an optional flag to omit headers and footers and a timeout flag for page capture. This can suit a direct Chrome command-line task, but it is not a replacement for Playwright’s page-level automation when you need to prepare a page, wait for application state, or configure the documented page.pdf() options. See the Chrome headless command-line reference.

Or skip the browser setup

For a URL-to-PDF request, ScreenshotNeo offers a single API call rather than a locally installed Playwright browser. Its PDF API options include paper size, margins, landscape, and page ranges. It also accepts cookie-consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the page verdict and billing status in headers. An MCP server exposes take_screenshot, get_page_info, and capture_pdf to AI agents and other MCP clients.

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://example.com -o page.pdf

See the ScreenshotNeo API documentation for request options. ScreenshotNeo has a free plan with 1,000 shots per month and no card; paid plans start at $5 for 3,000 shots. Learn more at ScreenshotNeo, or 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 Playwright create PDFs with Firefox or WebKit?

No. The documented Playwright PDF export capability is Chromium-only.

Does a valid HTML href guarantee a clickable link in the PDF?

No. Check the exported file in the PDF viewer you intend to use.

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.