Skip to content

Invoices are one of the most common document types developers need to generate programmatically. Traditionally, this means building HTML templates, wiring up a PDF library, and writing code to inject data. With PdfBroker.io's MCP server, you describe what you want and the AI agent handles the rest — HTML generation, CSS styling, and PDF rendering.

This tutorial walks through the complete workflow: from a simple chat prompt to a production-ready, PDF/A-compliant invoice.

Prerequisites

  • PdfBroker.io MCP server connected to your AI client (see the setup guide)
  • A paid PdfBroker.io plan (Starter or above) for WeasyPrint access — the free tier supports wkhtmltopdf only

Step 1: A Simple Invoice

Start with a plain language description. The AI agent generates the HTML, calls the html_to_pdf tool, and returns a download link.

Prompt:

Create a PDF invoice from Acme Consulting AB to Client Corp Ltd. Invoice number INV-2026-042, dated April 3, 2026, due in 30 days. Three line items: Strategy workshop (2 days at €1,500/day), Technical review (8 hours at €180/hour), and Travel expenses (€340 flat). Add 25% VAT. Use A4 paper with the html_to_pdf tool.

What the AI does:

  1. Generates a complete HTML document with an invoice layout — company details, client details, line item table, subtotal, VAT, and total
  2. Adds CSS for print-friendly styling — clean typography, proper table formatting, page margins
  3. Calls html_to_pdf with paperSize: "A4"
  4. Returns something like: "PDF generated successfully (22 KB). Download: https://mcp.pdfbroker.io/download/a1b2c3d4e5f6 (link expires in 30 minutes)."

Click the download link to get your invoice.

Step 2: Refining the Design

The first attempt will produce a functional invoice. Now refine it:

