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 100 free renders 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.

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+.

Try it with 100 free renders

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).

Get a free API key Full API reference