Generation and Templates

The PDF Toolkit can create new documents from images or HTML-like Liquid templates.

Generation endpoints

Endpoint Purpose
POST /v1/pdf/from-images Combine images into a PDF
POST /v1/pdf/from-template Render a Liquid template to PDF
GET /v1/pdf/download/{object_name} Download a processed output when storage-backed responses are enabled

REST API Examples

Create a PDF from images

curl -X POST "https://pdf.toolkitapi.io/v1/pdf/from-images" \
  -H "X-API-Key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"image_urls": ["https://toolkitapi.io/page-1.png", "https://toolkitapi.io/page-2.png"], "format": "a4"}'
const resp = await fetch("https://pdf.toolkitapi.io/v1/pdf/from-images", {
  method: "POST",
  headers: { "X-API-Key": "YOUR_KEY", "Content-Type": "application/json" },
  body: JSON.stringify({
    image_urls: ["https://toolkitapi.io/page-1.png", "https://toolkitapi.io/page-2.png"],
    format: "a4",
  }),
});
const data = await resp.json();
console.log(`Generated PDF: ${data.result_url}`);

Render a template to PDF

curl -X POST "https://pdf.toolkitapi.io/v1/pdf/from-template" \
  -H "X-API-Key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"template": "<html><body><h1>{{ title }}</h1><p>{{ body }}</p></body></html>", "variables": {"title": "Report", "body": "Generated on {{ date }}"}}'

Create a PDF from images

from toolkitapi import PDF

with PDF(api_key="tk_...") as pdf:
    result = pdf.from_images(
        image_urls=[
            "https://toolkitapi.io/page-1.png",
            "https://toolkitapi.io/page-2.png",
        ],
        page_size="A4",
        margin=24,
    )
    print(result["page_count"])

Render a Liquid template to PDF

from toolkitapi import PDF

invoice_template = """
<html>
  <body>
    <h1>Invoice for {{ customer }}</h1>
    <p>Total: {{ total }}</p>
  </body>
</html>
"""

with PDF(api_key="tk_...") as pdf:
    result = pdf.from_template(
        template=invoice_template,
        variables={"customer": "Acme Ltd", "total": "$199"},
        strict=True,
        page_size="Letter",
    )
    print(result["page_count"])

Use a hosted template URL

from toolkitapi import PDF

with PDF(api_key="tk_...") as pdf:
    result = pdf.from_template(
        template_url="https://toolkitapi.io/templates/invoice.liquid",
        variables={"invoice_no": "INV-1001"},
    )
    print(result["rendered_html_length"])

Download a processed file

from toolkitapi import PDF

with PDF(api_key="tk_...") as pdf:
    data = pdf.download("some-output-file.pdf", output_path="out.pdf")

Good use cases

  • invoices and quotes
  • generated reports
  • turning image bundles into PDFs
  • template-driven exports from your own application