ScreenshotNeo

BlogComparisons

Screenshot API vs Browser Automation for Generating PDF Invoices

Choose between a screenshot and a real PDF invoice, with runnable Playwright examples, decision criteria, and a managed capture option.

By the ScreenshotNeo team4 October 20268 min read

Short answer: generate a PDF when the invoice must be printed, shared as a document, or processed as a PDF. Use a screenshot API when you need a visual image record, such as a preview or audit snapshot. A screenshot is an image; it is not a paginated invoice PDF.

Use browser automation such as Playwright when you must sign in, interact with the invoice page, or control the browser before rendering. Consider a hosted rendering API when request-based HTML or URL-to-PDF generation fits your system better, after checking its supported behavior, privacy terms, reliability, and pricing.

1. Decide what artifact the workflow needs

Need Choose Why
Printable, shareable, or machine-processable invoice document PDF generation A PDF can paginate and use print-specific layout rules.
Image preview, visual audit trail, or image-based record Screenshot A screenshot captures rendered pixels as PNG, JPEG, or WebP.
Invoice requires authentication or page interaction Browser automation You can navigate, interact with the page, and then render it.
HTML or public URL should become a PDF through a request Hosted rendering API This may fit a service-oriented workflow; verify its actual controls and data handling.

Do not select a screenshot API just because an invoice is visible in a browser. If the consumer expects a PDF, create a PDF and test its page breaks, selectable text, links, and print layout as applicable.

2. Generate a PDF invoice with Playwright

Playwright gives the application direct control of navigation and page rendering. The following runnable Node.js example opens a URL and writes a PDF. Install Playwright and its Chromium browser first:

npm install playwright
npx playwright install chromium

Save this as invoice-pdf.mjs and replace the example URL with a page your process is authorized to access:

import { chromium } from 'playwright';

const browser = await chromium.launch();
const context = await browser.newContext();
try {
  const page = await context.newPage();
  await page.goto('https://example.com/invoices/123', {
    waitUntil: 'networkidle',
    timeout: 45_000,
  });

  await page.pdf({
    path: 'invoice.pdf',
    format: 'A4',
    printBackground: true,
    margin: { top: '12mm', right: '12mm', bottom: '12mm', left: '12mm' },
  });
} finally {
  await context.close();
  await browser.close();
}

Run it with node invoice-pdf.mjs. PDF export through Playwright is Chromium-only. Its page.pdf() operation uses print CSS by default. If the invoice has the desired styling only in screen media, select that media explicitly:

await page.emulateMedia({ media: 'screen' });
await page.pdf({ path: 'invoice.pdf', format: 'A4', printBackground: true });

For production, wait on a meaningful invoice-ready signal rather than assuming the initial navigation means all invoice data has rendered. For example, after navigating you can wait for a stable invoice element:

await page.goto(invoiceUrl, { waitUntil: 'domcontentloaded', timeout: 45_000 });
await page.locator('[data-invoice-ready="true"]').waitFor({ state: 'visible', timeout: 20_000 });
await page.pdf({ path: 'invoice.pdf', format: 'A4', printBackground: true });

The selector above is an example contract for your own page. Replace it with a selector that your invoice application controls. If a login is required, perform the authorized login flow in the same context before navigating to the invoice, and avoid embedding credentials in source code.

PDF options that commonly matter

  • format: choose a standard paper format such as A4 or Letter. The PDF API also supports explicit width and height when a fixed custom page size is required.
  • margin: set all four margins deliberately; defaults may not match invoice branding or printer constraints.
  • printBackground: enable it when the invoice depends on background colors or graphics.
  • media: PDF rendering defaults to print CSS. Call page.emulateMedia({ media: 'screen' }) first only when the screen-styled rendering is the required result.
  • page interaction: navigate, authenticate, click, or fill fields before calling page.pdf() when the page requires those actions.

Design the invoice’s print stylesheet with explicit page-break behavior. Check long line items, totals, footers, and repeated headers across multiple pages in the resulting PDF.

3. When browser automation is the right fit

Choose browser automation when the invoice exists behind a login, depends on client-side rendering, or requires a sequence of browser actions. It is also appropriate when you need to set rendering details in code and can operate the browser runtime within your application.

  1. Start a browser and create a fresh context for the job.
  2. Navigate to the application and complete the permitted authentication or interaction steps.
  3. Wait for invoice data and fonts or images that affect layout to be ready.
  4. Apply print or screen media as required, then create the PDF.
  5. Store or deliver the resulting file according to your own data-handling policy, and close the context and browser.

Playwright documents browser contexts as isolated, non-persistent sessions that do not write browsing data to disk. Your application still controls how invoice content, credentials, logs, and generated PDF files are handled.

4. When a hosted rendering API fits

