PDF API

Pixel-perfect PDFs from URLs or HTML through real Chromium — invoices, reports, contracts, certificates. Your CSS just works.

POST /v1/pdf → Binary document (application/pdf)

Example

curl -X POST https://rasterkit.com/v1/pdf \
  -H "x-api-key: $RASTERKIT_API_KEY" \
  -H "content-type: application/json" \
  -d '{"url": "https://example.com/invoice/42", "format": "A4", "print_background": true}' \
  -o document.pdf
import { writeFile } from 'node:fs/promises'

const res = await fetch('https://rasterkit.com/v1/pdf', {
  method: 'POST',
  headers: {
    'x-api-key': process.env.RASTERKIT_API_KEY,
    'content-type': 'application/json',
  },
  body: JSON.stringify({"url": "https://example.com/invoice/42", "format": "A4", "print_background": true}),
})
if (!res.ok) throw new Error(`Render failed: ${res.status} ${await res.text()}`)
await writeFile('document.pdf', Buffer.from(await res.arrayBuffer()))
console.log('Saved document.pdf')
import os
import requests

res = requests.post(
    "https://rasterkit.com/v1/pdf",
    headers={"x-api-key": os.environ["RASTERKIT_API_KEY"]},
    json={"url": "https://example.com/invoice/42", "format": "A4", "print_background": True},
    timeout=60,
)
res.raise_for_status()
with open("document.pdf", "wb") as f:
    f.write(res.content)
print("Saved document.pdf")
<?php
$ch = curl_init('https://rasterkit.com/v1/pdf');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 60,
    CURLOPT_HTTPHEADER => [
        'x-api-key: ' . getenv('RASTERKIT_API_KEY'),
        'content-type: application/json',
    ],
    CURLOPT_POSTFIELDS => '{"url": "https://example.com/invoice/42", "format": "A4", "print_background": true}',
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
if ($status !== 200) {
    throw new RuntimeException("Render failed: $status $body");
}
file_put_contents('document.pdf', $body);
echo "Saved document.pdf\n";
require "net/http"
require "json"

uri = URI("https://rasterkit.com/v1/pdf")
req = Net::HTTP::Post.new(uri)
req["x-api-key"] = ENV.fetch("RASTERKIT_API_KEY")
req["content-type"] = "application/json"
req.body = '{"url": "https://example.com/invoice/42", "format": "A4", "print_background": true}'

res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: 60) { |http| http.request(req) }
raise "Render failed: #{res.code} #{res.body}" unless res.code == "200"
File.binwrite("document.pdf", res.body)
puts "Saved document.pdf"
package main

import (
	"bytes"
	"fmt"
	"io"
	"net/http"
	"os"
	"time"
)

func main() {
	body := []byte(`{"url": "https://example.com/invoice/42", "format": "A4", "print_background": true}`)
	req, _ := http.NewRequest("POST", "https://rasterkit.com/v1/pdf", bytes.NewReader(body))
	req.Header.Set("x-api-key", os.Getenv("RASTERKIT_API_KEY"))
	req.Header.Set("content-type", "application/json")

	client := &http.Client{Timeout: 60 * time.Second}
	res, err := client.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()

	data, _ := io.ReadAll(res.Body)
	if res.StatusCode != 200 {
		panic(fmt.Sprintf("render failed: %d %s", res.StatusCode, data))
	}
	os.WriteFile("document.pdf", data, 0644)
	fmt.Println("Saved document.pdf")
}
import java.net.URI;
import java.net.http.*;
import java.nio.file.*;
import java.time.Duration;

public class Render {
    public static void main(String[] args) throws Exception {
        String body = """
            {"url": "https://example.com/invoice/42", "format": "A4", "print_background": true}""";
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://rasterkit.com/v1/pdf"))
            .timeout(Duration.ofSeconds(60))
            .header("x-api-key", System.getenv("RASTERKIT_API_KEY"))
            .header("content-type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(body))
            .build();

        HttpResponse<byte[]> res = HttpClient.newHttpClient()
            .send(request, HttpResponse.BodyHandlers.ofByteArray());
        if (res.statusCode() != 200) {
            throw new RuntimeException("Render failed: " + res.statusCode() + " " + new String(res.body()));
        }
        Files.write(Path.of("document.pdf"), res.body());
        System.out.println("Saved document.pdf");
    }
}
using System.Text;

var client = new HttpClient { Timeout = TimeSpan.FromSeconds(60) };
client.DefaultRequestHeaders.Add("x-api-key",
    Environment.GetEnvironmentVariable("RASTERKIT_API_KEY"));

var body = new StringContent(
    """{"url": "https://example.com/invoice/42", "format": "A4", "print_background": true}""",
    Encoding.UTF8, "application/json");

var res = await client.PostAsync("https://rasterkit.com/v1/pdf", body);
var bytes = await res.Content.ReadAsByteArrayAsync();
if (!res.IsSuccessStatusCode)
    throw new Exception($"Render failed: {(int)res.StatusCode} {Encoding.UTF8.GetString(bytes)}");

await File.WriteAllBytesAsync("document.pdf", bytes);
Console.WriteLine("Saved document.pdf");

Parameters

Send as a JSON body. Exactly the same fields work as query parameters on the signed GET variant.

ParameterTypeDefaultDescription
url url Page to print. Exactly one of url or html.
html string ≤2MB Raw HTML (invoices, reports, certificates).
format A4 | A3 | A5 | Letter | Legal | Tabloid A4 Paper size.
landscape bool false Landscape orientation.
margin_top/right/bottom/left css size 10mm Page margins, any CSS unit.
header_template html Repeating header. Supports <span class="pageNumber"> etc.
footer_template html Repeating footer.
page_ranges string all e.g. "1-3, 5".
print_background bool true Include CSS backgrounds.
prefer_css_page_size bool false Let @page CSS rules win over format.
scale number 0.1–2 1 Zoom factor.
delay_ms int 0–10000 0 Extra wait after load, for animations or late JS.
wait_until load | domcontentloaded | networkidle load Navigation settled condition before capture.
wait_for_selector string Block until this CSS selector is visible.
timeout_ms int 1000–60000 30000 Hard cap for navigation + capture.
cache_ttl int 0–604800 (s) 0 Cache the result; identical requests within the TTL are served free and instantly.
async bool false Return 202 + job id immediately instead of waiting.
webhook_url url POSTed (signed) when an async job finishes.

Responses

Headers, footers & page numbers

{
  "html": "<h1>Report</h1> …",
  "footer_template": "<div style='font-size:9px;margin:0 auto'>Page <span class='pageNumber'></span> of <span class='totalPages'></span></div>",
  "margin_bottom": "18mm"
}

Chromium injects pageNumber, totalPages, date, title, and url via those CSS classes. Header/footer templates need inline styles and an explicit small font-size.

Page breaks

Standard CSS works: break-inside: avoid on cards/rows, break-after: page to force a new page, and @page rules with prefer_css_page_size: true.