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

To include content created by JavaScript in an HTML-to-PDF file, render the page in a browser engine first, wait for the application’s content to be ready, and then print the rendered page to PDF. With Puppeteer, the core sequence is page.goto() followed by page.pdf(). Chrome Headless can do the same from the command line. The important detail is readiness: a page-load event or quiet network does not necessarily mean an application has finished rendering.

Why JavaScript requires a browser-based PDF workflow

HTML-to-PDF tools do not all work the same way. A browser engine loads a page, executes its scripts, and can then print the resulting page. That matters for single-page applications, dashboards, charts, and other pages where JavaScript inserts or changes content after the initial HTML arrives. Chrome Headless documents that scripts can alter the DOM before it is captured or printed (Chrome Headless command-line reference).

The reliable pattern is therefore not simply “convert the HTML file.” It is: open the page in a browser, let the relevant JavaScript work finish, and print the rendered result. You still need to choose a suitable readiness condition and check the PDF’s CSS and layout.

Generate a JavaScript-rendered PDF with Puppeteer

Puppeteer provides a JavaScript API for controlling a browser. Its documented PDF workflow navigates to a page and then calls page.pdf(); that method waits for fonts by default (Puppeteer PDF generation guide).

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Epson EcoTank ET-2800 Wireless Color All-in-One Supertank Printer - Black
  • INNOVATIVE CARTRIDGE-FREE PRINTING — No more dealing with lots of tiny ink cartridges; With this wireless document and photo printer each ink bottle set is equivalent to about 90 individual cartridges²
  • LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; When you choose this combination printer, scanner and copier you can print up to 4,500 pages black/7,500 color³
  • COLOR PRINTING — Up to 2 years of ink in the box4 (and with every replacement ink set) for fewer out-of-ink frustrations
  • ZERO CARTRIDGE WASTE — By using an Epson EcoTank printer you can help reduce the amount of cartridge waste ending up in landfills
  • HOME PRINTER DESIGNED FOR RELIABILITY — The Epson EcoTank ET-2800 All-in-One Supertank Color Printer creates vivid, detailed prints and documents thanks to Micro Piezo Heat-Free Technology; Fire off 10 ISO pages per minute1 to easily finish large jobs
const puppeteer = require('puppeteer');

async function savePdf(url, outputPath = 'output.pdf') {
  const browser = await puppeteer.launch();
  try {
    const page = await browser.newPage();
    await page.goto(url, { waitUntil: 'networkidle2' });

    // Replace or supplement this with the page's real readiness condition
    // if the application continues rendering after navigation.
    await page.pdf({ path: outputPath });
  } finally {
    await browser.close();
  }
}

savePdf('https://example.com', 'output.pdf').catch(error => {
  console.error(error);
  process.exitCode = 1;
});

Save this as a JavaScript file in an environment where Puppeteer is installed, then run it with Node.js. The example uses the navigation wait state shown in Puppeteer’s guide, but it is not a guarantee that every application is finished rendering. For a client-rendered page, add a page-specific wait between navigation and page.pdf().

Wait for the application, not just the browser

A browser can finish navigation while an application is still fetching data, rendering a chart, or revealing content. Choose a condition that corresponds to the work that must appear in the PDF, such as a specific element becoming visible or an application-provided readiness signal. Playwright’s documentation distinguishes navigation states and cautions against treating networkidle as a universal readiness strategy (Playwright Page API).

If the target is your own application, an explicit signal set after the content is ready is often easier to reason about than an arbitrary delay. If you cannot change the page, wait for a stable, page-specific element that indicates the needed content has appeared. A fixed sleep can be useful as a fallback for known delays, but it can waste time on fast runs and still be too short on slow ones.

Set the output path and close the browser

page.pdf({ path: 'output.pdf' }) writes the PDF to the specified path. Keeping browser cleanup in a finally block ensures the browser is closed if navigation, waiting, or PDF generation throws an error. For a service that processes many URLs, manage browser and page lifetimes deliberately rather than leaving a browser process open after a failed job.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Epson EcoTank Photo ET-8550 Wireless Wide-Format All-in-One Tank Printer
  • CARTRIDGE-FREE PRINTING — Print lab-quality photos, graphics and creative projects; Get vibrant colors and sharp text with Epson's high-accuracy printhead and Claria ET Premium 6-color inks
  • INK BOTTLES — Save on photos1 and creative projects with affordable in-house printing; All-in-one printer allows you to print 4" x 6" photos for about 4 cents each vs. 40 cents with traditional ink cartridges1
  • LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; Printer, scanner and copier lets you print up to 6,200 color pages³
  • PRINT FOR LONGER — Up to 2 years of ink in the box² (and with every replacement ink set) for fewer out-of-ink frustrations with this wireless printer
  • ZERO CARTRIDGE WASTE — Epson EcoTank printer helps reduce the amount of cartridge waste ending up in landfills; Cartridge-free printer uses high-yield ink bottles; Each replacement ink bottle set is equivalent to about 100 individual ink cartridges⁴

