Guides / Generate PDFs from Airtable

No-code · Updated 2026-12-03

Generate PDFs from Airtable

This guide turns an Airtable record into a finished PDF and puts the file back into the record's attachment field. A short script in an Airtable automation does the work: it reads the record and its linked line items, sends them to DevilPDF, and writes the returned link into the attachment field. Airtable then fetches and stores the file itself.

The example is an invoice, but the same pattern produces quotes, receipts, packing slips and certificates.

#What you need

  • An Airtable plan that includes automations with the Run a script action.
  • A DevilPDF API key. Sign up, open API keys and create one. It starts with dp_live_. The free plan includes 500 documents a month.

#The base

Two tables:

Invoices

FieldType
NumberSingle line text
CustomerSingle line text
Customer addressLong text
Issue dateDate
Line itemsLink to Line items
StatusSingle select: Draft, Ready, Sent
PDFAttachment

Line items

FieldType
NameSingle line text
QuantityNumber
Unit priceCurrency

No formula fields for totals are needed. The invoice template adds up quantity × unit_price, applies tax, and prints the subtotal and total.

#1. Create the automation

  1. Open Automations and create one.
  2. Trigger: When a record matches conditions. Table Invoices, condition Status is Ready.
  3. Action: Run a script.
  4. In the script editor's left panel, under Input variables, add a variable named recordId and set its value to the trigger record's Airtable record ID.

#2. The script

Paste this into the script editor and put your key on the first line.

Run a script
const DEVILPDF_API_KEY = "dp_live_..."; // see the note on keys below

const { recordId } = input.config();
const invoices = base.getTable("Invoices");
const lineItems = base.getTable("Line items");

// Load the invoice and its linked line items.
const invoice = await invoices.selectRecordAsync(recordId);
if (!invoice) throw new Error(`Invoice ${recordId} not found`);

const links = invoice.getCellValue("Line items") ?? [];
const lines = await lineItems.selectRecordsAsync({
  fields: ["Name", "Quantity", "Unit price"],
  recordIds: links.map((link) => link.id),
});

const items = lines.records.map((line) => ({
  name: line.getCellValueAsString("Name"),
  quantity: line.getCellValue("Quantity") ?? 1,
  unit_price: line.getCellValue("Unit price") ?? 0,
}));

// Render the PDF.
const number = invoice.getCellValueAsString("Number");
const res = await fetch("https://devilpdf.com/v1/render", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${DEVILPDF_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    template: "invoice",
    filename: `invoice-${number}`,
    data: {
      number,
      issue_date: invoice.getCellValue("Issue date"), // a date field returns "2026-12-03"
      company: { name: "Northwind Studio", address: "410 Bay Street\nToronto, ON M5H 2Y4" },
      customer: {
        name: invoice.getCellValueAsString("Customer"),
        address: invoice.getCellValueAsString("Customer address"),
      },
      items,
      tax_rate: 13,
      tax_label: "HST",
    },
  }),
});

const doc = await res.json();
if (!res.ok) throw new Error(`DevilPDF: ${doc.error.message}`);

// Attach the PDF to the record and mark it sent.
await invoices.updateRecordAsync(recordId, {
  "PDF": [{ url: doc.url, filename: doc.filename }],
  "Status": { name: "Sent" },
});

output.set("pdfUrl", doc.url);

Click Test with a record set to Ready. The PDF appears in the record's PDF field within a few seconds.

How it works:

  • An attachment field accepts a list of objects with a url (and an optional filename). Airtable downloads the file from that URL and keeps its own copy, so the attachment keeps working after DevilPDF's link expires (24 hours on the free plan).
  • A date field's cell value is an ISO date string such as 2026-12-03, which is what the template expects. It prints it in the document's locale.
  • The Status update stops the automation from running twice on the same record. Writing a single select requires the option to exist already.
  • output.set makes the link available to later actions, for example a Send email action that includes the PDF link.

#A note on the API key

The key sits in the script. Anyone who can edit this base's automations can see it. Create a dedicated DevilPDF key just for this base, so you can revoke it on its own if the base is shared more widely than you planned.

#From a button instead

To generate on demand, add a Button field to Invoices that runs the Scripting extension, and replace the first lines of the script with:

Scripting extension
const invoices = base.getTable("Invoices");
const invoice = await input.recordAsync("Pick an invoice", invoices);
const recordId = invoice.id;

Keep the rest of the script, except input.config() and output.set, which only exist in automations (output.text works in the extension).

#Other documents and languages

The other starters are quote, receipt, statement, report, packing-slip and certificate. Each documents the fields it accepts in sample_data; see templates.

Add a Language field to the customer and send it as locale next to template: locale: invoice.getCellValueAsString("Language") || "en-US". With ar, fr, ja or any of the 32 languages the starters are translated into, the starter's labels, dates and money switch, and Arabic and Hebrew invoices mirror right to left.

#Next steps