Generate PDF Invoice

Generate a professional PDF invoice with company branding, line items, and totals.

Who this is for

Finance teams and SaaS platforms use this recipe to generate a branded PDF invoice on demand. Define your company header, billing details, line items, and totals — ready to email or archive as part of your billing workflow.

Request
curl -X POST https://api.iterationlayer.com/document-generation/v1/generate \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "format": "pdf",
    "document": {
      "metadata": {
        "title": "Invoice #2026-0142",
        "author": "Acme Consulting LLC"
      },
      "page": {
        "size": { "preset": "A4" },
        "margins": {
          "top_in_pt": 72,
          "right_in_pt": 72,
          "bottom_in_pt": 72,
          "left_in_pt": 72
        }
      },
      "styles": {
        "text": {
          "font_family": "Helvetica",
          "font_size_in_pt": 11.0,
          "line_height": 1.5,
          "color": "#333333"
        },
        "headline": {
          "font_family": "Helvetica",
          "font_size_in_pt": 24.0,
          "color": "#111111",
          "spacing_before_in_pt": 12.0,
          "spacing_after_in_pt": 6.0,
          "is_bold": true
        },
        "link": {
          "color": "#0066CC",
          "is_underlined": true
        },
        "list": {
          "text_style": {
            "font_family": "Helvetica",
            "font_size_in_pt": 11.0,
            "line_height": 1.5,
            "color": "#333333"
          },
          "marker_color": "#333333",
          "marker_gap_in_pt": 8.0
        },
        "table": {
          "header": {
            "background_color": "#333333",
            "text_color": "#FFFFFF",
            "font_size_in_pt": 11.0,
            "is_bold": true
          },
          "body": {
            "background_color": "#FFFFFF",
            "text_color": "#333333",
            "font_size_in_pt": 11.0
          },
          "border": {
            "outer": {
              "top": { "color": "#CCCCCC", "width_in_pt": 1.0 },
              "right": { "color": "#CCCCCC", "width_in_pt": 1.0 },
              "bottom": { "color": "#CCCCCC", "width_in_pt": 1.0 },
              "left": { "color": "#CCCCCC", "width_in_pt": 1.0 }
            },
            "inner": {
              "horizontal": { "color": "#EEEEEE", "width_in_pt": 0.5 },
              "vertical": { "color": "#EEEEEE", "width_in_pt": 0.5 }
            }
          }
        },
        "grid": {
          "background_color": "#FFFFFF",
          "border_color": "#CCCCCC",
          "border_width_in_pt": 0.0,
          "gap_in_pt": 12.0
        },
        "separator": {
          "color": "#CCCCCC",
          "thickness_in_pt": 1.0,
          "spacing_before_in_pt": 12.0,
          "spacing_after_in_pt": 12.0
        },
        "image": {
          "border_color": "#000000",
          "border_width_in_pt": 0.0
        }
      },
      "footer": [
        {
          "type": "paragraph",
          "runs": [{
            "text": "Acme Consulting LLC · 742 Evergreen Terrace, Suite 300, Austin, TX 78701 · acme-consulting.com"
          }]
        }
      ],
      "content": [
        {
          "type": "grid",
          "columns": [
            {
              "column_span": 6,
              "blocks": [
                { "type": "headline", "level": "h1", "text": "Acme Consulting" },
                { "type": "paragraph", "runs": [{ "text": "742 Evergreen Terrace, Suite 300\nAustin, TX 78701\nhello@acme-consulting.com" }] }
              ]
            },
            {
              "column_span": 6,
              "blocks": [
                { "type": "headline", "level": "h2", "text": "INVOICE" },
                { "type": "paragraph", "runs": [
                  { "text": "Invoice #: ", "is_bold": true },
                  { "text": "2026-0142\n" },
                  { "text": "Date: ", "is_bold": true },
                  { "text": "March 1, 2026\n" },
                  { "text": "Due Date: ", "is_bold": true },
                  { "text": "March 31, 2026" }
                ] }
              ]
            }
          ]
        },
        { "type": "separator" },
        { "type": "headline", "level": "h3", "text": "Bill To" },
        { "type": "paragraph", "runs": [
          { "text": "Northwind Industries\n", "is_bold": true },
          { "text": "Attn: Sarah Chen, VP of Operations\n1200 Industrial Blvd, Denver, CO 80202\nsarah.chen@northwind.com" }
        ] },
        { "type": "separator" },
        {
          "type": "table",
          "column_widths_in_percent": [40, 15, 20, 25],
          "header": {
            "cells": [
              { "text": "Description" },
              { "text": "Qty", "horizontal_alignment": "center" },
              { "text": "Unit Price", "horizontal_alignment": "right" },
              { "text": "Amount", "horizontal_alignment": "right" }
            ]
          },
          "rows": [
            { "cells": [
              { "text": "Brand Strategy Workshop (2 days)" },
              { "text": "1", "horizontal_alignment": "center" },
              { "text": "$8,500.00", "horizontal_alignment": "right" },
              { "text": "$8,500.00", "horizontal_alignment": "right" }
            ] },
            { "cells": [
              { "text": "UI/UX Design Sprint (5 days)" },
              { "text": "1", "horizontal_alignment": "center" },
              { "text": "$15,000.00", "horizontal_alignment": "right" },
              { "text": "$15,000.00", "horizontal_alignment": "right" }
            ] },
            { "cells": [
              { "text": "Frontend Development" },
              { "text": "120", "horizontal_alignment": "center" },
              { "text": "$175.00", "horizontal_alignment": "right" },
              { "text": "$21,000.00", "horizontal_alignment": "right" }
            ] },
            { "cells": [
              { "text": "QA & User Acceptance Testing" },
              { "text": "40", "horizontal_alignment": "center" },
              { "text": "$150.00", "horizontal_alignment": "right" },
              { "text": "$6,000.00", "horizontal_alignment": "right" }
            ] }
          ]
        },
        { "type": "separator" },
        {
          "type": "grid",
          "columns": [
            { "column_span": 6, "blocks": [] },
            {
              "column_span": 6,
              "blocks": [
                { "type": "paragraph", "runs": [
                  { "text": "Subtotal: ", "is_bold": true },
                  { "text": "$50,500.00\n" },
                  { "text": "Tax (8.25%): ", "is_bold": true },
                  { "text": "$4,166.25\n" },
                  { "text": "Total Due: ", "is_bold": true },
                  { "text": "$54,666.25" }
                ] }
              ]
            }
          ]
        },
        { "type": "separator" },
        { "type": "paragraph", "runs": [
          { "text": "Payment Terms: ", "is_bold": true },
          { "text": "Net 30. Please remit payment via wire transfer to Acme Consulting LLC, Account #4821-7390-5512, Routing #021000021." }
        ] }
      ]
    }
  }'
