Invoice PDF API

Generate professional invoice PDFs from any URL or HTML template. High-fidelity Chromium rendering preserves your exact invoice layout, fonts, and styling.

Start Free — 200 PDFs/month

Generating Invoice PDFs with SnapAPI

SnapAPI's PDF endpoint converts any URL to a downloadable PDF document using Chromium's print-to-PDF functionality, which produces higher-fidelity output than PDF generation libraries that render HTML themselves. The Chromium engine supports the full CSS print media specification including page-break-before, page-break-after, widows, orphans, and @page rules for margin control, allowing your invoice HTML to define exactly how it should paginate across multiple pages. Pass the invoice URL to the SnapAPI PDF endpoint and receive back a binary PDF document. For invoice generation systems where the invoice lives at a temporary URL or is generated on-the-fly from template data, encode the invoice HTML as a base64 data URI and pass it as the URL parameter to generate the PDF without requiring a publicly accessible hosting environment.

Invoice HTML Template Best Practices for PDF Generation

Designing invoice HTML templates that render correctly as PDFs requires attention to several CSS properties that affect print layout differently than screen layout. Set the page width in the CSS to match the intended PDF paper size: 210mm for A4 or 215.9mm for US Letter, and avoid fluid or percentage-based widths that would scale to the viewport rather than the paper width. Use the @media print query to hide navigation, sidebars, and interactive elements that should not appear in the PDF output. Set font sizes in points rather than pixels for print stylesheets, as the browser uses point-to-pixel conversion when printing. Avoid CSS Grid and complex flexbox layouts that some print engines render inconsistently, preferring explicit block and table layouts for invoice line item rows which render reliably across all PDF engines. Test your invoice template by printing it from Chrome to a PDF file before deploying it to verify the layout matches your expectations at the actual PDF dimensions.

# Generate invoice PDF from URL
import requests

API_KEY = "your_api_key"

def generate_invoice_pdf(invoice_url, output_path):
    resp = requests.get(
        "https://api.snapapi.pics/pdf",
        params={
            "url": invoice_url,
            "format": "A4",
            "margin_top": "10mm",
            "margin_bottom": "10mm",
            "margin_left": "15mm",
            "margin_right": "15mm",
        },
        headers={"Authorization": f"Bearer {API_KEY}"},
        timeout=30,
    )
    resp.raise_for_status()
    open(output_path, "wb").write(resp.content)
    print(f"Invoice PDF: {len(resp.content):,} bytes")
    return output_path

# Example: generate invoice for a specific order
pdf_path = generate_invoice_pdf(
    "https://yourapp.com/invoices/INV-2026-001",
    "/tmp/INV-2026-001.pdf"
)

Automated Invoice Generation Workflows

Production invoice generation workflows trigger PDF generation at specific events in your billing system: when a subscription is charged, when a one-time purchase is completed, or when an invoice is manually issued for a service. Integrate SnapAPI PDF generation into your billing webhook handler: when your payment processor sends a successful charge event, your webhook handler retrieves the invoice data from the payment processor API, renders the invoice HTML at a temporary URL or as a data URI, calls SnapAPI to generate the PDF, stores the PDF in your file storage, and emails the PDF to the customer as an attachment. For monthly recurring billing with large customer volumes, batch the PDF generation across the billing cycle rather than generating all invoices simultaneously at the billing date, which would spike your SnapAPI usage volume in a narrow window. Spread the invoice generation across the day following the billing run using a task queue with a rate-limited worker that processes invoice PDF jobs at a controlled rate.

Invoice PDF Storage and Delivery Architecture

Invoice PDFs require long-term storage because customers and accounting teams may request copies months or years after the original issue date. Store generated invoice PDFs in S3 or compatible object storage with a key structure that encodes the customer ID and invoice ID for efficient retrieval: invoices/{customer_id}/{invoice_id}.pdf. Set the S3 object's Content-Disposition header to attachment; filename=invoice.pdf so that accessing the URL triggers a download rather than browser rendering. Generate pre-signed S3 URLs with a one-hour expiration for the download link included in the invoice email, so the customer can download their invoice at the time they receive the email without the URL remaining publicly accessible indefinitely. Store the S3 object key in your invoices database table so you can regenerate the pre-signed URL on demand when a customer requests a redownload from their account portal. For compliance with tax record retention requirements, configure S3 Object Lock on the invoices bucket to prevent deletion for a minimum of seven years, matching common tax record retention obligations in most jurisdictions.

