ScreenshotNeo

BlogComparisons

DocRaptor vs. Puppeteer for Generating PDFs from Web Pages

Compare DocRaptor’s Prince-backed conversion API with Puppeteer’s browser-based PDF generation, including runnable examples, print controls, and tradeoffs.

By the ScreenshotNeo team4 October 20268 min read

Short answer: Choose Puppeteer when you want PDF generation inside a browser automation workflow and are prepared to run that workflow. Choose DocRaptor when you prefer to send a document request to a hosted conversion API that uses Prince. Neither is a universal winner: rendering differences, operational ownership, current price, and the behavior of your actual templates need to be checked against your requirements.

This guide compares the integration models and shows runnable starting points. It also explains how to decide based on print styling, JavaScript, assets, page layout, and operations.

How the two approaches differ

Question DocRaptor Puppeteer
Where conversion happens Through DocRaptor’s hosted API In a browser automation workflow using Page.pdf()
Document engine DocRaptor identifies Prince as its PDF engine PDF output is generated from the browser page
Print media Styling and PDF behavior are configured through CSS and Prince-specific options Page.pdf() uses print CSS media by default
JavaScript Disabled by default; DocRaptor documents an API parameter to enable it Page content is rendered in the browser workflow; coordinate script completion and page readiness
Operational responsibility Integrate with an external conversion API Operate the Puppeteer/browser workflow in your application or infrastructure
Cost comparison Check current commercial terms and limits directly Account for the infrastructure and operational work in your own environment

The documentation establishes these integration models, but it does not establish comparative speed, reliability, fidelity, maintenance effort, or total cost. Treat those as things to measure for your own workload.

Generate a PDF with Puppeteer

Puppeteer’s Page.pdf() documentation says it “Generates a PDF of the page with the print CSS media type.” This makes print CSS the natural starting point. If you need screen media instead, set the media type before generating the PDF.

Install and run

npm install puppeteer

Save this as make-pdf.mjs. It opens a URL, waits for fonts, and writes a PDF:

import puppeteer from 'puppeteer';

const url = process.argv[2] ?? 'https://example.com';
const browser = await puppeteer.launch({ headless: true });

try {
  const page = await browser.newPage();
  await page.goto(url, { waitUntil: 'networkidle0', timeout: 60_000 });
  await page.pdf({
    path: 'page.pdf',
    format: 'A4',
    printBackground: true,
    preferCSSPageSize: true,
    waitForFonts: true,
    margin: { top: '16mm', right: '14mm', bottom: '16mm', left: '14mm' },
  });
} finally {
  await browser.close();
}
node make-pdf.mjs https://example.com

The example uses a public page. For private pages, establish authentication in the browser context before navigation, and do not place credentials in a URL that may appear in logs.

Control print layout with CSS

Use print styles for layout decisions that belong to the document. Check page breaks, overflow, and repeated headers with real output; screen layouts often need print-specific adjustments.