Choose print or screen styling deliberately

Browser PDF generation normally uses print CSS. That can change what appears compared with a normal browser view: a page may hide navigation, use different colors, or rearrange columns for paper. If the printed appearance is desired, define and test the page’s print styles.

Playwright documents that page.pdf() uses print media. To request screen media instead, call page.emulateMedia({ media: 'screen' }) before generating the PDF. This is relevant when the PDF should resemble the on-screen page rather than its print stylesheet. Check the result for clipping, page breaks, and color differences rather than assuming either media mode will suit every page.

await page.emulateMedia({ media: 'screen' });
await page.pdf({ path: 'screen-styled.pdf' });

When layout or color fidelity matters, consult the Playwright Page API for PDF options such as page size and print color adjustment, and validate the output against the intended use. A browser PDF is a print rendering, not automatically a pixel-identical copy of a viewport screenshot.

Print to PDF with Chrome Headless

If a command-line workflow is more convenient than writing browser automation, Chrome Headless supports printing a URL to PDF:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
HP Smart Tank 5000 Wireless All-in-One Ink Tank Printer, Scanner, Copier with 2 Years of Ink Included, Best-for-Home, Cartridge-Free, Refillable and AI-Enabled. (5D1B6A)
  • SET IT UP ONCE AND PRINT WITH CONFIDENCE. No complicated maintenance. Just easy, reliable printing you can count on.
  • INK FOR YEARS. NOT MONTHS. Up to 2 years of ink included. Get thousands of pages of cartridge-free printing. More pages, less hassle
  • KEEPS PRINTING WELL AFTER COMPETITORS HAVE QUIT. No complex maintenance. Sharper text, richer colors.[2] Only with HP Smart Tank
  • PREMIUM SUPPORT - Strong technical expertise to solve issues faster
  • THE LAST PRINTER YOU'LL EVER NEED. Enjoy years of refillable, cartridge-free printing.
chrome --headless --print-to-pdf https://example.com/

The command uses Chrome’s browser engine, so page scripts can change the DOM before printing. Chrome’s command-line reference also documents --timeout to limit capture waiting and --virtual-time-budget for time-dependent code (Chrome Headless command-line reference).

Use timing flags as limits, not readiness proof

A timeout establishes an upper bound on waiting; it does not prove that a particular application has completed rendering. A virtual-time budget can help with pages whose behavior depends on timers, but it is not a substitute for a page-specific signal when the output depends on asynchronous work. If a PDF intermittently omits content, first determine what event or application state means that content is ready, then select a wait strategy that corresponds to it.

Choose the method that matches the job

Method Interface JavaScript rendering Readiness and timing
Puppeteer JavaScript API Uses browser navigation and printing. Navigation wait states are available; add a page-specific condition when application work continues after navigation. PDF generation waits for fonts by default.
Chrome Headless Command line Chrome runs page scripts before printing. Supports a capture timeout and virtual-time budget; neither establishes that app-specific rendering is complete.
Playwright PDF workflow Browser automation API Uses browser page rendering. Choose a navigation state or application readiness signal. PDF output uses print media unless screen media is selected.
WeasyPrint Python HTML-to-PDF API The cited documentation establishes HTML-to-PDF output, but does not establish JavaScript execution. JavaScript readiness behavior is not stated in its cited First Steps documentation.

WeasyPrint documents HTML.write_pdf() for producing a PDF from an HTML object, but that API description alone does not establish that JavaScript is executed (WeasyPrint First Steps). If JavaScript-created content is a requirement, use a documented browser-rendering path rather than assuming a general HTML-to-PDF API runs scripts.