Response
{
  "success": true,
  "data": {
    "buffer": "JVBERi0xLjcKMSAwIG9iago8...",
    "mime_type": "application/pdf"
  }
}
Request
import { IterationLayer } from "iterationlayer";
const client = new IterationLayer({ apiKey: "YOUR_API_KEY" });

const result = await client.generateDocument({
  format: "pdf",
  document: {
    metadata: {
      title: "Invoice #2026-0142",
      author: "Acme Consulting LLC",
    },
    page: {
      size: { preset: "A4" },
      margins: {
        top_in_pt: 72,
        right_in_pt: 72,
        bottom_in_pt: 72,
        left_in_pt: 72,
      },
    },
    styles: {
      text: {
        font_family: "Helvetica",
        font_size_in_pt: 11.0,
        line_height: 1.5,
        color: "#333333",
      },
      headline: {
        font_family: "Helvetica",
        font_size_in_pt: 24.0,
        color: "#111111",
        spacing_before_in_pt: 12.0,
        spacing_after_in_pt: 6.0,
        is_bold: true,
      },
      link: {
        color: "#0066CC",
        is_underlined: true,
      },
      list: {
        text_style: {
          font_family: "Helvetica",
          font_size_in_pt: 11.0,
          line_height: 1.5,
          color: "#333333",
        },
        marker_color: "#333333",
        marker_gap_in_pt: 8.0,
      },
      table: {
        header: {
          background_color: "#333333",
          text_color: "#FFFFFF",
          font_size_in_pt: 11.0,
          is_bold: true,
        },
        body: {
          background_color: "#FFFFFF",
          text_color: "#333333",
          font_size_in_pt: 11.0,
        },
        border: {
          outer: {
            top: { color: "#CCCCCC", width_in_pt: 1.0 },
            right: { color: "#CCCCCC", width_in_pt: 1.0 },
            bottom: { color: "#CCCCCC", width_in_pt: 1.0 },
            left: { color: "#CCCCCC", width_in_pt: 1.0 },
          },
          inner: {
            horizontal: { color: "#EEEEEE", width_in_pt: 0.5 },
            vertical: { color: "#EEEEEE", width_in_pt: 0.5 },
          },
        },
      },
      grid: {
        background_color: "#FFFFFF",
        border_color: "#CCCCCC",
        border_width_in_pt: 0.0,
        gap_in_pt: 12.0,
      },
      separator: {
        color: "#CCCCCC",
        thickness_in_pt: 1.0,
        spacing_before_in_pt: 12.0,
        spacing_after_in_pt: 12.0,
      },
      image: {
        border_color: "#000000",
        border_width_in_pt: 0.0,
      },
    },
    footer: [
      {
        type: "paragraph",
        runs: [{
          text: "Acme Consulting LLC · 742 Evergreen Terrace, Suite 300, Austin, TX 78701 · acme-consulting.com",
        }],
      },
    ],
    content: [
      {
        type: "grid",
        columns: [
          {
            column_span: 6,
            blocks: [
              { type: "headline", level: "h1", text: "Acme Consulting" },
              { type: "paragraph", runs: [{ text: "742 Evergreen Terrace, Suite 300\nAustin, TX 78701\nhello@acme-consulting.com" }] },
            ],
          },
          {
            column_span: 6,
            blocks: [
              { type: "headline", level: "h2", text: "INVOICE" },
              { type: "paragraph", runs: [
                { text: "Invoice #: ", is_bold: true },
                { text: "2026-0142\n" },
                { text: "Date: ", is_bold: true },
                { text: "March 1, 2026\n" },
                { text: "Due Date: ", is_bold: true },
                { text: "March 31, 2026" },
              ] },
            ],
          },
        ],
      },
      { type: "separator" },
      { type: "headline", level: "h3", text: "Bill To" },
      { type: "paragraph", runs: [
        { text: "Northwind Industries\n", is_bold: true },
        { text: "Attn: Sarah Chen, VP of Operations\n1200 Industrial Blvd, Denver, CO 80202\nsarah.chen@northwind.com" },
      ] },
      { type: "separator" },
      {
        type: "table",
        column_widths_in_percent: [40, 15, 20, 25],
        header: {
          cells: [
            { text: "Description" },
            { text: "Qty", horizontal_alignment: "center" },
            { text: "Unit Price", horizontal_alignment: "right" },
            { text: "Amount", horizontal_alignment: "right" },
          ],
        },
        rows: [
          { cells: [
            { text: "Brand Strategy Workshop (2 days)" },
            { text: "1", horizontal_alignment: "center" },
            { text: "$8,500.00", horizontal_alignment: "right" },
            { text: "$8,500.00", horizontal_alignment: "right" },
          ] },
          { cells: [
            { text: "UI/UX Design Sprint (5 days)" },
            { text: "1", horizontal_alignment: "center" },
            { text: "$15,000.00", horizontal_alignment: "right" },
            { text: "$15,000.00", horizontal_alignment: "right" },
          ] },
          { cells: [
            { text: "Frontend Development" },
            { text: "120", horizontal_alignment: "center" },
            { text: "$175.00", horizontal_alignment: "right" },
            { text: "$21,000.00", horizontal_alignment: "right" },
          ] },
          { cells: [
            { text: "QA & User Acceptance Testing" },
            { text: "40", horizontal_alignment: "center" },
            { text: "$150.00", horizontal_alignment: "right" },
            { text: "$6,000.00", horizontal_alignment: "right" },
          ] },
        ],
      },
      { type: "separator" },
      {
        type: "grid",
        columns: [
          { column_span: 6, blocks: [] },
          {
            column_span: 6,
            blocks: [
              { type: "paragraph", runs: [
                { text: "Subtotal: ", is_bold: true },
                { text: "$50,500.00\n" },
                { text: "Tax (8.25%): ", is_bold: true },
                { text: "$4,166.25\n" },
                { text: "Total Due: ", is_bold: true },
                { text: "$54,666.25" },
              ] },
            ],
          },
        ],
      },
      { type: "separator" },
      { type: "paragraph", runs: [
        { text: "Payment Terms: ", is_bold: true },
        { text: "Net 30. Please remit payment via wire transfer to Acme Consulting LLC, Account #4821-7390-5512, Routing #021000021." },
      ] },
    ],
  },
});

