Use chromedp to control Chrome from Go, wait for the page to reach an application-specific ready state, then call Chrome DevTools Protocol’s Page.printToPDF method and write its returned bytes to a PDF file. For a simple URL-to-file job, Chrome’s headless command-line interface can print the page without a Go browser workflow.
Choose chromedp or Chrome’s command line
| Approach | Best fit | Control and lifecycle |
|---|---|---|
| Chrome CLI | A one-off URL capture or shell automation. | Pass a URL and print-related flags to Chrome. Your Go program does not manage navigation or browser-tab state. |
| chromedp | A Go application that needs to prepare a page, interact with it, wait for a condition, or configure print settings. | Go manages a browser context and sends Chrome DevTools Protocol commands, including Page.printToPDF. |
This distinction follows the interfaces documented by Chrome and chromedp; it is not a performance comparison. Both approaches ultimately use Chrome’s print pipeline.
Install the Go and browser dependencies
-
Add and pin
github.com/chromedp/chromedpand the matchinggithub.com/chromedp/cdprotodependency in your Go module. The project documents installation through Go tooling and provides a headless-shell image as an option for headless deployments: chromedp README and FAQ. -
Make a compatible Chrome or Chromium executable available to chromedp, or use a deployment that supplies the browser. Pin dependencies and verify the generated binding’s signatures against the version you use; the protocol and repository documentation are rolling references.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →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.
-
Choose the target page. For a public page, navigate to its URL. For HTML you generate, serve it at a URL the browser can reach or load it through the browser workflow appropriate to your application.
Convert a page with chromedp
The essential sequence is to create a chromedp context, navigate, wait for the page’s actual readiness condition, call Page.printToPDF, and write the resulting bytes. The following illustrates the protocol call shape; check the returned values and builder methods against the pinned cdproto version before using it as copy-paste code.
ctx, cancel := chromedp.NewContext(context.Background())
defer cancel()
var pdf []byte
err := chromedp.Run(ctx,
chromedp.Navigate(targetURL),
// Add a readiness action appropriate to the page here.
chromedp.ActionFunc(func(ctx context.Context) error {
var err error
pdf, _, err = page.PrintToPDF().
WithPrintBackground(true).
WithPreferCSSPageSize(true).
Do(ctx)
return err
}),
)
if err != nil {
return err
}
if err := os.WriteFile("output.pdf", pdf, 0600); err != nil {
return err
}
This example requires imports for context, os, github.com/chromedp/chromedp, and github.com/chromedp/cdproto/page, plus a definition for targetURL. The exact return signature can vary with generated binding versions; see the cdproto page binding for the version you select. Page.printToPDF is Chrome’s protocol operation for printing the page as PDF: Page domain reference.
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.
Wait for your page, not an arbitrary delay
Navigation completing does not prove that client-side rendering, data fetching, fonts, or other asynchronous work has finished. Wait for a selector, application signal, or other condition that means the content you need is ready. There is no universal fixed sleep that guarantees readiness across sites.
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 minutePC 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 & 11Handle context cancellation and errors
Use the context created by chromedp.NewContext for the browser actions and protocol calls so chromedp can associate them with browser and tab state. Defer cancellation, and return or handle errors from navigation, printing, and file output. The chromedp project notes that on Linux it kills Chrome child processes it started when the program finishes; a lost browser connection can cancel the context. See its README and FAQ.
Set PDF layout and print options
Page.printToPDF exposes settings for paper dimensions, margins, portrait or landscape orientation, scale, page ranges, headers and footers, background printing, CSS page-size preference, tagged output, document outlines, and stream transfer mode. Consult the protocol reference and the generated Go binding for parameter names and availability in your pinned version.
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.
- Paper size and margins: Set these in the protocol call when you need explicit dimensions or printable margins.
- Orientation and page range: Choose portrait or landscape and limit output to selected pages when appropriate.
- Backgrounds: Enable background printing if colored fills or background images are part of the intended document.
- Headers and footers: Configure protocol templates when needed; the binding defaults do not display headers or footers.
- CSS-driven layout: Author
@media printand@pagerules in the page. SetpreferCSSPageSizewhen the CSS page size should take precedence. If CSS page size is not preferred, Chrome documents that content is scaled to fit the chosen paper size. - Large output: The protocol documents a stream transfer mode as well as its other return behavior. Consider it when handling large PDFs, and follow the selected binding’s API for reading the result.
The generated Go binding documents defaults including portrait orientation, no displayed header or footer, backgrounds disabled, and PreferCSSPageSize false. Confirm defaults and supported parameters against the binding version in your module.
Use Chrome’s headless CLI for a direct URL capture
For a simple URL-to-PDF task, Chrome’s documented command is:
chrome --headless --print-to-pdf https://developer.chrome.com/
Chrome writes output.pdf in the current working directory. To suppress Chrome’s built-in date/time and URL/page-number header and footer, use:
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
chrome --headless --print-to-pdf --no-pdf-header-footer https://developer.chrome.com/
Chrome documents --timeout as a maximum wait before capture even if loading is ongoing, and --virtual-time-budget as a way to fast-forward time-dependent page code for capture. These timing controls are not a universal guarantee that an application has finished rendering. Chrome’s documentation says previous versions may require the older --print-to-pdf-no-header flag. Check the headless CLI reference for the version you run.
Troubleshoot common conversion problems
- The PDF is blank or missing dynamic content: Printing began before the page was ready. Replace a generic delay with a wait for the application’s content or readiness signal.
- The command cannot find Chrome: Ensure the Chrome executable is installed and available to the process, or provide the appropriate browser configuration for your environment.
- Navigation or printing returns an error: Check the returned error, ensure browser actions use the chromedp context, and verify that the browser process is still reachable. A lost browser connection can cancel the context.
- The file is missing or cannot be written: Check the output path and the process’s write permissions; handle errors from
os.WriteFile. - Print colors or images are absent: Enable background printing in the protocol parameters if backgrounds are required, and verify the page’s print CSS.
- Content is unexpectedly scaled or paginated: Check the paper dimensions, margins, scale, page size in
@page, and thepreferCSSPageSizesetting. - CLI headers remain visible: Use
--no-pdf-header-footeron versions that support it; the Chrome reference notes an older flag name for previous versions.
Or skip the browser setup
If your goal is to capture a website rather than build a Go-controlled PDF workflow, ScreenshotNeo provides a screenshot API and MCP server. Its PDF endpoint can return a PDF in one request:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.pdf
See the ScreenshotNeo documentation for request options. Cookie and consent banners, newsletter popups, and chat widgets are removed before capture; bot checks, blank pages, and failed loads are not billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000.
Recommended Free Tools
Sign up for ScreenshotNeo’s free plan to try it with 1,000 screenshots a month and no card.
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.
Frequently Asked Questions
Does headless Chrome use the same print-to-PDF operation as chromedp?
Yes. chromedp sends Chrome DevTools Protocol commands to Chrome; the PDF operation is the Page domain’s print-to-PDF method.
Can Chrome’s CLI wait until every web app has finished rendering?
No universal readiness condition is documented. Its timeout and virtual-time options control capture timing, but application-specific asynchronous work may need its own readiness check in a Go workflow.
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.

