Skip to content
Bitavu

PDF TEMPLATES

Generate a multi-page PDF from JSON

Turn an array of invoice lines into a table that flows across pages. Use the same saved Bitavu template for a three-line invoice and a 100-line invoice, with repeated column headings and a total after the last row.

Examples use fictional invoice data.

Read the guide

Download the test invoices

Start with three rows to check your bindings. Then use 100 rows to exercise page breaks. The longer invoice numbers every description from 001 to 100, so you can trace rows across pages and catch gaps or duplicates. These page counts come from the tested A4 layout.

Line itemsPagesFiles
31
1007

Set up the invoice template

Open the Studio invoice starter in Bitavu Studio. The starter already has a repeating table, document totals and page numbers. If you’re adapting another template, use the same three parts in its layer tree.

  1. Put the table in Body

    Keep Repeating line items in the body’s flow layout so rows can continue onto the next page. Set its array binding to items and enable repeating column headings in the table settings.

  2. Keep the total below the table

    Place Invoice total and Payment note after the table in Body. Their positions follow the last row as the table grows. The starter’s total sums quantity × unit price across the complete input array.

  3. Put the page number in Footer

    Use the footer for content that should appear on every page. The starter’s page-number layer uses Page {{page}} of {{totalPages}}.

In the Studio invoice layer tree, the table and total sit in Body. The repeating page number sits in Footer.

Match JSON to the table

The downloaded JSON has four top-level keys. The invoice heading reads invoice.number, invoice.date and invoice.due. The Bill to block reads client.name and client.address. The payment note reads notes. The table reads one object from items for each row, in the order supplied.

Inside a table cell, bind to a field of the current item, such as {{description}}. In the template’s input contract, the corresponding path is items[].description. Use JSON numbers for quantity and unit price so the template can calculate the row amount.

Table bindings in Studio invoice
Description{{description}}
items[].description · Text
Qty{{quantity}}
items[].quantity · Number
Unit price{{unitPrice|money}}
items[].unitPrice · Number
Amount{{quantity|multiply:unitPrice}}
Calculated from the row · Number

When mapping records from a spreadsheet or an API, build one object per invoice and group all its lines into items. Convert quantity and unit price to numbers upstream, and sort the items before sending them if row order matters.

Test page breaks in Studio

In the editor, open Sample data → Edit data and start with invoice-short.json. Use Test & preview to verify that the three rows, customer and dates appear. Swap in invoice-100-lines.json and open the generated PDF.

In the reference PDF, row 012 ends page 1 and row 013 starts page 2 under the repeated column headings.
  • First break. Note the last row on page 1 and verify that the following row starts page 2.
  • Last page. Find row 100 and confirm that the total appears once after the items. Check that the last footer shows the full page count.
  • Realistic line length. In a copy of the sample data, give a row near a page break a long description. Preview again and check that the description fits and all rows are still present. Fonts, column widths and margins can all move page breaks.

Generate the PDF from JSON

  1. Save and select the tested revision

    In Studio, save a version and open Use in your app. Copy the template ID and numeric revision into BITAVU_TEMPLATE_ID and BITAVU_REVISION. Pin that revision so the API uses the layout you checked while the input changes.

  2. Use a server-side API key

    In Integrations → API keys, create a key with access to the invoice template and the Generate PDFs permission. Set it as BITAVU_API_KEY in your server or secret store.

  3. Run the render request

    From a shell with jq and curl, run this where you saved the sample JSON. The request wraps the invoice under data and the response saves as invoice-100-lines.pdf.

input=invoice-100-lines.json
output="${input%.json}"

jq -e --arg id "$BITAVU_TEMPLATE_ID" --argjson revision "$BITAVU_REVISION" \
  '{templateId: $id, revision: $revision, data: .}' "$input" > "$output.request.json" &&
curl --fail --silent --show-error https://api.bitavu.com/v1/render \
  --header "Authorization: Bearer $BITAVU_API_KEY" \
  --header 'Content-Type: application/json' \
  --header 'Accept: application/pdf' \
  --data-binary @"$output.request.json" \
  --dump-header "$output.headers.txt" \
  --output "$output.pdf"

Run it again with input=invoice-short.json to save the other PDF. In the saved response headers, check Content-Type: application/pdf, X-Bitavu-Revision and X-Bitavu-Pages. Keep X-Bitavu-Request-Id for support if the render fails.

For application code, follow the Node.js guide or the C# guide. When retrying a render job with an Idempotency-Key, reuse the key with the same request body and give each new invoice operation its own key.

Troubleshoot pagination and data

Rows stop or overlap

Check that the table is a flow element in Body. Inspect any fixed-height frame around it and try the 100-line sample again.

Column headings disappear

Enable the table’s repeated column headings. The document header and the table’s column headings are configured separately.

The total repeats

Move the total to Body immediately after the table so it follows the last row. Keep page numbering in Footer.

HTTP 422 for input data

Check the returned field path against the saved revision’s bindings. For example, items[].quantity expects a JSON number. Check that each line supplies the required fields.

API output differs from preview

Check X-Bitavu-Revision against the revision you tested. Try the same input in both places and compare the row at the first page break.

See the same invoices rendered with Puppeteer to compare how each approach handles pagination and what your team needs to run in production.

← All support guides