await Bun.write("invoice-2026-0142.pdf", Buffer.from(result.data.buffer, "base64"));
Response
{
  "success": true,
  "data": {
    "buffer": "JVBERi0xLjcKMSAwIG9iago8...",
    "mime_type": "application/pdf"
  }
}
Request
import base64

from iterationlayer import IterationLayer
client = IterationLayer(api_key="YOUR_API_KEY")

result = client.generate_document(
    format="pdf",
    document={
        "metadata": {
            "title": "Invoice #2026-0142",
            "author": "Acme Consulting LLC",
        },
        "page": {
            "size": {"preset": "A4"},
            "margins": {
                "top_in_pt": 72,
                "right_in_pt": 72,
                "bottom_in_pt": 72,
                "left_in_pt": 72,
            },
        },
        "styles": {
            "text": {
                "font_family": "Helvetica",
                "font_size_in_pt": 11.0,
                "line_height": 1.5,
                "color": "#333333",
            },
            "headline": {
                "font_family": "Helvetica",
                "font_size_in_pt": 24.0,
                "color": "#111111",
                "spacing_before_in_pt": 12.0,
                "spacing_after_in_pt": 6.0,
                "is_bold": True,
            },
            "link": {
                "color": "#0066CC",
                "is_underlined": True,
            },
            "list": {
                "text_style": {
                    "font_family": "Helvetica",
                    "font_size_in_pt": 11.0,
                    "line_height": 1.5,
                    "color": "#333333",
                },
                "marker_color": "#333333",
                "marker_gap_in_pt": 8.0,
            },
            "table": {
                "header": {
                    "background_color": "#333333",
                    "text_color": "#FFFFFF",
                    "font_size_in_pt": 11.0,
                    "is_bold": True,
                },
                "body": {
                    "background_color": "#FFFFFF",
                    "text_color": "#333333",
                    "font_size_in_pt": 11.0,
                },
                "border": {
                    "outer": {
                        "top": {"color": "#CCCCCC", "width_in_pt": 1.0},
                        "right": {"color": "#CCCCCC", "width_in_pt": 1.0},
                        "bottom": {"color": "#CCCCCC", "width_in_pt": 1.0},
                        "left": {"color": "#CCCCCC", "width_in_pt": 1.0},
                    },
                    "inner": {
                        "horizontal": {"color": "#EEEEEE", "width_in_pt": 0.5},
                        "vertical": {"color": "#EEEEEE", "width_in_pt": 0.5},
                    },
                },
            },
            "grid": {
                "background_color": "#FFFFFF",
                "border_color": "#CCCCCC",
                "border_width_in_pt": 0.0,
                "gap_in_pt": 12.0,
            },
            "separator": {
                "color": "#CCCCCC",
                "thickness_in_pt": 1.0,
                "spacing_before_in_pt": 12.0,
                "spacing_after_in_pt": 12.0,
            },
            "image": {
                "border_color": "#000000",
                "border_width_in_pt": 0.0,
            },
        },
        "footer": [
            {
                "type": "paragraph",
                "runs": [{
                    "text": "Acme Consulting LLC · 742 Evergreen Terrace, Suite 300, Austin, TX 78701 · acme-consulting.com",
                }],
            },
        ],
        "content": [
            {
                "type": "grid",
                "columns": [
                    {
                        "column_span": 6,
                        "blocks": [
                            {"type": "headline", "level": "h1", "text": "Acme Consulting"},
                            {"type": "paragraph", "runs": [{"text": "742 Evergreen Terrace, Suite 300\nAustin, TX 78701\nhello@acme-consulting.com"}]},
                        ],
                    },
                    {
                        "column_span": 6,
                        "blocks": [
                            {"type": "headline", "level": "h2", "text": "INVOICE"},
                            {"type": "paragraph", "runs": [
                                {"text": "Invoice #: ", "is_bold": True},
                                {"text": "2026-0142\n"},
                                {"text": "Date: ", "is_bold": True},
                                {"text": "March 1, 2026\n"},
                                {"text": "Due Date: ", "is_bold": True},
                                {"text": "March 31, 2026"},
                            ]},
                        ],
                    },
                ],
            },
            {"type": "separator"},
            {"type": "headline", "level": "h3", "text": "Bill To"},
            {"type": "paragraph", "runs": [
                {"text": "Northwind Industries\n", "is_bold": True},
                {"text": "Attn: Sarah Chen, VP of Operations\n1200 Industrial Blvd, Denver, CO 80202\nsarah.chen@northwind.com"},
            ]},
            {"type": "separator"},
            {
                "type": "table",
                "column_widths_in_percent": [40, 15, 20, 25],
                "header": {
                    "cells": [
                        {"text": "Description"},
                        {"text": "Qty", "horizontal_alignment": "center"},
                        {"text": "Unit Price", "horizontal_alignment": "right"},
                        {"text": "Amount", "horizontal_alignment": "right"},
                    ],
                },
                "rows": [
                    {"cells": [
                        {"text": "Brand Strategy Workshop (2 days)"},
                        {"text": "1", "horizontal_alignment": "center"},
                        {"text": "$8,500.00", "horizontal_alignment": "right"},
                        {"text": "$8,500.00", "horizontal_alignment": "right"},
                    ]},
                    {"cells": [
                        {"text": "UI/UX Design Sprint (5 days)"},
                        {"text": "1", "horizontal_alignment": "center"},
                        {"text": "$15,000.00", "horizontal_alignment": "right"},
                        {"text": "$15,000.00", "horizontal_alignment": "right"},
                    ]},
                    {"cells": [
                        {"text": "Frontend Development"},
                        {"text": "120", "horizontal_alignment": "center"},
                        {"text": "$175.00", "horizontal_alignment": "right"},
                        {"text": "$21,000.00", "horizontal_alignment": "right"},
                    ]},
                    {"cells": [
                        {"text": "QA & User Acceptance Testing"},
                        {"text": "40", "horizontal_alignment": "center"},
                        {"text": "$150.00", "horizontal_alignment": "right"},
                        {"text": "$6,000.00", "horizontal_alignment": "right"},
                    ]},
                ],
            },
            {"type": "separator"},
            {
                "type": "grid",
                "columns": [
                    {"column_span": 6, "blocks": []},
                    {
                        "column_span": 6,
                        "blocks": [
                            {"type": "paragraph", "runs": [
                                {"text": "Subtotal: ", "is_bold": True},
                                {"text": "$50,500.00\n"},
                                {"text": "Tax (8.25%): ", "is_bold": True},
                                {"text": "$4,166.25\n"},
                                {"text": "Total Due: ", "is_bold": True},
                                {"text": "$54,666.25"},
                            ]},
                        ],
                    },
                ],
            },
            {"type": "separator"},
            {"type": "paragraph", "runs": [
                {"text": "Payment Terms: ", "is_bold": True},
                {"text": "Net 30. Please remit payment via wire transfer to Acme Consulting LLC, Account #4821-7390-5512, Routing #021000021."},
            ]},
        ],
    },
)

