Built for Real-World PDF Workflows

Whether you are generating invoices for an e-commerce platform, compiling quarterly financial reports, printing transaction receipts, or exporting technical documentation, PDFSpark handles it all through a single, consistent API. Every PDF is rendered by a real Chromium browser, so your output matches exactly what you see in Chrome's print preview.

🧾

Invoice Generation

Automate invoice creation for SaaS billing, freelance work, or e-commerce orders. PDFSpark renders your branded HTML invoice template into a professional PDF complete with logos, tables, tax breakdowns, and payment details. Use CSS Grid and Flexbox for precise layout control that older PDF generators cannot handle. Every invoice renders with web fonts, colored backgrounds, and crisp vector text ready for email delivery or archival storage.

  • CSS Grid layouts for line-item tables
  • Custom web fonts for brand consistency
  • Dynamic page breaks for multi-page invoices
  • Header and footer templates with page numbers
📊

Financial Reports

Convert data-rich dashboards and financial summaries into distributable PDF reports. PDFSpark executes JavaScript before capture, so charts rendered by libraries like Chart.js or D3.js appear exactly as they do in the browser. Set landscape orientation for wide tables, configure custom margins for binding, and use the print media type to optimize styles for paper output. Ideal for monthly analytics, investor updates, and compliance documents.

  • JavaScript execution for dynamic charts
  • Landscape orientation for wide datasets
  • Print media emulation for optimized styles
  • Custom metadata for document properties
📝

Transaction Receipts

Generate compact, branded receipts for online purchases, subscription renewals, or payment confirmations. PDFSpark supports custom page sizes, so you can produce standard A4 receipts or narrow thermal-printer-width formats. Embed QR codes linking to order details, include itemized breakdowns, and attach the PDF directly to confirmation emails. The API responds in seconds, making it suitable for real-time transactional workflows triggered by payment webhooks.

  • Custom page sizes for receipt formats
  • Sub-second generation for real-time use
  • QR code and barcode rendering support
  • Compact layouts with minimal margins
📚

Documentation Export

Export help articles, user manuals, API references, and knowledge base content as downloadable PDFs. PDFSpark preserves syntax highlighting in code blocks, maintains heading hierarchy for table-of-contents generation, and handles long-form content with automatic pagination. Use the /api/v1/pdf/from-url endpoint to capture live documentation pages directly, or send pre-rendered HTML for full control over the output.

  • Syntax-highlighted code blocks preserved
  • Automatic pagination for long documents
  • URL-to-PDF for live page capture
  • PDF merge for multi-section manuals

Practical Code Examples

Integrate HTML to PDF conversion into your application in minutes. Here are production-ready examples for the most common use cases across three popular languages.

Invoice PDF — cURL

cURL — Generate an invoice PDF
curl -X POST "https://pdfspark.dev/api/v1/pdf/from-html" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<html><head><style>body{font-family:Inter,sans-serif} table{width:100%;border-collapse:collapse} th,td{border:1px solid #ddd;padding:8px;text-align:left} .total{font-weight:bold;font-size:1.2em}</style></head><body><h1>Invoice #2026-0042</h1><p>Date: 2026-03-31</p><table><tr><th>Item</th><th>Qty</th><th>Price</th></tr><tr><td>API Integration</td><td>1</td><td>$500.00</td></tr><tr><td>Support Plan</td><td>1</td><td>$150.00</td></tr></table><p class=\"total\">Total: $650.00</p></body></html>",
    "options": {
      "format": "A4",
      "margin": { "top": "20mm", "bottom": "20mm", "left": "15mm", "right": "15mm" },
      "printBackground": true
    }
  }' \
  -o invoice-2026-0042.pdf

Report PDF — JavaScript

JavaScript (Node.js) — Generate a financial report
const fs = require('fs');

async function generateReport(htmlContent) {
  const response = await fetch('https://pdfspark.dev/api/v1/pdf/from-html', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      html: htmlContent,
      options: {
        format: 'A4',
        landscape: true,
        printBackground: true,
        emulateMediaType: 'print',
        margin: { top: '15mm', bottom: '15mm', left: '10mm', right: '10mm' },
        headerTemplate: '<div style="font-size:9px;width:100%;text-align:center;">Q1 2026 Financial Report</div>',
        footerTemplate: '<div style="font-size:9px;width:100%;text-align:center;">Page <span class="pageNumber"></span> of <span class="totalPages"></span></div>',
        displayHeaderFooter: true
      }
    })
  });

  const pdf = Buffer.from(await response.arrayBuffer());
  fs.writeFileSync('q1-report.pdf', pdf);
}

generateReport(reportHtml);

Receipt PDF — Python

Python — Generate a transaction receipt
import requests

def generate_receipt(order_id, items, total):
    html = f"""
    <html>
    <head><style>
      body {{ font-family: Inter, sans-serif; max-width: 400px; margin: 0 auto; padding: 20px; }}
      .header {{ text-align: center; border-bottom: 2px solid #333; padding-bottom: 10px; }}
      .item {{ display: flex; justify-content: space-between; padding: 4px 0; }}
      .total {{ font-weight: bold; font-size: 1.3em; border-top: 2px solid #333; padding-top: 10px; margin-top: 10px; }}
    </style></head>
    <body>
      <div class="header">
        <h2>Receipt</h2>
        <p>Order #{order_id}</p>
      </div>
      {''.join(f'<div class="item"><span>{i["name"]}</span><span>${i["price"]:.2f}</span></div>' for i in items)}
      <div class="total">
        <div class="item"><span>Total</span><span>${total:.2f}</span></div>
      </div>
    </body></html>
    """

    response = requests.post(
        "https://pdfspark.dev/api/v1/pdf/from-html",
        json={
            "html": html,
            "options": {
                "format": "A4",
                "margin": {"top": "10mm", "bottom": "10mm"},
                "printBackground": True
            }
        }
    )

    with open(f"receipt-{order_id}.pdf", "wb") as f:
        f.write(response.content)

