Quickstart
Generate your first PDF document in under 5 minutes.
1. Get your API key
Sign in to DocPayload and navigate to Settings > API Keys to create a new key.
2. Create a document definition
A document definition is a JSON object that describes your PDF layout, styles, and content.
{
"document": {
"metadata": {
"title": "My First Document",
"author": "DocPayload"
},
"pageSetup": {
"size": "A4",
"orientation": "portrait",
"margins": [50, 40, 50, 40]
},
"styles": {
"title": { "fontSize": 22, "bold": true, "fontColor": "#1A1A2E" },
"body": { "fontSize": 11, "fontColor": "#333333", "textAlign": "justified" }
},
"content": [
{ "p": "Hello from DocPayload!", "style": "title" },
{ "p": "This PDF was generated from a JSON definition using the DocPayload API. You can add [b]bold text[/b], [i]italic text[/i], [fontcolor, #0066CC]colored text[/fontcolor], tables, lists, images, barcodes, and much more.", "style": "body" }
]
}
}
3. Generate the PDF
- cURL
- C#
- JavaScript
- Python
curl -X POST https://api.docpayload.com/v1/documents/generate-from-payload \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d @definition.json \
-o output.pdf
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", "YOUR_API_KEY");
var json = File.ReadAllText("definition.json");
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync(
"https://api.docpayload.com/v1/documents/generate-from-payload", content);
var pdfBytes = await response.Content.ReadAsByteArrayAsync();
File.WriteAllBytes("output.pdf", pdfBytes);
const response = await fetch('https://api.docpayload.com/v1/documents/generate-from-payload', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify(definition),
});
const blob = await response.blob();
const url = URL.createObjectURL(blob);
window.open(url);
import requests
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
}
with open("definition.json") as f:
response = requests.post(
"https://api.docpayload.com/v1/documents/generate-from-payload",
headers=headers,
data=f.read(),
)
with open("output.pdf", "wb") as f:
f.write(response.content)
4. Open your PDF
That's it! Open output.pdf to see your generated document.
Works with any stack
You just generated a PDF with a standard HTTP request. That's the entire integration — if your stack can POST JSON, you're ready.
PHP with curl_exec, Java with HttpClient, Ruby with Net::HTTP, Go with net/http, WordPress with wp_remote_post, legacy systems with any HTTP library — they all work. The code you just saw in the examples above is all you need. No special library to install or keep updated.
Point your IDE at the published JSON Schema and you'll get autocomplete on every property and red squiggles on typos before you ever hit the API:
{
"$schema": "https://docpayload.com/docs/schemas/v1/document-definition.schema.json",
"document": { "content": [{ "p": "Hello." }] }
}
That one line in your JSON file is all most editors need.
Next steps
- Document Definition — Learn the full schema
- Inline Formatting — Bold, italic, colors, images, barcodes
- Data Injection — Build reusable templates with dynamic data
- Playground — Try it live in the browser