JSON to PDF

Utilities

Convert JSON data + HTML template to PDF (invoices, reports, payslips)

POST /api/utilities/json-to-pdf Auth Required
!
Action Cost: This tool consumes 3 actions per request.

Parameters

Name Type Required Description
html textarea Required HTML template. Use [[var:template-variable]] to load a saved template, then [[variable]] tags inside the template/HTML for dynamic JSON data.
Example: <h1>Invoice #[[id]]</h1>
css textarea Optional CSS styles (url() is blocked for security). Use [[var:template-variable]] to load a saved template, then [[variable]] tags inside the template for JSON data.
Example: h1 { color: blue; }
data json Optional JSON object with data to populate the template. Use [[variable]] tags in the HTML template to access this data.
Example: {"id": "12345", "amount": "99.99"}
page_size select Optional Paper size for the PDF document
orientation select Optional Page orientation

Request Example

curl -X POST https://nisastack.com/api/utilities/json-to-pdf \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1>Invoice #[[id]]</h1><p>Total: $[[amount]]</p>",
    "css": "h1 { color: #333; }",
    "data": {
        "id": "12345",
        "amount": "99.99"
    },
    "page_size": "A4",
    "orientation": "portrait"
}'

Response Format

Success Response (200 OK)

{
  "success": true,
  "data": {"download_url": "https://app.com/files/download/files/123/abc123.pdf", "signed_url": "https://pub-xxx.r2.dev/files/123/abc123.pdf?X-Amz-Signature=...", "signed_url_expires_at": "2026-05-16T15:30:00Z", "expires_at": "2026-05-15T15:30:00Z", "pdf_base64": "JVBERi...", "size_bytes": 12345, "page_count": 1},
  "metadata": {
    "actions_consumed": 3
  }
}

Error Response

{
  "success": false,
  "error": "Error message describing what went wrong"
}

Additional Notes

Maximum 50 pages. CSS url() is blocked for security. Remote images require valid HTTPS URLs. Data URLs must be PNG/JPEG/GIF only. Use [[var:...]] to insert saved variables, and [[variable]] inside templates for JSON data.

Try it out

Test this tool interactively in the playground with your own API token.