HTML to PDF
Generate PDF documents from HTML templates in your Spala flows.
HTML to PDF
The HTML to PDF addon generates PDF documents from HTML content using a headless browser engine. Create invoices, reports, receipts, certificates, and any other document by writing HTML templates and converting them to PDF.
Installation
1. Enable the HTML to PDF addon from the Addons panel 2. No setup beyond enabling the addon
No API keys or external services are required — all rendering happens locally on the server.
Available Steps
Generate PDF
Renders HTML content as a PDF document.
Generate PDF from URL
Renders a web page at the given URL as a PDF.
Example: Invoice Generation
// POST /api/invoices/:orderId/pdf
// Step 1: Database Query - Get order with items // SELECT o.*, json_agg(oi.*) as items FROM orders o // JOIN order_items oi ON oi.order_id = o.id // WHERE o.id = params.orderId GROUP BY o.id
// Step 2: Set Variable - Build HTML
// vars.html = `
// <html>
// <style>
// body { font-family: Arial, sans-serif; padding: 40px; }
// .header { display: flex; justify-content: space-between; }
// table { width: 100%; border-collapse: collapse; margin-top: 20px; }
// th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
// .total { font-size: 24px; text-align: right; margin-top: 20px; }
// </style>
// <body>
// <div class="header
// <h1>Invoice #${vars.order.id}</h1>
// <p>Date: ${new Date(vars.order.created_at).toLocaleDateString()}</p>
// </div>
// <table>
// <tr><th>Item</th><th>Qty</th><th>Price</th><th>Total</th></tr>
// ${vars.order.items.map(item => `
// <tr>
// <td>${item.name}</td>
// <td>${item.quantity}</td>
// <td>${item.price.toFixed(2)}</td>
// <td>${(item.price * item.quantity).toFixed(2)}</td>
// </tr>
// `).join('')}
// </table>
// <p class="total">Total: ${vars.order.total.toFixed(2)}</p>
// </body>
// </html>
// `
// Step 3: Generate PDF (HTML to PDF addon)
// html: vars.html
// outputPath: storage + '/invoices/invoice-' + vars.order.id + '.pdf'
// format: 'A4'
// margin: { top: '20mm', bottom: '20mm', left: '15mm', right: '15mm' }
// Step 4: Response
// { pdfPath: vars.pdfPath }
Example: Report with Header/Footer
// Step 1: Generate PDF (HTML to PDF addon)
// html: vars.reportHtml
// outputPath: storage + '/reports/monthly-' + vars.month + '.pdf'
// format: 'A4'
// headerTemplate: '<div style="font-size:10px; width:100%; text-align:center;">Monthly Report - <span class="date"></span></div>'
// footerTemplate: '<div style="font-size:10px; width:100%; text-align:center;">Page <span class="pageNumber"></span> of <span class="totalPages"></span></div>'
// margin: { top: '30mm', bottom: '20mm' }
The HTML template supports full CSS including Flexbox and Grid layouts. You can use inline images with base64 data URIs or reference external image URLs.
PDF generation requires a headless browser and is resource-intensive. For high-volume document generation, run the operation in a background task to avoid blocking API responses.
The HTML content to render. Can include inline CSS and images.
File path where the PDF will be saved.
Paper size: 'A4' (default), 'Letter', 'Legal', 'A3', 'A5', or 'Tabloid'.
Set to true for landscape orientation (default: false).
Margins object with top, right, bottom, left values (e.g., { top: '20mm', bottom: '20mm' }).
HTML template for the page header. Use CSS classes: date, title, url, pageNumber, totalPages.
HTML template for the page footer.
The URL of the page to render.
File path where the PDF will be saved.
Paper size (default: A4).
CSS selector to wait for before rendering (useful for pages with async content).
Addons Overview
/addons
Browse available addons
Installing Addons
/addons/installing
Enable and configure addons in your project