Your first PDF
This example creates a complete document with caller supplied wording. Choose your preferred client. These examples use the address of the API you are viewing; change it to your deployment when integrating.
curl --fail-with-body \
-X POST __API_ORIGIN__/api/v1/pdfs/custom-template \
-H 'Content-Type: application/json' \
--data '{"template":{"title":"{{data.title}}","pages":[{"layout":"flow","blocks":[{"type":"heading","text":"{{labels.heading}}"},{"type":"paragraph","text":"{{data.summary}}"}]}]},"labels":{"heading":"Overview"},"data":{"title":"Project brief","summary":"Made for your app."}}' \
--output project-brief.pdf$baseUrl = '__API_ORIGIN__'
$requestPath = Join-Path ([IO.Path]::GetTempPath()) ([IO.Path]::GetRandomFileName())
$json = @{
template = @{ title = '{{data.title}}'; pages = @(@{ layout = 'flow'; blocks = @(
@{ type = 'heading'; text = '{{labels.heading}}' }
@{ type = 'paragraph'; text = '{{data.summary}}' }
) }) }
labels = @{ heading = 'Overview' }
data = @{ title = 'Project brief'; summary = 'Made for your app.' }
} | ConvertTo-Json -Depth 10
[IO.File]::WriteAllText($requestPath, $json, [Text.UTF8Encoding]::new($false))
try {
curl.exe --fail-with-body -X POST "$baseUrl/api/v1/pdfs/custom-template" `
-H 'Content-Type: application/json' `
--data-binary "@$requestPath" --output '.\project-brief.pdf'
if ($LASTEXITCODE -ne 0) { throw 'PDF generation failed.' }
} finally { Remove-Item -LiteralPath $requestPath }using System.Net.Http.Json;
using var client = new HttpClient { BaseAddress = new Uri("__API_ORIGIN__") };
// If required: client.DefaultRequestHeaders.Add("X-Api-Key", yourKey);
using var response = await client.PostAsJsonAsync("/api/v1/pdfs/custom-template", new
{
template = new
{
title = "{{data.title}}",
pages = new[] { new { layout = "flow", blocks = new[] {
new { type = "heading", text = "{{labels.heading}}" },
new { type = "paragraph", text = "{{data.summary}}" }
} } }
},
labels = new { heading = "Overview" },
data = new { title = "Project brief", summary = "Made for your app." }
});
response.EnsureSuccessStatusCode();
await File.WriteAllBytesAsync("project-brief.pdf", await response.Content.ReadAsByteArrayAsync());import { writeFile } from 'node:fs/promises';
const response = await fetch('__API_ORIGIN__/api/v1/pdfs/custom-template', {
method: 'POST',
headers: { 'Content-Type': 'application/json' }, // Add X-Api-Key if required.
body: JSON.stringify({
template: {
title: '{{data.title}}',
pages: [{ layout: 'flow', blocks: [
{ type: 'heading', text: '{{labels.heading}}' },
{ type: 'paragraph', text: '{{data.summary}}' }
] }]
},
labels: { heading: 'Overview' },
data: { title: 'Project brief', summary: 'Made for your app.' }
})
});
if (!response.ok) throw new Error(await response.text());
await writeFile('project-brief.pdf', Buffer.from(await response.arrayBuffer()));On deployments that require a key, add -H 'X-Api-Key: YOUR_KEY' to cURL. Use a backend for calls from your platform so its API key stays private.