Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
HTML to PDF

How to Convert HTML Text to PDF with Puppeteer

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a repeatable developer workflow, render the HTML in a browser with Puppeteer and save the result with page.pdf(). Puppeteer uses print CSS by default, waits for fonts before generating the PDF, and lets you set page size, margins, orientation, backgrounds, and page ranges. If you have raw HTML text rather than a web page, first put it in a local HTML file or serve it from your application, then open that page in Puppeteer.

Convert an HTML page to PDF with Puppeteer

The shortest workflow is to launch a browser, open the HTML page, generate a PDF, and close the browser. Install Puppeteer in a Node.js project first, then save this as make-pdf.js:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  try {
    const page = await browser.newPage();
    await page.goto('https://example.com', { waitUntil: 'networkidle0' });
    await page.pdf({ path: 'output.pdf' });
  } finally {
    await browser.close();
  }
})();

Run it with node make-pdf.js. Replace the example URL with the page you want to convert. Puppeteer’s documented basic sequence is launch, navigate, call page.pdf(), and close the browser; the method can save to a file with path and also returns PDF bytes for application-side handling. See the Puppeteer PDF generation guide.

Converting HTML text you already have

If your input is a string such as <h1>Invoice</h1><p>...</p>, place it in a complete HTML document and make that document available as a local file or a page served by your application. Then navigate to that page in the script. Include any CSS and assets the document needs; relative image, font, or stylesheet paths must resolve in the environment running the browser. The official guide’s basic example navigates to a URL; adapt the navigation step to the way your application serves or opens its HTML.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Brother DCP-L2640DW Wireless Compact Monochrome Multi-Function Printer, Copy, Scan, Duplex, Mobile Printing
  • BEST FOR SMALL BUSINESSES – Engineered for extraordinary productivity, the Brother DCP-L2640DW Monochrome (Black & White) 3-in-1 combines laser printer, scanner, copier in one compact footprint and delivers high-quality black & white prints
  • FAST PRINTER WITH EFFICIENT SCANNING – Produces documents quickly with print speeds up to 36 ppm(2) and scan speeds up to 23.6/7.9 ipm(3) (black/color). A 50-page auto document feeder(4) allows for convenient, time saving multi-page scanning and copying
  • FLEXIBLE CONNECTION OPTIONS – Easily navigate the changing demands of your business with secure multi-device connectivity via built-in dual-band wireless (2.4GHz / 5GHz) and Ethernet. Or connect locally to a single computer via USB interface
  • BROTHER MOBILE CONNECT APP – Print, scan, and manage your wireless printer anytime, from almost anywhere from your mobile device. Order Brother Genuine Supplies, track toner usage, and complete more work on-the-go(5)
  • CHOOSE BROTHER GENUINE TONER – When it’s time to replace your toner, be sure to choose Brother Genuine TN830 or TN830XL replacement toner. And with Refresh EZ Print Subscription Service, you’ll never worry about running out of toner again and you’ll enjoy savings of up to 50%(6) on Brother Genuine Toner. Get started with Refresh today with a Free Trial(1)

Use the target page’s URL, not a plain-text string, in page.goto(). A URL is rendered as a page; unmarked text in a browser is not automatically interpreted as HTML markup. For untrusted input, treat HTML and scripts as active content and consider what the browser process can access before rendering it.

Choose print or screen styling

page.pdf() generates a PDF with the print CSS media type by default, as stated in the Puppeteer Page.pdf() API. This means print-specific rules such as @media print can affect the result. If you want the page’s screen styling instead, emulate screen media before calling page.pdf():

await page.emulateMediaType('screen');
await page.pdf({ path: 'output.pdf' });

PDF rendering may alter colors for printing. To request more exact color reproduction, Puppeteer’s API points to the CSS property -webkit-print-color-adjust. For example, apply it to the relevant elements or document in your stylesheet:

