Use Puppeteer to open a fully qualified URL in a browser and save the rendered page as a PDF with page.pdf(). The key choices are when the page is ready to print and whether the output should use print or screen styles. The example below uses Puppeteer’s documented API, with PDF option defaults referenced against version 25.12.0; check the current documentation if you use another version.
Install Puppeteer and create a PDF
In a new project, install Puppeteer, which downloads a compatible browser for its default setup:
npm install puppeteer
Save this as convert.js in the project directory. It uses ES module syntax; use a .mjs filename or set "type": "module" in package.json.
import puppeteer from 'puppeteer';
const url = 'https://example.com';
const outputPath = 'page.pdf';
const browser = await puppeteer.launch();
try {
const page = await browser.newPage();
const response = await page.goto(url, {
waitUntil: 'networkidle2',
timeout: 30_000,
});
if (response && !response.ok()) {
throw new Error(`Page returned HTTP ${response.status()}`);
}
await page.pdf({
path: outputPath,
format: 'A4',
printBackground: true,
});
} finally {
await browser.close();
}
Run it with node convert.js. The file is written relative to the current working directory, not necessarily the script’s directory. Replace https://example.com with the target URL, including https:// or http://. Puppeteer’s getting-started guide covers the launch, page, navigation, and close flow: Puppeteer getting started. See the Page API for page.pdf().
#1 Best Overall
- 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.
Why the browser closes in finally
Closing the browser after success and after errors prevents a failed navigation or PDF write from leaving a Chromium process running. If you need to create several PDFs in one process, reuse the browser and create a fresh page for each job; close the browser when the batch is finished.
Choose when navigation is ready
page.goto() resolves with the main resource response, including the final response after redirects. A resolved navigation does not by itself prove the response was successful: inspect its status when the target may return an HTTP error. The navigation method documents a default lifecycle condition of load; the example explicitly chooses networkidle2. See Page.goto() and WaitForOptions.
| Readiness choice | When it can fit | Trade-off |
|---|---|---|
load |
Pages whose important content and assets are ready at the load event. | Client-rendered content may still be updating after load. |
networkidle2 or another network-idle condition |
Pages that settle after their network activity quiets down. | Some sites keep connections or requests active, so waiting for network idle can time out or be unsuitable. |
| Page-specific signal | Applications that expose a known element or readiness condition after rendering. | You must identify a reliable signal for that site; there is no universal signal or readiness condition. |
For a page-specific signal, navigate using an appropriate lifecycle such as domcontentloaded, then wait for a selector the site displays only when its content is ready:
Rank #2
- 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.
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30_000 });
await page.waitForSelector('[data-page-ready="true"]', { timeout: 15_000 });
Replace the selector with one that actually exists on the target page. If the application has another documented ready signal, use that instead. Navigation lifecycle values can be passed singly or as an array; when using an array, all listed conditions must occur.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Set the PDF page layout
Puppeteer generates PDFs using print CSS by default, so the result may use a website’s print-specific layout rather than looking like its screen view. Set the media type to screen before calling page.pdf() if the screen stylesheet is the intended output:
await page.emulateMediaType('screen');
await page.pdf({ path: 'page.pdf', format: 'A4', printBackground: true });
For print output, backgrounds are not included unless you set printBackground: true. The available PDF options include paper format, landscape orientation, margins, page ranges, scale, output path, and font readiness. In the PDF options documented for Puppeteer 25.12.0, the paper format defaults to letter, waitForFonts defaults to true, and the PDF timeout is documented as 30 seconds. See the PDFOptions reference for the version-specific details.
Rank #3
- 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.
Let the page’s CSS set its paper size
If the page uses CSS @page rules to define its paper dimensions, set preferCSSPageSize: true so those dimensions take priority over the PDF format, width, or height options. Its documented default is false.
await page.pdf({
path: 'page.pdf',
printBackground: true,
preferCSSPageSize: true,
});
Set margins, orientation, and page range
Specify margins and landscape mode when the output needs them. Use pageRanges for selected pages rather than generating every page:
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallawait page.pdf({
path: 'page.pdf',
format: 'A4',
landscape: true,
margin: { top: '12mm', right: '12mm', bottom: '12mm', left: '12mm' },
pageRanges: '1-3',
printBackground: true,
});
Remove pageRanges to include the full document. Confirm the output layout for the target site: print styles, content length, and the chosen paper dimensions affect pagination.
Rank #4
- 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
Convert HTML already in memory
If you already have HTML as a string, set it on a page instead of navigating to a remote URL. This does not automatically provide remote resources or application-specific readiness; those depend on the HTML and how its referenced assets are made available.
const html = '<!doctype html><html><body><h1>Report</h1></body></html>';
const page = await browser.newPage();
await page.setContent(html);
await page.pdf({ path: 'report.pdf', format: 'A4', printBackground: true });
The method signature is documented at Page.setContent().
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If you want a PDF from one request instead of managing Puppeteer and Chromium, ScreenshotNeo accepts a URL and can return a PDF. Its API also accepts the parameter names used by other screenshot APIs. See the ScreenshotNeo API documentation.
Best Value
- 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.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.pdf
ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks, blank pages, and failed loads are not billed, and response headers identify the page verdict and billing status. Its MCP server lets AI agents use screenshot and PDF tools. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo’s free plan.
Troubleshoot common failures
- Invalid URL: Include the scheme, such as
https://, and confirm the address is correctly formed. - Navigation timeout: The site may be slow, unreachable, or still making network requests. Increase the navigation timeout if appropriate, or switch from a network-idle condition to a suitable lifecycle and wait for a page-specific readiness signal.
- SSL error or unreachable server: Check that the URL opens from the machine running Node.js and that its certificate and network access are valid.
page.goto()can reject on SSL errors, timeouts, and unreachable servers. - PDF contains an error page: Check the response returned by
page.goto(). A navigation can resolve with an HTTP error status; inspectresponse.status()instead of assuming it succeeded. - PDF document as the navigation target: In headless shell mode,
page.goto()does not support navigating to a PDF document. Use a web page URL for this workflow. - Missing backgrounds or unexpected colors: Set
printBackground: truewhen backgrounds matter. Print rendering can change colors; use screen media only if screen styling is what you want. - Different layout or page breaks: Check the site’s print CSS and
@pagerules. SetpreferCSSPageSize: truewhen CSS page dimensions should take priority. - Browser launch mismatch: Puppeteer is only guaranteed to work with its bundled browser; using another browser is at your risk. See the LaunchOptions reference.
Performance and reliability considerations
There is no single readiness setting that is best for every page: network-idle waits can be a poor fit for pages with ongoing requests, while a page-specific signal is only useful if the target exposes one reliably. Choose navigation and readiness timeouts for the page you are converting, and treat timeout, navigation, and PDF-generation failures as errors your application must handle. The documentation cited here does not establish a universal conversion speed or success rate.
For repeated conversions, reuse the browser process rather than launching one for each URL, while keeping page state isolated where needed. Puppeteer and browser behavior can change; the PDF options cited above are from the Puppeteer 25.12.0 reference, and Puppeteer’s bundled-browser guarantee matters when selecting a runtime.
Frequently Asked Questions
Does Puppeteer save a PDF in the current directory?
Yes. A relative `path`, such as `page.pdf`, is resolved from the Node.js process’s current working directory.
Can Puppeteer include backgrounds in a PDF?
Yes. Pass `printBackground: true` to `page.pdf()`.
Can I use a URL without `https://`?
Use a fully qualified URL with a scheme such as `https://` or `http://`.
Quick Recap
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.

