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

Use Puppeteer when your replacement must navigate, authenticate, wait for application state, or set PDF options per page. Use Chrome headless when a shell command is enough. Puppeteer’s page.pdf() is the closest programmable replacement for a PhantomJS readPdf() wrapper, but Chromium uses different rendering and print defaults, so you must map paper settings and validate timing, fonts, headers, and CSS.

Choose the replacement: Puppeteer or Chrome headless

Puppeteer is a JavaScript library that automates Chrome and Firefox and exposes navigation, cookies, DOM interaction, waiting, and PDF generation. It is the better fit for authenticated pages, dashboards, invoices, reports, and any workflow that must click or modify the DOM before printing.

Chrome’s command line is simpler for a public URL and a fixed output file:

chrome --headless --print-to-pdf=output.pdf https://example.com
chrome --headless --print-to-pdf=output.pdf --no-pdf-header-footer https://example.com

Chrome also supports --timeout=5000 for a bounded wait and --virtual-time-budget=42000 when timers or animations need simulated time to advance. The exact executable name can differ by operating system; use the installed Chrome or Chromium binary in your environment.

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.

Install Puppeteer and generate the basic PDF

The package puppeteer downloads a compatible Chrome for Testing during installation when install scripts are permitted. Choose puppeteer-core when your deployment manages Chrome itself; it does not download a browser, so provide an executable path or channel.

npm install puppeteer

This complete example preserves browser cleanup even when navigation or printing fails:

import puppeteer from 'puppeteer';

const url = process.argv[2] || 'https://example.com';
let browser;

try {
  browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto(url, { waitUntil: 'networkidle2' });
  await page.pdf({
    path: 'output.pdf',
    format: 'A4',
    printBackground: true,
    preferCSSPageSize: true,
    margin: { top: '12mm', right: '12mm', bottom: '12mm', left: '12mm' }
  });
} finally {
  if (browser) await browser.close();
}

Run it with node make-pdf.js https://example.com. page.pdf() prints using the print CSS media type and waits for fonts by default. Keep that behavior unless you have a deliberate reason to change it.

Control print versus screen styles

PhantomJS jobs sometimes captured the screen appearance rather than print styles. Puppeteer’s PDF operation uses print media by default. To reproduce screen styling, set the media type before printing:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.emulateMediaType('screen');
await page.pdf({ path: 'output.pdf', printBackground: true });

Conversely, leave the default print media when your document has intentional @media print rules. Inspect the page’s @page declarations and decide whether CSS or the API should own the paper size.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 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.

Map PhantomJS paperSize to Puppeteer

PhantomJS paperSize supports standard formats such as A3, A4, A5, Legal, Letter, and Tabloid; custom dimensions in millimetres, centimetres, inches, or pixels; margins; portrait or landscape orientation; and repeating header and footer content. Puppeteer exposes the corresponding controls as follows:

PhantomJS concept Puppeteer option Migration note
Standard paper format format: 'A4', 'Letter', etc. Use one named format instead of width and height.
Custom width and height width, height Use units such as mm, cm, in, or px.
Margins margin: {top, right, bottom, left} Specify units explicitly, for example '12mm'.
Orientation landscape: true Omit or set false for portrait.
CSS page size preferCSSPageSize: true Lets the document’s @page rule control dimensions.
Background graphics printBackground: true Enable when the old PDF included colored or image backgrounds.
Repeating header/footer displayHeaderFooter: true, headerTemplate, footerTemplate Chrome templates are separate from CLI header/footer suppression.

For custom paper, use a single source of truth. For example:

await page.pdf({
  path: 'custom.pdf',
  width: '210mm',
  height: '297mm',
  margin: { top: '15mm', right: '10mm', bottom: '15mm', left: '10mm' },
  landscape: false,
  printBackground: true,
  preferCSSPageSize: true
});

If both an API format and CSS @page size are present, preferCSSPageSize: true gives CSS priority. Confirm the result rather than assuming Chromium and PhantomJS paginate identically.

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

Replace a callback-style readPdf wrapper safely

PhantomJS’s callback-oriented readPdf() wrapper is application code, not a standard Puppeteer API. Keep your existing input contract if callers depend on it, but convert completion to a promise and close the browser in finally.

import puppeteer from 'puppeteer';

export async function readPdfReplacement(options, callback) {
  let browser;
  try {
    browser = await puppeteer.launch();
    const page = await browser.newPage();
    if (options.cookies) await page.setCookie(...options.cookies);
    await page.goto(options.url, { waitUntil: 'networkidle2' });
    if (options.media === 'screen') await page.emulateMediaType('screen');
    await page.pdf({
      path: options.path,
      format: options.format || 'A4',
      width: options.width,
      height: options.height,
      landscape: Boolean(options.landscape),
      margin: options.margin,
      printBackground: options.printBackground !== false,
      preferCSSPageSize: options.preferCSSPageSize !== false,
      displayHeaderFooter: Boolean(options.displayHeaderFooter),
      headerTemplate: options.headerTemplate,
      footerTemplate: options.footerTemplate
    });
    callback(null, options.path);
  } catch (error) {
    callback(error);
  } finally {
    if (browser) await browser.close();
  }
}

Recheck selectors, cookies, authentication, custom fonts, external images, and JavaScript timing. Chromium and PhantomJS are different browser engines, so a visually similar input can paginate differently.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • 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.

