ScreenshotNeo

BlogHTML to image & PDF

How to Save ScreenshotMachine CLI Captures as PDF

ScreenshotMachine documents a curl request to its PDF API for saving webpage captures from the command line. Here are the command, output settings, and fixes for common problems.

By the ScreenshotNeo team4 October 20266 min read

To save a ScreenshotMachine webpage capture as a PDF from the command line, send a GET request to its PDF API with curl and redirect the response body to a file. ScreenshotMachine’s documented endpoint is https://pdfapi.screenshotmachine.com. The service requires a customer key.

The official material reviewed documents this curl/API workflow, not a separate ScreenshotMachine CLI executable or installation process. The command below is therefore curl calling the PDF API, rather than a vendor CLI command. See ScreenshotMachine’s official PDF API guide.

Save a PDF with curl

Set your key and target URL, then run:

#!/usr/bin/env bash
set -euo pipefail

CUSTOMER_KEY="YOUR_CUSTOMER_KEY"
URL="https://example.com"
OUTPUT="output.pdf"

curl --fail --show-error --silent --get \
  "https://pdfapi.screenshotmachine.com" \
  --data-urlencode "key=$CUSTOMER_KEY" \
  --data-urlencode "url=$URL" \
  --output "$OUTPUT"

printf 'Saved %s\n' "$OUTPUT"

Replace the placeholder key with your account key, the URL with the page to capture, and the output path as needed. --data-urlencode safely encodes query values such as URLs that contain ampersands or other reserved characters. --output saves the response body to the named file; the documented API guide also demonstrates shell redirection with > output.pdf.

Keep the key out of source control and shared scripts. For local use, you can read it from an environment variable instead of writing it into the script:

#!/usr/bin/env bash
set -euo pipefail

: "${SCREENSHOTMACHINE_KEY:?Set SCREENSHOTMACHINE_KEY first}"
URL="https://example.com"

curl --fail --show-error --silent --get \
  "https://pdfapi.screenshotmachine.com" \
  --data-urlencode "key=$SCREENSHOTMACHINE_KEY" \
  --data-urlencode "url=$URL" \
  --output "page.pdf"

For example, set SCREENSHOTMACHINE_KEY in your shell environment before running this script. The required parameter names are key and url.

Choose PDF rendering options

The PDF API guide documents options for page size and rendering. Add each option as another --data-urlencode argument. Use only values supported by the vendor’s guide.

Parameter What it controls Documented choices or behavior
paper PDF page size Defaults to letter. Listed sizes include letter, legal, ledger, tabloid, and ISO A0 through A6.
orientation Page direction Portrait is the default; landscape is also accepted.
media Screen or print rendering screen targets a browser-like appearance. print creates a print-optimized PDF without web-specific graphics or elements the service considers unnecessary for printing.
bg Page background Use bg to include the page background or nobg to omit it.
delay Wait before conversion The guide lists allowed millisecond values from 0 through 10000. A longer wait can give content time to settle, but does not guarantee that every dynamic page will finish loading.
scale Page scale The API sample includes this parameter. Consult the official guide for accepted values and choose one suitable for the output.

Here is a command combining common choices. The values below illustrate the documented option names; adjust them for your output:

curl --fail --show-error --silent --get \
  "https://pdfapi.screenshotmachine.com" \
  --data-urlencode "key=YOUR_CUSTOMER_KEY" \
  --data-urlencode "url=https://example.com" \
  --data-urlencode "paper=a4" \
  --data-urlencode "orientation=landscape" \
  --data-urlencode "media=screen" \
  --data-urlencode "bg" \
  --data-urlencode "delay=1000" \
  --data-urlencode "scale=1" \
  --output "example.pdf"

For print-oriented output, try media=print; to omit the page background, use nobg in place of bg. The exact accepted values for scale and delay should be checked against the current API documentation.

Python example

Python can make the same GET request and write the response bytes to disk. Install the requests package if it is not already available in your environment.

import os
from pathlib import Path

import requests

key = os.environ["SCREENSHOTMACHINE_KEY"]
params = {
    "key": key,
    "url": "https://example.com",
    "paper": "a4",
    "orientation": "portrait",
    "media": "screen",
    "bg": "",
    "delay": "1000",
}

response = requests.get(
    "https://pdfapi.screenshotmachine.com",
    params=params,
    timeout=90,
)
response.raise_for_status()

output = Path("page.pdf")
output.write_bytes(response.content)
print(f"Saved {output} ({output.stat().st_size} bytes)")

