Website screenshots & PDFs in Java

Skip Selenium, a bundled Chrome and Flying Saucer. The built-in java.net.http.HttpClient (Java 11+) gets you a PNG or PDF with no extra dependencies.

1. Get an API key

Click Get free key. You get 25 free renders a month instantly, no account needed. Store the key in an environment variable called SHOTMINT_KEY.

2. Screenshot a URL

import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;

public class Shot {
    public static void main(String[] args) throws Exception {
        var client = HttpClient.newHttpClient();
        var target = URLEncoder.encode("https://example.com", StandardCharsets.UTF_8);
        var req = HttpRequest.newBuilder(URI.create("https://shotmint.creasework.com/v1/screenshot?url=" + target + "&full_page=true"))
                .header("X-API-Key", System.getenv("SHOTMINT_KEY"))
                .timeout(Duration.ofSeconds(90))
                .build();
        var res = client.send(req, HttpResponse.BodyHandlers.ofByteArray());
        if (res.statusCode() != 200) {
            throw new RuntimeException("Render failed: " + new String(res.body(), StandardCharsets.UTF_8));
        }
        Files.write(Path.of("shot.png"), res.body());
        System.out.println("Credits left: " + res.headers().firstValue("X-Credits-Remaining").orElse("?"));
    }
}

Useful parameters: full_page=true for the whole scrollable page, width/height for the viewport, device_scale_factor=2 for retina, selector to capture a single element, dark_mode=true, and hide_selectors to remove cookie banners. See the full list.

3. Turn HTML into a PDF

var json = """
    {"html": "<h1>Invoice #42</h1>", "format": "A4"}
    """;
var req = HttpRequest.newBuilder(URI.create("https://shotmint.creasework.com/v1/pdf"))
        .header("X-API-Key", System.getenv("SHOTMINT_KEY"))
        .header("Content-Type", "application/json")
        .POST(HttpRequest.BodyPublishers.ofString(json))
        .build();
var res = client.send(req, HttpResponse.BodyHandlers.ofByteArray());
Files.write(Path.of("invoice.pdf"), res.body());

// Spring Boot controller: return it directly
// return ResponseEntity.ok().contentType(MediaType.APPLICATION_PDF).body(res.body());

PDF options include format (A4, Letter…), landscape, margin, and print_background. You can pass a url instead of html.

Errors & credits

A failed render never costs a credit. Status 400 means bad input or an unreachable URL, 402 means you're out of credits, and 429/503 mean you should retry with backoff. Every successful response includes an X-Credits-Remaining header, and screenshots and PDFs of a URL also carry X-Page-Status: the HTTP status the site answered with. A 403 there usually means you captured the site's bot-protection page, a 404 its error page.

Notes for Java

Save the first example as Shot.java and run it with java Shot.java, no build step needed. In a real app, build the JSON body with Jackson (mapper.writeValueAsString(Map.of("html", html, "format", "A4"))) so quotes in your template are escaped, and reuse one HttpClient across requests. The text block in the PDF example needs Java 15+.

Production version: retries, timeouts and page status

The quickstart above stops at the first error. In production you want three more things: retry only the failures that can fix themselves (503 when the renderer is busy, network timeouts), never retry a 400 or 402, and warn when the site itself answered with an error page. This script does all three for screenshots and PDFs, and prints the credits left after each call:

import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpTimeoutException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;

public class Render {
    static final String API = "https://shotmint.creasework.com";
    static final HttpClient HTTP = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).build();

    // Retries only what is worth retrying: 503 (renderer busy) and network errors.
    // A 400 (bad input, unreachable site) or 402 (no credits) will not fix itself.
    static byte[] render(String path, String json) throws IOException, InterruptedException {
        int attempts = 3;
        for (int i = 0; i < attempts; i++) {
            if (i > 0) Thread.sleep(1000L << (i - 1));
            HttpRequest req = HttpRequest.newBuilder(URI.create(API + path))
                .timeout(Duration.ofSeconds(90))
                .header("X-API-Key", System.getenv("SHOTMINT_KEY"))
                .header("Content-Type", "application/json")
                .POST(HttpRequest.BodyPublishers.ofString(json))
                .build();
            HttpResponse<byte[]> res;
            try {
                res = HTTP.send(req, HttpResponse.BodyHandlers.ofByteArray());
            } catch (HttpTimeoutException | java.net.ConnectException e) {
                if (i == attempts - 1) throw e;
                continue;
            }
            if (res.statusCode() == 200) {
                int page = Integer.parseInt(res.headers().firstValue("x-page-status").orElse("0"));
                if (page >= 400) System.err.println("site answered " + page + ": you may have captured an error or bot page");
                System.err.println("credits left: " + res.headers().firstValue("x-credits-remaining").orElse("?"));
                return res.body();
            }
            if (res.statusCode() != 503) {
                throw new IOException(res.statusCode() + ": " + new String(res.body()));
            }
        }
        throw new IOException("renderer still busy after " + attempts + " attempts");
    }

    public static void main(String[] args) throws Exception {
        Files.write(Path.of("shot.png"), render("/v1/screenshot",
            "{\"url\":\"https://en.wikipedia.org/wiki/Java_(programming_language)\",\"full_page\":true,\"format\":\"png\"}"));
        Files.write(Path.of("page.pdf"), render("/v1/pdf", "{\"url\":\"https://example.com\",\"format\":\"A4\"}"));
    }
}

HttpClient has no request timeout unless you set one on each HttpRequest (connectTimeout on the builder covers only the connection), so a hung site would block the thread forever. Run it with java Render.java (Java 11+; no build step, no dependencies). The error bodies are JSON ({"error": "..."}), printed as-is here; parse them with Jackson or Gson if your project already has one.

Timing, measured on 2026-10-25: a full-page capture of a long Wikipedia article plus an A4 PDF took 8.5 to 25 s end to end, so keep the read timeout well above 30 s. Full-page captures are capped at 16,000 px tall (the Go and PHP articles hit that cap). With a format the API doesn't support, the script stops at once with the API's own message: 400: format must be png, jpeg or webp (got "gif").

Try it with 25 free renders a month

No signup, no card. Get a key in one click, then buy credits only if you need more (from €5 for 2,000, never expire). From a script, an AI agent, Make or Zapier, POST /v1/keys/free (no body) returns a key as JSON (openapi.json, no-code recipes).

Get a free API key Full API reference

More guides: API quickstarts by language

All guides: guides · integrations · comparisons