Get Started with Invoice PDF API

Register at snapapi.pics/register for a free account with two hundred PDF generation requests per month. For billing systems that issue invoices monthly, two hundred requests covers a customer base of up to two hundred customers on the free tier, with the Starter plan at nineteen dollars per month covering five thousand customers per monthly billing cycle. The SnapAPI documentation at snapapi.pics/docs includes all PDF endpoint parameters and code examples for Node.js, Python, PHP, and other languages commonly used in billing system backends.

Customizing Invoice PDF Layout for Different Paper Sizes

Invoice PDFs need to work correctly for both digital delivery and physical printing, which means the PDF must render correctly at the actual paper dimensions rather than just looking correct on screen. Configure the SnapAPI PDF endpoint's format parameter to match your target paper size: A4 (210mm by 297mm) for European markets, Letter (215.9mm by 279.4mm) for North American markets, and A5 (148mm by 210mm) for compact invoice formats. Set the margin parameters to match the printer's non-printable area: a ten to fifteen millimeter margin on all sides is standard for laser printers. For invoices with a header and footer that should appear on every page, use CSS @page with content rules to define running headers and footers rather than placing them in the document flow, allowing them to repeat correctly on multi-page invoices without manual page break management. Test the multi-page rendering by generating a sample invoice with enough line items to force a page break and verify that the header, footer, and table columns remain correctly aligned on the second and subsequent pages.

Invoice Numbering and Sequential PDF Generation

Invoice PDF generation workflows need to integrate with your billing system's invoice numbering sequence to produce sequential invoice numbers that are guaranteed unique and audit-compliant. Generate the invoice number in your application before triggering the PDF generation, storing it in your database with the customer ID, amount, and timestamp. The invoice HTML template receives the pre-assigned invoice number as a parameter and renders it in the PDF. Never generate the invoice number inside the PDF generation process because a failure in the PDF generation step could cause the number to be consumed without producing a PDF, creating a gap in your invoice sequence. For jurisdictions that require sequential invoice numbers for VAT compliance, use a database sequence or a Redis atomic counter to generate invoice numbers that are guaranteed sequential even under concurrent billing runs. Store the generated PDF's S3 key in your invoices table alongside the invoice number so you can retrieve or regenerate the PDF for any historical invoice on demand.

Invoice PDF Internationalization

Businesses that invoice customers in multiple countries need invoice PDFs that render correctly in the customer's locale, including right-to-left text for Arabic and Hebrew, currency symbols in the correct position for each locale, and date formats appropriate to the customer's country. SnapAPI's Chromium renderer supports full Unicode and international text rendering natively, making it well-suited for multilingual invoice generation. Generate the invoice HTML with the locale-specific content — translated field labels, locale-formatted numbers and dates, and the appropriate currency symbol placement — and pass it to SnapAPI. The Chromium renderer handles complex scripts, bidirectional text, and international fonts correctly without additional configuration. For invoices in Arabic or Hebrew, ensure the HTML document sets the dir=rtl attribute and the appropriate lang attribute so Chromium applies the correct bidirectional text rendering algorithm to the invoice content.

Invoice PDF Email Delivery Best Practices

Delivering invoice PDFs via email requires attention to file size, email client compatibility, and deliverability. PDF files larger than five megabytes may trigger spam filters or bounce on email servers with attachment size limits. Optimize invoice PDFs for email delivery by using JPEG format for any photographs or complex images within the invoice, compressing images to 85 percent quality, and configuring the PDF generation with print optimizations that reduce embedded font subsets to only the characters actually used in the document. For invoices that reference product images, use smaller thumbnail images sized to the actual print dimensions rather than full-resolution images scaled down by CSS, which would embed unnecessarily large image data in the PDF. Store the generated PDF in S3 and include a download link in the email body as an alternative to attaching the PDF directly, which avoids email size limits entirely and provides a durable download URL the customer can access later from their order history.