Set the SCREENSHOTMACHINE_KEY environment variable before running this program. The request library encodes the query parameters. If you include optional parameters, use values from the official API guide.

Node.js example

This example uses Node’s built-in fetch and file APIs. It requires a Node version that provides global fetch.

import { writeFile } from "node:fs/promises";

const key = process.env.SCREENSHOTMACHINE_KEY;
if (!key) throw new Error("Set SCREENSHOTMACHINE_KEY first");

const params = new URLSearchParams({
  key,
  url: "https://example.com",
  paper: "a4",
  orientation: "portrait",
  media: "screen",
  bg: "",
  delay: "1000",
});

const response = await fetch(
  `https://pdfapi.screenshotmachine.com?${params}`
);
if (!response.ok) {
  throw new Error(`PDF API returned HTTP ${response.status}`);
}

const bytes = new Uint8Array(await response.arrayBuffer());
await writeFile("page.pdf", bytes);
console.log(`Saved page.pdf (${bytes.byteLength} bytes)`);

Save this as an ES module file, or adapt the imports to your project’s module setup. As with curl and Python, keep the key in an environment variable rather than committing it.

PDF API versus the screenshot API

Use https://pdfapi.screenshotmachine.com for PDF output. ScreenshotMachine documents a separate https://api.screenshotmachine.com endpoint for screenshot image output, with JPG, PNG, and GIF formats. Sending a PDF workflow to the image endpoint is the wrong route. See the vendor’s screenshot API guide for the image endpoint and formats.

ScreenshotMachine also offers a browser-based PDF converter. Use the API for repeatable terminal commands or scripts; use the converter for a one-off browser interaction.

Common problems and fixes

Symptom Likely cause What to check
The request is rejected The key is missing, misspelled, or invalid. Confirm that the request includes key, and that the environment variable contains the intended account key.
The output is not a usable PDF The request failed but its response body was still written to a file, or the image endpoint was used. Use the PDF endpoint. With curl, add --fail so HTTP errors produce a nonzero exit code rather than silently looking like a successful download.
The page is missing content The page may need more time before conversion, or its content may depend on client-side loading. Try a documented delay value that gives the page more time. A delay cannot guarantee that every dynamic page or interaction will complete.
Query values behave unexpectedly Reserved URL characters were not encoded correctly. Use curl’s --data-urlencode, Python’s params, or Node’s URLSearchParams rather than concatenating a raw query string.
Layout or colors differ from expectation Paper, orientation, media mode, or background settings do not match the intended use. Review paper, orientation, media, and bg/nobg. Compare screen and print rendering for the target page.
The shell reports that the key variable is unset The environment variable was not exported into the process environment. Set and export SCREENSHOTMACHINE_KEY in the shell that launches the script.

Reliability, runtime, and cost considerations

The request’s response body is the PDF, so make sure your program checks the HTTP result before treating the bytes as a document. For scripts, curl’s --fail and language-level status checks help distinguish an HTTP error from a successful download. Use an appropriate request timeout for your environment; no completion time is guaranteed by the cited API material.

The delay option adds waiting before conversion and can increase the time spent per request. Use a larger documented delay only when the page needs it. The cited material does not provide a reliable benchmark or a price schedule, so check ScreenshotMachine’s current account and API documentation for applicable costs and limits.

For repeatable jobs, write to a temporary filename first and rename it after a successful response. This avoids leaving a partial or error response at the final path if a script is interrupted. Treat the customer key as a secret and rotate it according to your account’s security practices.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server by Yorker Media. For PDF output, make one GET request and save the response:

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

See the ScreenshotNeo API documentation for request options. Cookie and consent banners are accepted like a visitor and removed before the shot, along with 60+ known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks, blank pages, and failed loads are never billed, and response headers report the page verdict and billing status. Its MCP server lets AI agents use take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.

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

FAQ

Is there a ScreenshotMachine CLI to install?

The official material reviewed documents a curl request to the PDF API. It does not establish a separate CLI executable or installation process.

Can I use this for a one-time PDF?

Yes. Run the curl command once, or use ScreenshotMachine’s browser-based converter for a one-off browser workflow.

Which endpoint returns the PDF?

https://pdfapi.screenshotmachine.com. The separate ScreenshotMachine API endpoint is documented for image captures.

Can I choose a paper size and orientation?

Yes. The PDF API guide lists paper sizes including letter and ISO A0 through A6, and supports portrait or landscape orientation.