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 |
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