A hosted API can suit a workflow that sends HTML or a URL to an endpoint and receives a rendered document. The Chromium PDF Service reference, for example, documents separate HTML, URL, and file-to-PDF endpoints, as well as screenshot endpoints and a selector wait option. These are capabilities of that referenced service, not a guarantee about every provider.

Before using a hosted service for invoices, confirm whether it can reach authenticated pages, how credentials and submitted HTML are protected, where requests are processed, how long inputs and outputs are retained, how deletion works, what waits or browser controls are available, and how failures and charges are reported. The cited API reference does not establish those terms or comparable performance, cost, or reliability.

Choose based on the operating model: direct browser interaction and control favor automation; request-based rendering of HTML or URLs may favor an API. This is an architectural tradeoff, not evidence that one is inherently faster, cheaper, safer, or more reliable.

5. When to use a screenshot API

A screenshot API is a fit when the required output is an image of the invoice page, such as a thumbnail, visual preview, or image-based audit snapshot. It does not produce the same artifact as a paginated PDF invoice. If the downstream system requires PDF, use PDF generation instead.

ScreenshotNeo is a website screenshot API and MCP server. For a screenshot rather than a PDF, it returns PNG, JPEG, or WebP from one GET request and supports browser capture controls. Its clean-shot flow accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, with response headers indicating the page verdict and billing status. It also provides MCP tools for AI agents. Those screenshot features do not turn an image into a PDF invoice.

6. Or skip the browser setup

If your goal is an image capture, ScreenshotNeo can return one directly. See the API documentation for request details.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Cookie banners, popups, and chat widgets are removed before the shot. Bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Use it for image captures, and use a PDF renderer when the invoice itself must be a PDF.

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

7. Reliability, performance, and cost considerations

No comparable benchmark or cost evidence establishes that browser automation or hosted rendering is faster or less expensive. Measure your own invoice workload and include browser startup, rendering, retries, storage, and operational ownership in the comparison.

  • Reliability: use explicit navigation and readiness timeouts, detect missing invoice content before export, and record whether the failure was navigation, authentication, readiness, or PDF creation. Retry only failures that may be transient, and prevent duplicate delivery when a job is retried.
  • Performance: avoid waiting for network idle if the page keeps analytics or other long-lived connections open; wait for an invoice-specific ready marker instead. Reuse browser processes carefully if your deployment model permits it, while keeping each job’s session isolated.
  • Cost: account for the compute and maintenance of browser execution, or the provider’s published request and storage pricing. Compare equivalent output requirements and include failed jobs and retention needs. Verify provider pricing directly; there is no evidence here for a universal cost winner.
  • Invoice privacy: treat invoice HTML, URLs, cookies, credentials, and output files as sensitive. Review the actual hosting or API provider terms and configure access, retention, and deletion to match your requirements.

8. Troubleshooting

Symptom Likely cause Fix
PDF is styled differently from the browser view page.pdf() uses print CSS by default. Adjust print styles, or emulate screen media before exporting if screen styling is intended.
PDF export is unavailable or fails in another browser engine Playwright PDF export is Chromium-only. Launch Chromium for PDF generation.
Invoice content is missing or half-rendered The export began before application data or a client-rendered component was ready. Wait for a page-specific ready selector or application signal before calling page.pdf().
Navigation times out on a page that appears loaded A network-idle condition may never occur because of ongoing requests. Use a less restrictive navigation milestone, then wait for the invoice’s ready element.
Colors or logos disappear in print Background printing is disabled or the print stylesheet suppresses those elements. Enable printBackground and inspect print CSS and asset loading.
PDF content clips or splits awkwardly Paper size, margins, or page-break rules do not fit the invoice layout. Set the intended page size and margins; revise print CSS and test long invoices.
Authenticated invoice renders as a login page The browser context did not complete authentication, or the session was not available on the invoice navigation. Complete the permitted login flow in the same context and verify the invoice heading before export.
Hosted API response differs from local rendering The provider may expose different browser controls, waits, fonts, or resource access. Check that provider’s options and documentation; do not assume all hosted renderers behave alike.

9. Frequently asked questions

Can a screenshot be saved as a PDF?

An image can be embedded in a PDF container, but that does not make it equivalent to a properly paginated, text-capable invoice PDF. Generate the invoice as a PDF when document behavior matters.

Can Playwright create an invoice PDF from a logged-in page?

Yes, when your application can complete the authorized login and reach the invoice in a browser context before calling page.pdf(). Protect credentials and generated files according to your data policies.

Should I use an API or run Playwright myself?

Use Playwright when direct interaction and browser control are central and you can own the runtime. Consider an API for request-based rendering after verifying its feature support and terms. There is no established universal winner for price, speed, or reliability.

Does ScreenshotNeo generate PDF invoices?

ScreenshotNeo is presented here as a website screenshot API. Use its image output for visual captures; choose a PDF rendering workflow for a document invoice.

Sources