printpipe.io
← All guides

How to save a web page as a PDF, exactly as shown

Turn any public URL into a PDF or screenshot, with lazy-loaded images, cookie banners out of the way and pages that are drawn by JavaScript.

web-pagesscreenshots

Send a URL instead of HTML and our browser visits the page for you: it loads it, scrolls through it so lazy content appears, clicks away the cookie banner, and prints it. Good for archiving pages, sending a page as an attachment, or keeping a record of what a page said on a given day.

Try it free above opens the online converter with the address filled in, no account needed.

The first page of the PDF this guide makes: how to save a web page as a pdf, exactly as shown
The first page of the PDF, made by printpipe.io from the request below.

The request

curl https://api.printpipe.io/v1/generate \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "html": "https://example.com",
  "format": "A4",
  "media": "screen",
  "printBackground": true,
  "marginTop": 24,
  "marginBottom": 24,
  "marginLeft": 24,
  "marginRight": 24
}' \
  --output document.pdf
import { writeFile } from 'node:fs/promises';

const res = await fetch('https://api.printpipe.io/v1/generate', {
  method: 'POST',
  headers: { 'X-API-Key': process.env.API_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "html": "https://example.com",
    "format": "A4",
    "media": "screen",
    "printBackground": true,
    "marginTop": 24,
    "marginBottom": 24,
    "marginLeft": 24,
    "marginRight": 24
  }),
});
if (!res.ok) throw new Error((await res.json()).message);
await writeFile('document.pdf', Buffer.from(await res.arrayBuffer()));
import os, requests

res = requests.post(
    "https://api.printpipe.io/v1/generate",
    headers={"X-API-Key": os.environ["API_KEY"]},
    json={
      "html": "https://example.com",
      "format": "A4",
      "media": "screen",
      "printBackground": True,
      "marginTop": 24,
      "marginBottom": 24,
      "marginLeft": 24,
      "marginRight": 24
    },
    timeout=60,
)
res.raise_for_status()
with open("document.pdf", "wb") as f:
    f.write(res.content)

Screen or print styles

Most websites look different when printed: navigation hidden, colours dropped, links spelled out. You choose which look you get:

  • "media": "screen" (the default) keeps the page as you see it in a browser.
  • "media": "print" applies the site’s own @media print rules. Good for articles and documentation that were designed for printing.

"printBackground": true (the default) keeps background colours and images. Set it to false to save ink on a page that will really be printed.

One long page, or sheets of paper

A web page has no pages, so by default it’s cut into sheets of the chosen format. Breaks can land in the middle of a picture. Two alternatives:

  • "singlePage": true puts the whole page on one PDF page as tall as the content, like a very long screenshot that stays text. It needs a paid plan.
  • A screenshot instead of a PDF: "output": "png" (or "jpeg"), with "fullPage": true for the whole page and "scale": 2 for a sharp retina image.
{ "html": "https://example.com", "output": "png", "fullPage": true, "width": 1440, "scale": 2 }

Pages that load as you scroll

Many pages load their images only when you scroll to them, or fade sections in. URLs are scrolled through before printing (lazyLoad, on by default for URLs), so those appear. If a page still comes out with gaps:

  • Content drawn by JavaScript after loading needs a moment: add "waitFor": 2 (seconds).
  • Single-page apps that show a spinner first need the same.
  • If you know a page doesn’t need scrolling, "lazyLoad": false makes it a little faster.

Cookie banners cover the content, so we accept them before printing (acceptCookies, on by default for URLs). It works with the common consent tools and with banners in most European languages. The browser is thrown away after each conversion, so nothing is remembered. If you need the banner in the PDF, send "acceptCookies": false.

What can’t be converted

  • Pages behind a login. Our browser isn’t signed in to your account, and shouldn’t be. Fetch the page yourself (your server is signed in) and send us its HTML instead of the URL.
  • Private addresses. Pages can only reach the public internet: localhost, private networks and cloud-internal addresses are blocked. For an intranet page, send its HTML.
  • Bot checks. When a site shows an “are you human?” check instead of its page, the conversion is refused and costs nothing. Send the HTML instead, or ask the site to allow the service.

Sending HTML instead of a URL

When you send HTML, relative links in it (<img src="logo.png">) have nothing to be relative to. Add a <base href="https://your-site.example/"> to its <head>, or use absolute URLs. You can also upload an HTML file as it is, see Sending an HTML file.

More guides