Wait for the page that users actually see

networkidle2 waits for a period with no more than two active network connections, but it is not proof that an application has finished rendering. Add an application-specific readiness signal when needed:

await page.goto(url, { waitUntil: 'domcontentloaded' });
await page.waitForSelector('[data-report-ready]', { timeout: 30000 });
await page.evaluate(() => document.fonts.ready);
await page.waitForFunction(() => [...document.images].every(img => img.complete));
await page.pdf({ path: 'report.pdf', format: 'A4', printBackground: true });

Use a bounded timeout for every wait. For data loaded by a single request, wait for the relevant selector or response instead of adding an arbitrary long sleep. If an animation changes layout, disable it with CSS or wait until its final state before printing.

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.

Headers, footers, page ranges, and long documents

For Puppeteer headers and footers, enable displayHeaderFooter and supply HTML templates. Chrome exposes page-number classes such as pageNumber and totalPages inside those templates. The command-line switch --no-pdf-header-footer is a different control and does not configure Puppeteer templates.

For a long report, test page breaks, repeated table headings, images near boundaries, and custom fonts. Use CSS such as break-inside: avoid selectively; applying it to very large containers can create unexpectedly blank pages. Puppeteer also supports page ranges through its PDF options, which is useful for testing a subset before producing the entire document.

Validate the migration before switching production traffic

  1. Compare geometry: check paper size, orientation, margins, and whether CSS @page rules are taking effect.
  2. Compare appearance: verify background colors, images, font weights, line wrapping, and print-versus-screen rules.
  3. Compare data timing: confirm web fonts, images, API data, and client-side charts are present before printing.
  4. Test chrome: exercise headers, footers, page numbers, custom dimensions, and page ranges separately.
  5. Test failure cleanup: terminate a navigation, font, or PDF error and confirm the browser process exits.
  6. Pin versions: record Puppeteer and Chrome versions, then periodically review them because rendering and API defaults can change.

Troubleshooting common migration failures

The PDF is blank or missing application data

Cause: printing started after navigation but before client-side rendering completed. Fix: wait for a page-specific ready selector, the required response, fonts, and images. Capture the same URL with JavaScript enabled and inspect console errors.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • 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

Colors or backgrounds disappeared

Cause: print CSS suppresses them or backgrounds were not requested. Fix: set printBackground: true, inspect @media print, and use emulateMediaType('screen') only when screen styling is the intended output.

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

The paper size is wrong

Cause: conflicting API dimensions and @page CSS, or a unit conversion mistake. Fix: choose named format or explicit width/height, use units, and set preferCSSPageSize deliberately.

Headers or footers do not appear

Cause: displayHeaderFooter is false, or a CLI suppression flag was used. Fix: enable the Puppeteer option and provide templates; do not rely on the CLI flag for template behavior.

Fonts or images are missing

Cause: external resources failed, authentication blocked them, or printing happened too early. Fix: set cookies or headers before navigation, wait for document.fonts.ready and image completion, and verify resource URLs from the browser context.

Puppeteer cannot launch in CI or a container

Cause: the selected binary is absent, install scripts were disabled, or the runtime lacks required system dependencies. Fix: install Chrome explicitly, use puppeteer-core with its executable path when your platform manages the browser, and document the launch configuration. Do not assume a locally installed desktop Chrome exists in a restricted runner.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 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.

Processes accumulate after errors

Cause: the code closes the browser only on success. Fix: put shutdown in finally and ensure each job owns and closes its browser or page.

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

Or skip the browser setup

ScreenshotNeo provides a URL-to-PDF and screenshot API when you do not want to install or operate a browser. It accepts consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and each response reports the result in X-Page-Verdict and X-Billed headers. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients.

For the PDF-oriented call, request PDF output and pass the same target URL:

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 PDF parameters such as paper size, margins, landscape mode, page ranges, and the other capture options.

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

Python

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
r.raise_for_status()
open("shot.pdf", "wb").write(r.content)

Node.js

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
require('fs').writeFileSync('shot.pdf', Buffer.from(await res.arrayBuffer()));

ScreenshotNeo includes full-page capture with lazy images loaded, CSS-selector element capture, dark mode, 12 device presets plus custom viewports, retina scale, custom CSS and JavaScript, clicks, selector or network-idle waits, ad and tracker blocking, custom headers and cookies, user agents and Authorization, timezone and geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed links, asynchronous jobs with signed webhooks, bulk capture for up to 100 URLs per call, a usage API, an OpenAPI specification, and compatibility with parameter names used by other screenshot APIs. Every feature is on every plan: 1,000 screenshots per month are free with no card; paid plans start at $5 for 3,000. Create a free ScreenshotNeo account.

Frequently Asked Questions

Can I keep PhantomJS output byte-for-byte identical?

No. PhantomJS and Chromium use different rendering engines, fonts, layout behavior, and pagination. Treat the old PDF as a visual reference and approve defined differences during migration.

When should I use puppeteer-core instead of puppeteer?

Use puppeteer-core when your platform supplies and manages Chrome. It does not download a browser, so configure the executable path or channel and document that dependency.

Does Chrome headless support the same header and footer templates as Puppeteer?

The CLI and Puppeteer expose different controls. Validate CLI output separately; Puppeteer templates require displayHeaderFooter and template options.

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

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.