ScreenshotNeo

BlogGuides

Website Screenshot APIs: Converting URLs to JPG, PNG, and PDF

Learn how screenshot APIs turn URLs into JPG, PNG, or PDF files, with runnable Playwright code, API patterns, troubleshooting, and format guidance.

By the ScreenshotNeo team1 October 20267 min read

Short answer: a website screenshot API opens a URL in a managed browser, waits for the page to render, and returns a binary image or document. Use JPEG for compact photographic images, PNG for lossless detail or transparency, and PDF for print, invoices, and archival workflows. For complete control, run Playwright yourself; for a one-request integration, use ScreenshotNeo.

What a website screenshot API does

The service receives a URL, authentication, and render options, loads the page in a browser, executes its JavaScript, and returns the rendered result. Depending on the provider, the response is a direct binary stream or a JSON object containing a URL. Authentication is commonly an access key. The response Content-Type identifies whether the body is an image or PDF.

This differs from downloading HTML: CSS, fonts, client-side data, lazy images, and consent dialogs all affect the rendered pixels. A reliable integration therefore chooses a viewport, wait strategy, and page state as carefully as it chooses the output format.

Choose JPG, PNG, or PDF

Format Use it when Trade-offs
JPG/JPEG Photos, thumbnails, email previews, and bandwidth-sensitive delivery Lossy compression; no transparency; text can show artifacts
PNG UI screenshots, diagrams, sharp text, and transparent backgrounds Usually larger than JPEG for photographic pages
PDF Print, invoices, reports, archival copies, or downloadable documents Pagination, paper size, margins, and print CSS affect the result

WebP and other formats may also be available. Select the format your downstream system accepts instead of converting after the fact.

DIY: render a URL with Playwright

Running a browser yourself is useful when you need custom code, private network access, or complete control over the capture pipeline. This example produces PNG, JPEG, and PDF files from one URL.

1. Install Chromium

mkdir url-capture
cd url-capture
npm init -y
npm install playwright
npx playwright install chromium

2. Save capture.js

const { chromium } = require('playwright');

async function capture(url) {
  const browser = await chromium.launch();
  const page = await browser.newPage({
    viewport: { width: 1440, height: 900 },
    deviceScaleFactor: 1
  });
  try {
    await page.goto(url, { waitUntil: 'networkidle', timeout: 60000 });
    await page.screenshot({ path: 'page.png', fullPage: true, type: 'png' });
    await page.screenshot({ path: 'page.jpg', fullPage: true, type: 'jpeg', quality: 85 });
    await page.pdf({
      path: 'page.pdf', format: 'A4', printBackground: true,
      margin: { top: '12mm', right: '12mm', bottom: '12mm', left: '12mm' }
    });
  } finally {
    await browser.close();
  }
}
const url = process.argv[2];
if (!url) { console.error('Usage: node capture.js https://example.com'); process.exit(1); }
capture(url).catch(error => { console.error(error); process.exit(1); });
node capture.js https://example.com

fullPage: true grows the image to the document height. PDF output follows print layout and can paginate differently from a tall image.

Capture one element

const card = page.locator('[data-testid="invoice"]');
await card.waitFor({ state: 'visible', timeout: 30000 });
await card.screenshot({ path: 'invoice.png', type: 'png' });

Make dynamic pages deterministic

await page.goto(url, { waitUntil: 'domcontentloaded' });
await page.waitForSelector('#report-ready', { state: 'visible', timeout: 30000 });
await page.waitForTimeout(500);
await page.screenshot({ path: 'stable.png', fullPage: true });

Prefer a meaningful ready selector to an arbitrary sleep. If a site never becomes idle because analytics or sockets remain open, use domcontentloaded plus a selector or bounded delay.

API request and response mechanics

Most screenshot APIs accept GET query parameters or POST data. Keep credentials server-side, URL-encode the target, set a client timeout longer than the page’s expected load time, and write the binary body directly to disk or object storage. For large HTML or Markdown inputs, POST JSON avoids URL-length limits. Check Content-Type before treating the body as an image.

Render controls that affect the result

  • Viewport and device: set width, height, device emulation, and retina scale.
  • Full page versus element: full-page mode captures the document; a CSS selector limits the shot to one component.
  • Waiting: wait for a selector, delay, or network idle. Lazy-loaded images often need scrolling or full-page mode.
  • JavaScript and interaction: run custom JavaScript or click an element before capture.
  • Page state: supply cookies, headers, Authorization, user agent, timezone, or geolocation.
  • Noise control: hide selectors and block ads, trackers, requests, or resource types.
  • Output: choose PNG, JPEG, WebP, or PDF; PDF controls include paper size, margins, landscape, and page ranges.
  • Delivery: use caching with a chosen TTL, signed links for public images, asynchronous jobs with signed webhooks, and bulk capture when supported.