@media print {
  body { color: #111; background: #fff; }
  nav, .screen-only { display: none !important; }
  .keep-together { break-inside: avoid; }
  h1, h2 { break-after: avoid; }
}

@page {
  size: A4 portrait;
  margin: 16mm 14mm;
}

html {
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

By default, printing may adjust colors. Puppeteer’s PDF documentation points to -webkit-print-color-adjust for forcing exact colors. Background printing is also controlled by the PDF options.

Useful Puppeteer PDF options

The PDF options reference documents controls including:

  • format or explicit dimensions for paper size, landscape for orientation, and margin for page margins.
  • pageRanges to restrict output to selected pages.
  • printBackground to include backgrounds.
  • scale to scale the rendered page.
  • preferCSSPageSize to let CSS @page sizing take priority.
  • timeout and waitForFonts to control waiting behavior.

Read the current Puppeteer options reference for accepted values and defaults. These options are not guaranteed to map one-for-one to DocRaptor controls.

Generate a PDF with DocRaptor

DocRaptor accepts document requests through a hosted API and supports direct binary output as well as hosted and asynchronous response modes. The following Python example uses the documented API shape; insert credentials using the current authentication method in DocRaptor’s API documentation and use the exact request fields supported by your account and API version.

import requests

api_url = 'https://docraptor.com/docs'
api_key = 'YOUR_DOCRAPTOR_API_KEY'

payload = {
    'document_content': '<!doctype html><html><body><h1>Report</h1><p>Hello from HTML</p></body></html>',
    'name': 'report.pdf',
    'document_type': 'pdf',
    'test': True,
}

response = requests.post(
    api_url,
    auth=(api_key, ''),
    json=payload,
    timeout=90,
)
response.raise_for_status()
with open('report.pdf', 'wb') as output:
    output.write(response.content)

DocRaptor test documents are free and watermarked; that is a testing mode, not evidence of a free production plan. Confirm the current endpoint, authentication format, request fields, and response mode against the official API reference before production use.

HTML, JavaScript, CSS, and resources

  • JavaScript: DocRaptor’s tutorial says JavaScript is disabled by default and can be enabled through an API parameter. Enable it only when the document needs client-side rendering, and verify that the page has finished producing its content before conversion.
  • CSS and pagination: DocRaptor documentation describes CSS-controlled page styling, including page size, headers, and footers, with some PDF-only options specific to Prince. Validate page breaks and headers in generated files.
  • External resources: CSS, fonts, and images must be reachable to the conversion service. The API documentation describes how resource download errors such as failed HTTP responses, DNS errors, timeouts, SSL problems, or rejected connections can affect generation when resource errors are configured to fail the request.
  • Engine versions: DocRaptor maps pipeline versions to Prince and JavaScript engine versions. Avoid relying on a timeless engine-version claim; check the current mapping when a version matters.

Choose based on your requirements

  1. Start with the rendering behavior. Puppeteer creates a PDF from browser automation; DocRaptor documents Prince-backed conversion. Render representative pages containing your real CSS, fonts, images, and scripts, then inspect the PDFs.
  2. List required page controls. For Puppeteer, consider paper size, margins, page ranges, backgrounds, scale, and CSS page-size preference. For DocRaptor, check its CSS and Prince-specific controls for the exact headers, footers, and pagination you require.
  3. Check dynamic content and access. Decide how scripts finish rendering, how fonts and images load, and how protected content is made available. Test those paths instead of assuming a public-page example covers them.
  4. Choose who owns the conversion workflow. Puppeteer makes conversion part of your browser automation and operational stack. DocRaptor makes it an external API integration. The reviewed sources do not quantify hosting, concurrency, maintenance, or scaling work.
  5. Verify current cost and limits. Compare current commercial terms and expected volume directly. The evidence here does not support a numerical price comparison.

Or skip the browser setup

If you need a screenshot of a web page rather than a paginated PDF, ScreenshotNeo provides a website screenshot API and MCP server. It is an alternative to try first for screenshot capture; it is not a replacement for a multi-page document-generation workflow when you need PDF pagination.

One GET request returns a PNG, JPEG, WebP, or PDF. For a PDF response, use the documented PDF option and consult the ScreenshotNeo API documentation for current parameter details:

curl -G "https://api.screenshotneo.com/v1/shot" \
  -d access_key=YOUR_API_KEY \
  --data-urlencode url=https://stripe.com \
  -d format=pdf \
  -o page.pdf
import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com", "format": "pdf"},
    timeout=90,
)
r.raise_for_status()
open("page.pdf", "wb").write(r.content)
const q = new URLSearchParams({
  access_key: 'YOUR_API_KEY',
  url: 'https://stripe.com',
  format: 'pdf',
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
await Bun.write('page.pdf', res);
  • Cookie and consent banners are accepted like a visitor, and 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 cost nothing. Response headers say which outcome occurred and whether it was billed.
  • An MCP server gives AI agents tools for screenshots, page information, and PDF capture.
  • 1,000 screenshots per month are free with no card; paid plans start at $5 for 3,000. Every feature is on every plan.

Create a free ScreenshotNeo account for 1,000 screenshots a month with no card.

Troubleshooting

Symptom Likely cause What to check
PDF is missing client-rendered content The page was captured before scripts completed, or JavaScript is disabled for the DocRaptor request For DocRaptor, check the JavaScript setting and readiness behavior. For Puppeteer, wait for the application’s real ready condition before calling pdf().
Images or fonts are absent Resource URL is inaccessible, blocked, or slow from the renderer’s environment Check URLs, DNS, TLS, access controls, and response times. DocRaptor documents resource download errors and their possible effect on generation.
Colors differ from the screen Print media applies different CSS or print color adjustment changes output Inspect @media print; in Puppeteer, enable backgrounds if needed and use print color adjustment CSS for exact colors.
Content clips or creates unexpected pages Screen-oriented dimensions, margins, or page-break rules do not suit print Set paper size and margins deliberately, inspect @page, and test long tables and unbreakable sections.
Conversion fails after a resource error A remote asset returned an error or could not be fetched Make resources reliably reachable and review the DocRaptor resource-error configuration to decide whether such errors should fail the request.
Generation times out Navigation, script work, or resource loading exceeds the configured wait Identify the slow dependency, set an appropriate timeout, and avoid treating indefinite network activity as proof the page is ready.

Performance, reliability, and cost

No comparative benchmark in the reviewed sources establishes which option is faster or more reliable. Test with representative document sizes and asset patterns, and record conversion duration, failure rate, output validity, and resource use in your own environment.

For reliability, make source HTML and assets deterministic where possible, define an explicit readiness condition, and retain enough request context to reproduce failures. For API-based conversion, decide how your application handles timeouts and unsuccessful responses. For browser automation, plan for browser process lifecycle and cleanup. These are operational practices, not claims of measured product performance.

DocRaptor’s free, watermarked test documents are useful for evaluating output, but do not establish production pricing or allowances. Check both products’ current prices, limits, and terms before estimating cost. For Puppeteer, include the infrastructure and maintenance required by your deployment; no source here provides a comparable total-cost figure.

Frequently asked questions

Does Puppeteer always use print CSS for PDFs?

Page.pdf() uses the print CSS media type by default. Puppeteer can use screen media if you change the media type before creating the PDF.

Is DocRaptor a browser automation library?

It is a hosted document-generation API that uses Prince as its PDF engine. Puppeteer is the browser automation option in this comparison.

Is DocRaptor’s free test mode suitable for production?

The documentation describes test documents as free and watermarked. Verify current production pricing and terms separately.

Which one produces more faithful PDFs?

The reviewed sources do not establish a universal fidelity winner. Compare generated PDFs from the exact templates, assets, and CSS your application will use.