with open("invoice-2026-0142.pdf", "wb") as f:
    f.write(base64.b64decode(result["data"]["buffer"]))
Response
{
  "success": true,
  "data": {
    "buffer": "JVBERi0xLjcKMSAwIG9iago8...",
    "mime_type": "application/pdf"
  }
}
Request
package main

import (
    "encoding/base64"
    "os"

    il "github.com/iterationlayer/sdk-go"
)

func main() {
    client := il.NewClient("YOUR_API_KEY")

    result, err := client.GenerateDocument(il.GenerateDocumentRequest{
        Format: "pdf",
        Document: il.DocumentDefinition{
            Metadata: il.DocumentMetadata{
                Title:  "Invoice #2026-0142",
                Author: "Acme Consulting LLC",
            },
            Page: il.PageConfig{
                Size:    il.PageSize{Preset: "A4"},
                Margins: il.Margins{TopInPt: 72, RightInPt: 72, BottomInPt: 72, LeftInPt: 72},
            },
            Content: []il.ContentBlock{
                il.NewHeadlineBlock("h1", "Acme Consulting"),
                il.NewSeparatorBlock(),
                il.NewHeadlineBlock("h3", "Bill To"),
                il.ParagraphBlock{Type: "paragraph", Markdown: "**Northwind Industries**\nAttn: Sarah Chen, VP of Operations"},
                il.NewSeparatorBlock(),
                il.NewTableBlock([]il.TableRow{
                    {Cells: []il.TableCell{{Text: "Brand Strategy Workshop (2 days)"}, {Text: "$8,500.00"}}},
                    {Cells: []il.TableCell{{Text: "UI/UX Design Sprint (5 days)"}, {Text: "$15,000.00"}}},
                    {Cells: []il.TableCell{{Text: "Frontend Development"}, {Text: "$21,000.00"}}},
                    {Cells: []il.TableCell{{Text: "QA & User Acceptance Testing"}, {Text: "$6,000.00"}}},
                }),
                il.NewSeparatorBlock(),
                il.ParagraphBlock{Type: "paragraph", Markdown: "**Total Due:** $54,666.25"},
            },
        },
    })
    if err != nil {
        panic(err)
    }

    decoded, _ := base64.StdEncoding.DecodeString(result.Data.Buffer)
    os.WriteFile("invoice-2026-0142.pdf", decoded, 0644)
}
Response
{
  "success": true,
  "data": {
    "buffer": "JVBERi0xLjcKMSAwIG9iago8...",
    "mime_type": "application/pdf"
  }
}

Related Recipes

Start building in minutes

Free trial credits included. No credit card required.