Rank #2
Brother HL-L2405W Wireless Compact Monochrome Laser Printer with Mobile Printing, Black & White Output | Includes Refresh Subscription Trial(1), Works with Alexa
  • BEST FOR HOMES & HOME OFFICES – Engineered for consistent, premium print quality, the Brother HL-L2405W Monochrome (Black & White) Laser Printer delivers sharp, crisp prints at an affordable price. Prints one-sided documents at speeds up to 30ppm(2)
  • COMPACT, CONNECTED PRINTER – Flexible connection options make this an ideal printer for home use and at-home offices. Securely connect to multiple devices with built-in dual-band wireless (2.4GHz/5GHz) or locally to a single computer via USB interface
  • BROTHER MOBILE CONNECT APP – Manage your printer remotely and print from your mobile device anytime, from almost anywhere. Order Brother Genuine Supplies, track toner usage, and complete more work on-the-go(3)
  • VERSATILE PAPER HANDLING – Enjoy seamless, reliable everyday printing with the 250-sheet paper tray(4) and a manual feed slot that enables printing on envelopes and specialty pape
  • BROTHER IS AT YOUR SIDE – Backed by Brother with a 1-year limited warranty and free online, call, or live chat support for the life of your printer
* {
  -webkit-print-color-adjust: exact;
}

Check the resulting PDF rather than assuming a screen preview and a printed PDF will look identical.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set page size, margins, and included pages

Use the PDF options that match the document instead of relying on defaults. The current Puppeteer PDFOptions reference documents these controls:

Need Option How it affects output
Standard paper size format Choose a paper format. When format is set, it takes priority over width and height.
Custom page dimensions width, height Set dimensions when a standard format is not appropriate. These dimensions are subordinate to format if it is also supplied.
Landscape output landscape Set to true for a horizontal page orientation.
Page whitespace margin Set top, right, bottom, and left margins to control the printable area.
Honor CSS page size preferCSSPageSize Prioritize an @page size in CSS over API-provided format or dimensions.
Background graphics printBackground Enable when the PDF needs background colors or images. Its documented default is false.
Selected pages pageRanges Limit the output to specified page ranges.
Running page labels displayHeaderFooter and templates Enable and supply optional header or footer templates when the document needs them.

For example, this configuration requests landscape A4, includes background graphics, and adds margins:

Rank #3
Sale
Canon imageCLASS LBP6030w - Monochrome Single-Function Wireless Compact Wireless Laser Printer, 1 Year Limited Warranty, 19 PPM, White - Print Only
  • FAST PRINT SPEEDS: Print up to 19 pages per minute.
  • COMPACT DESIGN: Space-saving, compact design fits anywhere in your home, school or small office.
  • WIRELESS CONNECTIVITY: Print from almost anywhere in your workspace using your compatible mobile device.
  • PAPER CAPACITY: Up to 150 sheets.
  • SUSTAINABILITY: Uses less than 2 watts in Energy Saver mode.
await page.pdf({
  path: 'output.pdf',
  format: 'A4',
  landscape: true,
  printBackground: true,
  margin: { top: '12mm', right: '12mm', bottom: '12mm', left: '12mm' }
});

Option names, defaults, and experimental status can vary by installed Puppeteer version. Check the reference for the version used by your project before relying on a setting.

Make the PDF reflect the finished page

Wait for the content you need

PDF generation waits for fonts by default, according to the Puppeteer guide. That helps when the page relies on web fonts, but it does not establish that every image, asynchronous widget, or application-specific component has finished loading. If content appears late, wait for a meaningful page condition before calling page.pdf(), and verify that the condition matches your page.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Design the page for print

Use print CSS for page breaks, printable colors, and content that should differ between screen and paper. A long web layout may otherwise split headings from their content or place navigation and interactive controls in the PDF. Preview the generated file at the intended paper size, especially when content length varies.

Rank #4
Brother HL-L2460DW Wireless Compact Monochrome Laser Printer with Duplex, Mobile Printing, Black & White Output | Includes Refresh Subscription Trial(1), Works with Alexa
  • BEST FOR HOME OFFICES & SMALL TEAMS – Engineered for consistent, premium print quality, the Brother HL-L2460DW Monochrome (Black & White) Laser Printer produces documents that are clear, crisp, and easy to review and share, all at an affordable price
  • COMPACT, CONNECTED, EXCEPTIONALLY EFFICIENT– Connect with built-in dual-band wireless (2.4GHz/5GHz), Ethernet, or to a single computer via USB interface. Prints at speeds up to 36ppm(2), plus automatic duplex printing saves time and reduces paper waste
  • BROTHER MOBILE CONNECT APP – Manage your wireless printer remotely and print from your mobile device anytime, from almost anywhere. Order Brother Genuine Supplies, track toner usage, and complete more work on-the-go(3)
  • VERSATILE PAPER HANDLING – Tackle high-volume black & white printing with the 250-sheet capacity paper tray.(4) The manual feed slot enables printing on envelopes and specialty paper
  • BROTHER IS AT YOUR SIDE – Backed by Brother with a 1-year limited warranty and free online, call, or live chat support for the life of your printer