PDF details developers usually miss

PDF pagination is provider-specific. Paper size, margins, landscape mode, print CSS, and page ranges change where content breaks. A “full page” PDF may mean one very tall page or a normal multi-page document, so verify the provider’s definition before building an invoice workflow. Enable background printing when colored panels are part of the document.

Provider comparison

1. ScreenshotNeo — clean shots with consent banners, newsletter popups, and chat widgets removed; only clean shots are billed, and the paid entry plan is $5.

Provider Documented capabilities Best fit
ApiFlash Authenticated HTTPS URL-to-image endpoint, current Chrome rendering, GET or POST requests, and direct image or JSON-link responses. A simple URL-to-image endpoint.
ScreenshotOne GET and POST, access keys, image quality and viewport controls, metadata, broad image/document formats, and URL/HTML/Markdown-to-PDF workflows. Projects needing many output formats or HTML/Markdown input.
Urlbox URL or HTML rendering, image/PDF/video/markup outputs, viewport and format options, a full_page option, and SDK examples. Teams needing broad render options and SDKs.

Compare output formats, viewport and device emulation, full-page behavior, waits and JavaScript, selectors, cookies, PDF pagination, metadata, signing, response style, SDKs, rate limits, and price. The reviewed documentation does not provide a common independent speed benchmark, so test your own pages.

Or skip the browser setup

ScreenshotNeo exposes one GET request that returns a PNG, JPEG, WebP, or PDF. See the ScreenshotNeo API docs for the complete option list.

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}`);

Before capture, ScreenshotNeo accepts cookie and consent banners 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 cost nothing, and every response reports the result in X-Page-Verdict and X-Billed headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000.

Create a free ScreenshotNeo account and start with the 1,000 included shots.

Troubleshooting

Symptom Cause Fix
Blank image Capture happened before client rendering finished. Wait for a ready selector, use a bounded delay, and confirm the page works in the same viewport.
Images missing Lazy loading, blocked resources, or early capture. Use full-page mode or scroll, allow image requests, and wait for the image selector.
Cookie banner covers content Consent is required before the page is usable. Accept or remove it in your browser flow; enable ScreenshotNeo’s consent handling and cleanup.
Timeout or network idle never arrives Long polling, analytics, or a stuck third-party request. Use domcontentloaded plus a selector or delay, block nonessential requests, and keep a hard timeout.
PDF breaks oddly Paper size, margins, print CSS, or provider pagination rules. Set these explicitly and test representative content lengths.
401/403 response Missing key, expired credentials, or target authentication. Keep the key server-side, send required headers or cookies, and verify the target URL.
Output is too large High retina scale, PNG compression, or a very tall page. Use JPEG/WebP for photos, reduce scale, capture an element, or resize.

Performance, reliability, and cost

  • Bound the work: set navigation and overall request timeouts.
  • Reduce bytes: block trackers and ads, choose an appropriate viewport, and use JPEG/WebP when lossless output is unnecessary.
  • Retry safely: retry transient network failures with backoff and avoid duplicate page side effects. Cache stable URLs with a TTL.
  • Observe artifacts: log URL, viewport, format, duration, status, and cache state. For ScreenshotNeo, also record X-Page-Verdict and X-Billed.
  • Budget by clean results: ScreenshotNeo bills only clean shots; bot checks, blank pages, timeouts, failed loads, and cache hits are not billed. Check other providers’ current billing rules separately.

Integration checklist

  1. Choose the format based on delivery requirements.
  2. Set viewport, device scale, timezone, and locale deliberately.
  3. Define a ready condition and hard timeout.
  4. Handle lazy images, consent dialogs, authentication, and popups.
  5. Validate Content-Type, status, and output bytes.
  6. Cache deterministic pages and retry only transient failures.
  7. Track billing or verdict headers where supplied.

FAQ

Can an API convert any URL directly to JPG or PNG?

It can render publicly reachable pages, subject to browser, network, authentication, and anti-bot behavior. Private pages need supported headers, cookies, or a browser inside your network.

Is a full-page PNG the same as a PDF?

No. A full-page PNG is one raster image whose height follows the document. A PDF is laid out according to paper and print settings.

Should I use GET or POST?

GET is convenient for a URL and small option set. POST is safer for large HTML or Markdown inputs and avoids URL-length limits.

How do I capture a page for an AI agent?

Use an MCP server with screenshot and page-inspection tools. ScreenshotNeo provides take_screenshot, get_page_info, and capture_pdf.

What should I test before shipping?

Test short and long pages, mobile and desktop viewports, slow resources, consent dialogs, authenticated routes, missing assets, and PDF page breaks.