HTML to PDF

Utilities

Convert HTML templates with variables and CSS to PDF documents

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

Parameters

Name Type Required Description
html textarea Required HTML template. Send the HTML directly, or use [[var:template-variable]] to load a saved HTML template. Use [[variable]] tags inside the template/HTML for dynamic JSON data.
Example: <h1>Project Report</h1><p>Hello [[customer.name]]</p>
css textarea Optional CSS styles (url() is blocked for security). Send CSS directly, or use [[var:template-variable]] to load a saved CSS template, then combine it with HTML variables and 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: {"customer": {"name": "Acme Inc"}}
page_size select Optional Paper size for the PDF document
orientation select Optional Page orientation

Request Example

Direct HTML

Send the HTML and CSS in the request body.

{
    "html": "<h1>Project Report</h1><p>Hello [[customer.name]]</p>",
    "css": "body { font-family: sans-serif; color: #10211f; }",
    "data": {
        "invoice": {
            "number": "INV-1001"
        },
        "customer": {
            "name": "Acme Inc"
        }
    },
    "page_size": "A4",
    "orientation": "portrait"
}

Saved variables

Reference saved HTML and CSS with `[[var:...]]`.

{
    "html": "[[var:invoice-template-html]]",
    "css": "[[var:invoice-template-css]]",
    "data": {
        "invoice": {
            "number": "INV-1001"
        },
        "customer": {
            "name": "Acme Inc"
        }
    },
    "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 HTML or CSS variables, and [[variable]] inside templates for JSON data.

Try it out

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