Make the invoice header dark blue (#1a365d) with white text. Add a horizontal rule below the header. Right-align the amounts column. Make the total row bold with a top border. Add payment terms at the bottom: "Payment via bank transfer to Nordea IBAN SE12 3456 7890 1234, BIC NDEASESS."

The AI modifies the HTML and regenerates. Each iteration takes seconds.

More refinements you can request:

  • "Add a company logo — here's the base64 PNG: data:image/png;base64,..."
  • "Add page numbers at the bottom center"
  • "Use the font Inter for headings and system-ui for body text"
  • "Make the layout match this style: clean, minimal, lots of whitespace"

Step 3: Adding PDF/A Compliance

For invoices that need to be archived or meet regulatory requirements:

Regenerate the invoice with PdfA1b conformance level for long-term archival.

The AI calls html_to_pdf with conformanceLevel: "PdfA1b". The resulting PDF embeds all fonts and conforms to the PDF/A-1b standard — suitable for tax records, legal archives, and regulatory submissions.

For accessibility compliance (required by the European Accessibility Act for certain organizations):

Use PdfUA1 conformance level instead, and make sure the HTML uses semantic elements — proper heading hierarchy, table headers with scope attributes, and a lang attribute on the html element.

Step 4: Multi-Currency and Localization

AI agents handle localization naturally:

Create the same invoice but in Swedish. Use SEK currency, Swedish date format, and include "Betalningsvillkor: 30 dagar netto" as the payment terms. Apply 25% moms.

Or mixed currency:

Create an invoice in English with amounts in USD. Convert the EUR amounts from the previous invoice at 1.08 USD/EUR.

Step 5: Batch Generation with a Template

Once you have an invoice design you like, you can use it as a template for batch generation. Ask the AI to extract the pattern:

Take the HTML from the last invoice and create a reusable version. Replace the dynamic values (invoice number, date, client name, line items, amounts) with clear placeholder markers. Show me the template.

Then for each new invoice:

Using the invoice template, generate an invoice for:

  • Client: TechStart GmbH, Friedrichstraße 123, Berlin
  • Invoice: INV-2026-043, dated today, net 14 days
  • Items: API integration (40h at €140/h), Documentation (8h at €120/h)
  • VAT: 19% (German rate)
  • Use PdfA1b conformance

Step 6: Multi-Page Invoices with Page Numbers

For invoices with many line items, WeasyPrint's CSS Paged Media handles pagination automatically. Prompt the AI to use it:

The invoice may span multiple pages. Add headers and footers using CSS @page margin boxes: the company name in the top-left corner of every page, and "Page X of Y" in the bottom-right. The line items table should not break inside a row — use page-break-inside: avoid on table rows.

The AI generates CSS like:

@page {
  margin: 2cm;
  @top-left { content: "Acme Consulting AB"; font-size: 9pt; color: #666; }
  @bottom-right { content: "Page " counter(page) " of " counter(pages); font-size: 9pt; }
}
tr { page-break-inside: avoid; }

This is the advantage of the WeasyPrint engine — CSS Paged Media features that html_to_pdf_wk (wkhtmltopdf) doesn't support.

Step 7: Programmatic Integration

If you want to integrate this workflow into your own application rather than generating invoices from chat, you can call PdfBroker.io's MCP server programmatically.

Using C# with the MCP C# SDK

using ModelContextProtocol.Client;

var transport = new HttpClientTransport(new HttpClientTransportOptions
{
    Endpoint = new Uri("https://mcp.pdfbroker.io/"),
    Headers = new Dictionary<string, string>
    {
        ["X-PdfBroker-ClientId"] = clientId,
        ["X-PdfBroker-ClientSecret"] = clientSecret
    }
});

var mcpClient = await McpClient.CreateAsync(transport);

// Generate invoice HTML (from your template engine or AI)
var invoiceHtml = BuildInvoiceHtml(order);

var result = await mcpClient.CallToolAsync("html_to_pdf", new Dictionary<string, object?>
{
    ["html"] = invoiceHtml,
    ["conformanceLevel"] = "PdfA1b",
    ["paperSize"] = "A4"
});

var response = result.Content.OfType<TextContentBlock>().First().Text;
// "PDF generated successfully (24 KB). Download: https://mcp.pdfbroker.io/download/..."

Using cURL

curl -X POST https://mcp.pdfbroker.io/ \
  -H "Content-Type: application/json" \
  -H "X-PdfBroker-ClientId: YOUR_CLIENT_ID" \
  -H "X-PdfBroker-ClientSecret: YOUR_CLIENT_SECRET" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/call",
    "params": {
      "name": "html_to_pdf",
      "arguments": {
        "html": "<!DOCTYPE html><html><head><style>body{font-family:system-ui;margin:2cm}table{width:100%;border-collapse:collapse}th,td{padding:8px;text-align:left;border-bottom:1px solid #ddd}th{background:#1a365d;color:white}.total{font-weight:bold;font-size:1.2em}</style></head><body><h1>Invoice INV-2026-042</h1><table><thead><tr><th>Description</th><th>Amount</th></tr></thead><tbody><tr><td>Consulting</td><td>€3,000</td></tr><tr><td>Development</td><td>€1,440</td></tr></tbody><tfoot><tr class=\"total\"><td>Total (incl. 25% VAT)</td><td>€5,550</td></tr></tfoot></table></body></html>",
        "conformanceLevel": "PdfA1b",
        "paperSize": "A4"
      }
    }
  }'

Tips for Production Invoice Workflows

Consistency. Once you have a design you like, save the HTML template in your codebase. Use the AI for generating content and data injection, not for re-designing the layout each time.

Compliance. Use PdfA1b for tax and archival requirements. Use PdfUA1 if your invoices need to be accessible. Both are available through the html_to_pdf tool.

Number formatting. Be explicit about currency formatting in your prompt. "€1,500.00" vs "1.500,00 €" depends on locale — tell the AI which convention to use.

Sequential invoice numbers. The AI can generate invoice numbers, but for production systems, generate them in your application logic to guarantee uniqueness and sequential ordering.

Base64 images. If you need a company logo, convert it to a base64 data URI and include it in the prompt or template. WeasyPrint renders inline base64 images without needing network access.

What's Next