Use the Chrome DevTools Protocol (CDP) Page.printToPDF command to create a PDF from a page rendered in Chrome. Navigate and prepare the page, call the command with your print settings, then save its base64-encoded PDF data—or read a stream if you select stream transfer. The key caveat is readiness: navigation returning does not mean that dynamic content, images, or other assets are ready to print.
How CDP converts a webpage to PDF
Page.printToPDF is a command in CDP’s Page domain. Your application connects to a Chrome target through a CDP client, prepares the page, and sends the print command. The protocol defines options for page geometry, orientation, margins, scaling, page ranges, backgrounds, headers and footers, CSS page sizing, and PDF transfer mode. See the CDP Page.printToPDF protocol definition.
CDP is the browser-control protocol, not a complete browser-launch or session-management library. The way you launch or attach to Chrome, create a session, enable the Page domain, and send commands depends on the CDP client you choose. The protocol documentation describes the command and its parameters; it does not prescribe one universal client setup.
Prepare the page before printing
- Connect to the intended Chrome target. Create or attach a CDP session using your chosen client.
- Enable the Page domain if your client requires it. Follow the client’s session and domain setup conventions.
- Navigate to the page and check readiness. Wait for the content and assets needed in the PDF. A navigation event alone is not proof that scripts, lazy-loaded images, or other dynamic content have finished.
- Call
Page.printToPDF. Supply the print options that matter for your output instead of relying on defaults when consistency is important. - Save the result. Decode the returned base64 data, or read and close the returned stream if you selected stream transfer.
There is no single readiness signal that suits every site. Choose a condition that reflects the page you need—for example, the appearance of a page-specific element or completion of your own application’s rendering work—and handle timeouts or missing content explicitly.
#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.
Choose print settings deliberately
Paper size, CSS page rules, and orientation
You can provide paper width and height, or set preferCSSPageSize when the page’s @page CSS should determine the PDF’s paper size. Decide which should take precedence for your workflow; do not assume CSS sizing and explicit dimensions will produce the same layout. Set landscape orientation when the document calls for it, then inspect the pagination: orientation and scale can change where content breaks, but neither guarantees readable output for every page.
Scale, margins, and page ranges
Use scale to adjust how the printed layout fits the selected paper, and margins to reserve or remove space around the page content. For a partial document, provide page ranges and decide how invalid ranges should be handled with the protocol’s invalid-range option. Check the result when the document length can change; a range that works for one version may not fit another.
Backgrounds and headers or footers
Background printing is controlled separately. Enable it when page background colors or images belong in the PDF. Header and footer templates accept HTML and can use the documented substitutions for date, title, URL, page number, and total page count. Keep templates simple and verify their appearance in the generated document.
Tagged PDFs and document outlines
The protocol exposes options for tagged-PDF generation and document outlines. These are available output controls, not a guarantee of a particular accessibility conformance level. Review the resulting PDF against the accessibility requirements of your use case.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchRank #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.
Handle the PDF response
By default, the command returns PDF data encoded as base64. Decode it to bytes before writing a PDF file; writing the base64 text itself produces an invalid file. With stream transfer selected, the response instead contains a stream handle. Read it using the IO mechanism supported by your CDP binding, continue until the stream is exhausted, and close it when finished. The protocol schema defines these response forms, while the exact read and close calls vary by client. See the CDP IO domain.
Base64 is straightforward for modest outputs. A stream workflow may better suit callers that want to consume the result incrementally, but it requires stream handling in the client. Choose based on your application’s output-handling needs; the documentation does not establish a universal size threshold.
When Puppeteer may be a better fit
If your application already uses Puppeteer, its page.pdf() method offers a higher-level library API and returns PDF bytes. Puppeteer documents print CSS media as the default for PDF generation; call page.emulateMediaType('screen') first if you need screen media instead. Its documentation also describes -webkit-print-color-adjust for controlling print color adjustment. These are Puppeteer behaviors, not evidence that its options are identical to raw CDP’s. See the Puppeteer PDF API.
Choose raw CDP when your application already manages CDP sessions or needs to work directly with protocol commands and transfer modes. Choose Puppeteer when its browser-automation library API fits your existing application. The documented interfaces do not establish a performance winner or a complete feature-by-feature equivalence.
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.
Or skip the browser setup
If you need a screenshot or PDF endpoint rather than managing Chrome and CDP sessions, ScreenshotNeo is a website screenshot API and MCP server. Its one-request screenshot endpoint accepts a URL and can return PNG, JPEG, WebP, or PDF. For example, this cURL request saves a PDF:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -d format=pdf -o page.pdf
See the ScreenshotNeo API documentation for request parameters and response details. Cookie banners are accepted and removed before capture, along with known newsletter popups and chat widgets; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots.
Sign up free for 1,000 screenshots a month—no card required.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshooting CDP PDF generation
The PDF is blank or missing recently added content
Likely cause: The print command ran before the page finished rendering the content you need. A completed navigation does not establish that scripts, lazy-loaded images, or asynchronous requests are done.
Recommended Free Tools
Fix: Add a page-specific readiness check before printing. Confirm that the required content exists and that the application has completed any rendering work relevant to the PDF. Set a timeout and treat a missing readiness condition as an explicit failure rather than silently saving an incomplete document.
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
The saved file is not a valid PDF
Likely cause: The response’s base64 string was written as text, or a stream response was treated as base64 data.
Fix: Check the selected transfer mode. Decode base64 to binary bytes for the default response. For stream transfer, read the handle using the client’s IO support, then close it.
The output has unexpected page size or clipping
Likely cause: The PDF’s paper size, CSS @page rules, orientation, scale, or margins do not match the intended print layout.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesFix: Decide whether explicit paper dimensions or CSS page sizing should control the result, set the relevant options deliberately, and inspect page breaks and margins in the output.
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.
Colors or page decoration are missing
Likely cause: Background printing is not enabled, or the page’s print styles differ from its on-screen appearance.
Fix: Enable background printing when appropriate and review the page’s print CSS. If using Puppeteer and you need screen styles, emulate screen media before generating the PDF.
Headers or footers show unexpected text
Likely cause: The template HTML or its substitution values do not match the intended output.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Fix: Review the header and footer templates and use the documented substitutions for date, title, URL, page number, and total pages. Inspect a generated file rather than assuming the template rendered as intended.
A requested page range fails or omits pages
Likely cause: The range does not fit the actual number of pages, or invalid-range behavior is not configured for the case.
Fix: Check the produced document’s page count and choose the protocol’s invalid-range behavior to suit your application. Avoid hard-coding ranges if the document’s length varies.
Quick Recap
Operational considerations
- Readiness is application-specific. A site’s scripts and print styles determine what is ready and what appears; CDP does not make every dynamic page complete merely by issuing the PDF command.
- Inspect representative output. Check page breaks, scale, margins, backgrounds, and headers or footers against the documents your workflow actually produces.
- Handle failures as failures. Make session errors, timeouts, absent readiness conditions, and stream-read errors visible to the caller instead of returning an incomplete file as success.
- Do not infer guarantees from options. Tagged-PDF and outline options exist, but enabling them alone does not establish an accessibility conformance level.
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.
Free tools Windows power users keep installed
One-click scans. No signup required.