Troubleshoot missing or incorrect PDF content

  • JavaScript content is missing: The page may have navigated before its application finished rendering. Add a wait for the specific content or an explicit application signal before printing.
  • The wait never completes: Check that the selector or readiness signal exists on the target page and can become true in the current state. Avoid a condition that depends on content hidden by consent, authentication, or an error page.
  • The PDF is blank or nearly empty: Confirm that the requested URL loads successfully in the browser and that the page has rendered before capture. A completed navigation alone does not prove useful content is present.
  • The PDF looks different from the browser: Check whether print CSS is active. In Playwright, explicitly select screen media before printing if screen styling is intended.
  • Fonts or text layout are wrong: Puppeteer’s documented page.pdf() waits for fonts by default. If the output still differs, verify that the intended font is available to the page and inspect the final PDF rather than relying only on a successful method call.
  • Content appears only sometimes: Replace a generic network-idle or fixed-delay assumption with the application’s actual completion condition. Network activity and application readiness are related but not equivalent.
  • The command-line capture takes too long: Use Chrome Headless’s timeout as a maximum wait, then investigate what is keeping the page active. The timeout limits waiting; it does not fix an incomplete or continuously loading application.
  • A chosen converter omits scripted content: Verify that the converter’s documentation establishes JavaScript execution. The cited WeasyPrint API page establishes PDF creation from HTML, not JavaScript rendering.
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 you need a screenshot or PDF without operating your own browser automation, ScreenshotNeo is a website screenshot API and MCP server. Its API can return PNG, JPEG, WebP, or PDF. The one-call example below requests an image; see the ScreenshotNeo API documentation for PDF settings and the available options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
NDYIN Portable Printers Wireless for Travel, N80 Bluetooth Thermal Printer
  • Wireless Bluetooth Printer: Portable thermal printer compatible with iPhone, Android phones, iPad and tablet computers via Bluetooth. For smartphones, please download the "Nada Print" App. You can also connect to laptops and computers for printing using a USB-C cable. (Note: Laptops and computers can only be connected via USB and require the installation of a driver first. Bluetooth connection is not supported.)
  • No-ink printing: Only supports US Letter and A4 size thermal paper.(Doesn't support regular paper) The no-ink portable thermal printer uses direct thermal technology, requiring no ink, toner or ribbons, making it environmentally friendly, cost-effective and time-saving. The thermal printer package comes with a roll of US Letter thermal printing paper. Note: When installing the paper, remember to switch the paper size switch on APP
  • Clear Print: NDYIN N80 portable thermal printer adopts high-definition printing technology, with a 203DPI resolution to provide you with clear printing results. This mobile printer is compatible with roll paper, folded paper and tattoo transfer paper, supporting printing from your mobile phone PDF, Word, pictures and web pages anytime and anywhere. It is recommended to use our NDYIN thermal paper to achieve good printing quality
  • Portable wireless printer for travel: The thermal printer is equipped with a built-in 1500mAh rechargeable battery, which can print 160 sheets of 8.5" x 11" thermal paper after being fully charged. It weighs only 1.5 pounds and is compact in size. This ink-free portable printer can be easily carried in a backpack or briefcase! It is perfect for business travel, cars, small offices, construction sites, schools and homes. You can print documents, contracts, invoices and boarding passes anytime and anywhere
  • The N80 thermal printer has a wide range of uses. The package includes the N80 printer, a roll of US Letter paper(7m/roll), a user manual, a guide card, a type-C soft cable and a type C adapter. Note: The charging adapter is not included. Special thermal paper is required for use; ordinary paper cannot be used. This ink-free portable thermal printer is suitable for various scenarios such as home, school, travel, office, and outdoor, meeting the printing needs of different groups of people. This tattoo template printer is also compatible with tattoo transfer paper, making it an ideal choice for tattoo art
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
  • Cookie and consent banners are accepted, and more than 60 known consent platforms, newsletter popups, and chat widgets are removed before capture; each step can be turned off.
  • Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed. Responses identify the page verdict and billing status in 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 without a card; paid plans start at $5 for 3,000 shots. Every feature is available on every plan.

Sign up free for 1,000 screenshots a month, with no card required.

Frequently asked questions

Does page.pdf() run JavaScript?

In the Puppeteer workflow, the browser navigates to the page before PDF generation, so page scripts run as part of browser loading and rendering. The result still depends on waiting for the application’s content to be ready before printing.

Will networkidle2 always wait long enough?

No. It is the navigation wait state used in Puppeteer’s guide example, not a universal guarantee that asynchronous application rendering has finished. Use a condition tied to the page’s actual work when needed.

Can I use a non-browser HTML-to-PDF converter?

Only if its documentation establishes the JavaScript behavior your page requires. The cited WeasyPrint documentation describes PDF generation from HTML but does not establish JavaScript execution.

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.

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.