generate_receipt("ORD-7891", [{"name": "Pro Plan", "price": 29.99}], 29.99)

Documentation Export — cURL (URL-to-PDF)

cURL — Capture a live docs page as PDF
curl -X POST "https://pdfspark.dev/api/v1/pdf/from-url" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://your-app.com/docs/getting-started",
    "options": {
      "format": "A4",
      "printBackground": true,
      "emulateMediaType": "print",
      "delay": 2000
    }
  }' \
  -o getting-started-guide.pdf

Advanced PDF Features

PDFSpark goes beyond basic HTML-to-PDF conversion. Fine-tune every aspect of your output with a comprehensive options API designed for production use.

📐

Custom Margins & Page Size

Set per-edge margins in millimeters, inches, or pixels. Choose from standard formats like A4, Letter, and Legal, or define custom width and height dimensions for non-standard document sizes like receipts or labels.

📃

Headers & Footers

Inject HTML header and footer templates that repeat on every page. Use built-in CSS classes to insert page numbers, total page count, document title, current date, and the source URL automatically.

🏷️

PDF Metadata

Set the document title, author, subject, and keywords in the PDF metadata. These properties appear in PDF readers and improve document organization for archival and search purposes.

📎

PDF Merge

Combine multiple PDFs into a single document with the /api/v1/pdf/merge endpoint. Merge cover pages with report content, append terms and conditions, or compile multi-chapter manuals from separate sources.

Frequently Asked Questions

Everything you need to know about using PDFSpark for HTML to PDF conversion in production.

What is an HTML to PDF conversion API?

An HTML to PDF conversion API is a web service that accepts HTML content (markup, CSS, and optionally JavaScript) and returns a rendered PDF document. Instead of installing native PDF libraries or headless browsers on your server, you send a POST request with your HTML and receive the PDF binary in the response. PDFSpark uses a headless Chromium browser to render the HTML, which means you get the exact same output quality as printing a page from Google Chrome. This approach eliminates dependency management, simplifies deployment, and ensures consistent rendering across all environments.

Is PDFSpark free to use for generating invoices and reports?

Yes. PDFSpark is completely free with no API keys, no account registration, and no usage tiers. You can generate invoices, reports, receipts, and any other document type without cost. The only limitation is rate limiting at 20 requests per minute per IP address, which is sufficient for most production workloads. PDFSpark is part of the SoftVoyagers open ecosystem and will remain free indefinitely.

Can I use custom fonts and branding in my PDFs?

Absolutely. Since PDFSpark renders with Chromium, it supports all Google Fonts and any web font loaded via @font-face in your CSS. Include your brand colors, logo images (as base64 or hosted URLs), and custom typography directly in the HTML template. The rendered PDF will match your browser preview pixel-for-pixel, ensuring brand consistency across all generated documents.

How do I add page numbers to my PDF documents?

Use the displayHeaderFooter, headerTemplate, and footerTemplate options. PDFSpark supports special CSS classes within these templates: <span class="pageNumber"></span> for the current page number, <span class="totalPages"></span> for the total page count, and <span class="date"></span> for the current date. Style these templates with inline CSS for full control over positioning and appearance.

What is the difference between /from-html and /from-url endpoints?

The /api/v1/pdf/from-html endpoint accepts raw HTML as a string in the request body. Use it when you generate HTML dynamically on your server, such as rendering invoice or report templates. The /api/v1/pdf/from-url endpoint accepts a URL and navigates to it with a real Chromium browser, executing JavaScript and waiting for content to load before capture. Use it when you want to convert an existing live webpage into a PDF. Both endpoints support the same rendering options for margins, page size, headers, footers, and metadata.

Can I merge multiple PDFs into one document?

Yes. The /api/v1/pdf/merge endpoint accepts an array of PDF files (as multipart form data) and combines them into a single PDF in the order provided. This is useful for assembling multi-section documents such as a cover page followed by a report, appending legal disclaimers, or compiling invoice batches into a single downloadable file. See the API documentation for the complete merge endpoint reference.

Does PDFSpark support JavaScript execution in my HTML?

Yes. PDFSpark runs a full Chromium browser that executes JavaScript before generating the PDF. This means chart libraries (Chart.js, D3.js, Highcharts), dynamic content rendering, and client-side calculations all work. Use the delay option (in milliseconds) to give JavaScript time to execute and render before capture. For single-page applications or pages that load data asynchronously, set a delay of 1000–3000ms to ensure all content is visible.

Start Converting HTML to PDF Today

Free API. No signup. No API key. Production-ready in minutes.

Try the Playground → API Documentation

Looking for alternatives? Read our wkhtmltopdf migration guide, free HTML to PDF API overview, or URL to PDF tutorial.

Part of the SoftVoyagers Ecosystem