Handle the generated bytes

With path, Puppeteer writes the PDF to a file. If your application needs to send or store the document itself, use the returned PDF bytes instead of writing to disk. The API describes a byte result; the exact destination and storage process depend on your application.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your HTML is already available as a public page, ScreenshotNeo can capture a URL as an image or PDF. It also supports HTML/CSS-to-image workflows; it is not a substitute for rendering an arbitrary private HTML string unless you first make that content available to the service. Its PDF settings include paper size, margins, landscape orientation, and page ranges. See the ScreenshotNeo documentation for the current request parameters and PDF format selection.

Example one-call URL capture (using the supplied image-output example):

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
HP LaserJet M110w Wireless Black & White Printer, Print, Fast speeds, Easy Setup, Mobile Printing, Best-for-Small Teams
  • FROM AMERICA'S MOST TRUSTED PRINTER BRAND – Perfect for small teams printing professional-quality black & white documents and reports. Perfect for 1-3 people
  • WORLD'S SMALLEST LASER IN ITS CLASS – Precision laser printing that fits anywhere
  • FAST PRINT SPEEDS – Up to 21 black-and-white pages per minute single-sided
  • WIRELESS WITH SELF-RESET – Helps you stay connected
  • PRINT FROM ANY DEVICE – Wireless printing from any mobile device, PC or tablet. Works with Microsoft, Mac, AirPrint, Android, Chromebook and more
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
  • It accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing; the response includes X-Page-Verdict and X-Billed headers.
  • An 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 required; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Troubleshooting HTML-to-PDF output

  • Background colors or images are missing: Set printBackground: true; it is false by default in the documented options.
  • The PDF looks different from the browser window: Check whether print media rules are active. Puppeteer uses print media by default; emulate screen media before PDF generation if that is the intended appearance.
  • Colors look washed out or changed: Print rendering can modify colors. Apply -webkit-print-color-adjust where exact colors are needed and inspect the PDF output.
  • Fonts are absent or substituted: The guide says PDF generation waits for fonts by default. Confirm that font URLs are reachable from the browser process and that your document references them correctly.
  • The page is missing late-loading content: The PDF call’s font wait does not guarantee every dynamic element has rendered. Wait for an application-specific selector or completion signal before capturing.
  • The page size ignores your CSS: Check whether format is set, since it takes priority over width and height. To prioritize a CSS @page size, use preferCSSPageSize.
  • Unexpected margins or orientation: Specify the margins and landscape setting explicitly, then confirm you are using the options supported by the installed Puppeteer version.
  • Only some pages should appear: Use pageRanges and verify the page numbering against the rendered document.

Reliability and cost considerations

Puppeteer automates a browser, so the conversion runs wherever your Node.js application and browser can run. The cited Puppeteer documentation establishes the rendering workflow and options, but does not provide a universal runtime, hosting cost, or performance figure; these depend on your document and deployment. For repeat jobs, close the browser in a finally block as in the example so errors during navigation or PDF generation do not skip cleanup.

For a third-party capture service, consider whether the page can be accessed by that service and review the service’s documentation for request options and data handling. ScreenshotNeo’s published plan prices are Free: 1,000 shots/month; Starter: $5 for 3,000; Growth: $15 for 15,000; Pro: $39 for 60,000; Scale: $99 for 250,000; and Business: $249 for 1,000,000. Yearly billing gives two months free, and every feature is available on every plan. Those are shot allowances and plan prices, not a general per-page conversion benchmark.

Frequently Asked Questions

Does Puppeteer create a PDF from HTML or only from a URL?

Its PDF method renders a browser page. A raw HTML string must first be made into a page, such as a local HTML file or a page served by your application.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can I get PDF bytes instead of writing a file?

Yes. The Page.pdf() API returns PDF bytes; omit file output when you intend to handle the result in application code.

Does Puppeteer use print or screen CSS for PDFs?

Print CSS is the default. Emulate screen media before generating the PDF if you want screen styling.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.