What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Use chromedp to drive Chrome or Chromium, navigate to the page, call Chrome’s Page.printToPDF method, and write the returned bytes to a file. The browser is a separate dependency: chromedp is the Go automation layer, not a bundled browser. The example below creates a PDF using the browser’s default print settings; choose explicit settings when the page’s paper size, margins, backgrounds, or headers and footers matter.
What you need
- A current Go toolchain and a Go module for your project.
- Chrome, Chromium, or a compatible remote DevTools Protocol endpoint that the process can use. chromedp does not bundle a browser.
The browser can run locally, in a container, on Windows or macOS, or behind a remote DevTools endpoint. A headless-shell container is one deployment option, not a requirement. Choose based on where you can supply and maintain the browser binary and how you want to manage browser lifecycle and isolation; the available project guidance does not establish comparative performance or cost.
Install chromedp and create a PDF
From the project directory, add chromedp:
go get github.com/chromedp/chromedp
Save this as main.go. It takes the page URL as the first command-line argument and writes the PDF to page.pdf:
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/chromedp/chromedp"
"github.com/chromedp/cdproto/page"
)
func main() {
if len(os.Args) < 2 {
fmt.Fprintln(os.Stderr, "usage: go run . <url>")
os.Exit(2)
}
ctx, cancel := context.WithTimeout(context.Background(), 90*time.Second)
defer cancel()
var pdf []byte
err := chromedp.Run(ctx,
chromedp.Navigate(os.Args[1]),
chromedp.ActionFunc(func(ctx context.Context) error {
data, _, err := page.PrintToPDF().Do(ctx)
if err != nil {
return err
}
pdf = data
return nil
}),
)
if err != nil {
fmt.Fprintln(os.Stderr, "capture page as PDF:", err)
os.Exit(1)
}
if err := os.WriteFile("page.pdf", pdf, 0o644); err != nil {
fmt.Fprintln(os.Stderr, "write page.pdf:", err)
os.Exit(1)
}
fmt.Println("Wrote page.pdf")
}
Run it with a URL:
go run . https://example.com
chromedp.NewContext creates an automation context; it does not start Chrome immediately. The first chromedp.Run starts or connects to the browser. If the context is derived from an existing chromedp context with a browser, it creates a tab on that browser instead. Cancellation closes the tab or browser according to that relationship. The timeout in this example bounds browser work; use a deadline suited to your application and propagate errors as shown.
#1 Best Overall
Choose print settings for the output you need
page.PrintToPDF exposes print controls through the generated cdproto/page bindings. Those bindings track the browser protocol, so check the documentation for the exact cdproto version in your module before relying on a particular option.
| Setting | What it controls | Practical choice |
|---|---|---|
| Paper width and height; orientation | PDF page dimensions and portrait or landscape layout. | Set dimensions and orientation deliberately when a predictable paper format is required. |
| Margins | Space around printed content. | Choose margins that suit the page design and avoid clipping important content. |
preferCSSPageSize |
Whether CSS-defined page size takes precedence over the PDF paper dimensions. | It defaults to false. With the default, content is scaled to fit the paper; enable CSS page sizing when the page’s print styles should define the page dimensions. |
printBackground |
Whether background graphics are printed. | Backgrounds default to off. Enable them if colors or images in the background are essential to the document. |
displayHeaderFooter and templates |
Whether headers and footers appear and what their HTML contains. | Headers and footers default to off. Templates can use classes for the date, title, URL, page number, and total pages. |
scale and pageRanges |
Content scale and which pages are included. | Set them when you need to adjust printed content or export selected pages. |
| Transfer mode, tagged PDF, document outline | How PDF data is returned and whether accessibility-related tags or an outline are generated. | Consult the bindings for your selected version; the tagged-PDF default is described as the embedder’s choice. |
The minimal example leaves these options at the protocol defaults: portrait orientation, no headers or footers, no printed backgrounds, and no preference for CSS page size. If those defaults do not match the intended document, set the relevant options explicitly on the PrintToPDF command before calling Do(ctx).
Rank #2
Wait for dynamic pages to become ready
Navigation finishing does not prove that a site has completed its client-side rendering or loaded the fonts, images, and asynchronous data needed in the PDF. For a dynamic page, wait for a meaningful application-specific condition—such as a selector that appears only when the content is ready—before printing. Prefer a state-based wait to an arbitrary fixed sleep, and inspect the generated PDF to confirm the page reached the intended state. There is no universal readiness condition that works for every website.
Handle failures and deployment issues
- Chrome or Chromium cannot start: Confirm a compatible browser binary is installed and available to the process, or configure a reachable remote DevTools target. Installing the Go package alone does not install the browser.
- The command times out or the page is incomplete: Check whether navigation, the browser, or the site is slow; adjust the context deadline where appropriate and wait for the page’s required application state before printing.
- The PDF is missing colors or background images: Background printing is off by default. Enable the print-background option and check the browser-protocol binding for the version you use.
- The page is scaled or has unexpected page dimensions: Review paper dimensions, orientation, margins, scale, and
preferCSSPageSize. Decide whether explicit PDF dimensions or the page’s CSS print size should govern. - Headers or footers are absent: They are disabled by default. Enable them and configure templates if the document needs them.
- The PDF is empty, malformed, or not written: Check and return errors from navigation and the PDF command, then check the file-write error. Verify the resulting file at the output path and inspect it in a PDF viewer.
Browser-driven PDF output depends on the browser and the page. The available documentation does not establish universal rendering fidelity, throughput, memory requirements, or compatibility across all sites; pin your Go dependencies and validate output with the browser and pages you deploy.
Or skip the browser setup
ScreenshotNeo is a website screenshot API that can return a PDF as well as PNG, JPEG, or WebP. Its one-request pattern avoids managing a local Chrome process. Use the PDF output option described in the API documentation when you need a PDF; the example below shows the one-call request shape:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o page.pdf
ScreenshotNeo accepts cookie or consent banners 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 are not billed, and each response identifies the page verdict and billing status in headers. 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 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for 1,000 free screenshots a month, with no card.
Frequently Asked Questions
Does chromedp include Chrome or Chromium?
No. chromedp controls a separately installed browser or a compatible remote DevTools Protocol target.
Rank #4
Why does the first chromedp run take longer than creating its context?
Creating the context does not start the browser. The first run starts or connects to one, unless the context inherits an existing browser.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Quick Recap
Best Value
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.

