Back to Blog

How to generate PDFs from Airtable data

Learn how to generate PDFs using your Airtable data and save the output PDF to a field in your Airtable table.

By Alex Cooney |

There are a number of ways to generate PDFs in Airtable. The most basic is to use the Airtable Page Designer extension (which is an official extension made by Airtable). However, the Page Designer comes with a number of pretty significant limitations:

  • It cannot be automated in any way (you have to manually 'save' every PDF)
  • You can only create 1-page documents

Thankfully, there are a number of apps that allow you to overcome these limitations and automate PDF generation in your Airtable table. In this article, we'll be showing how you can generate PDFs using an Airtable Automation and DocuPotion.

Structuring your Airtable table

The first step is to structure your Airtable table so that we can reference the relevant data. In this example we're going to be creating a PDF of a simple invoice. In the image below, we have a table called 'Invoices' that has the following columns:

  • Customer Name (single line text)
  • Address (single line text)
  • Invoice Number (number)
  • Grand Total (rollup)
  • Line Items (linked records)
  • PDF (attachment)
  • Generate PDF (checkbox)
Airtable table structure for invoices

Airtable table structure for invoices

The linked record links the 'Invoices' table to the 'Line Items' records. The 'Line Items' table includes information on each product that's going to be included in our invoice:

Line items table structure

Line items table structure

There are a couple of key things to note at this stage:

  • The 'PDF' field in the 'Invoices' table is going to be the field that the output PDF is attached to - this must be an Attachment field
  • The 'Generate PDF' checkbox field is going to be used to trigger the automation that creates the PDF. When the user checks the checkbox, we're going to run a script that calls the DocuPotion API and attaches the generated PDF to the 'PDF' field

Register for a DocuPotion account and generate API key

We're going to design a PDF template in DocuPotion. Navigate to the DocuPotion homepage and click on the 'Register / Sign in' button.

DocuPotion homepage

DocuPotion homepage

You'll then be brought to the registration page where you'll need to enter some details. Once you've submitted your details, you'll be navigated to the DocuPotion dashboard.

Navigate to the 'My Account' tab and click the 'Generate API Key' button to generate an API key:

Generate API key in DocuPotion

Generate API key in DocuPotion

You don't need to do anything with this API key - it will automatically be included in your Airtable Automation script when you generate it later on.

Designing a PDF template

Navigate to the 'Templates' tab and click on the 'Create New Template' button. You can choose from a pre-built template or start with a blank template. You'll then be brought to the PDF editor where you can design your PDF template.

See this doc for details on using the template editor

You can drag components onto the editor canvas to design your PDF:

DocuPotion PDF editor example

DocuPotion PDF editor example

You can preview how your PDF will look in the 'Preview' tab:

Preview tab in DocuPotion editor

Preview tab in DocuPotion editor

Mapping data to Airtable data

You can add custom data (i.e. data from your Airtable table) by using {{ }} inside a text component or a dynamic table cell. For example, in the below template we've added in the following variables inside text components:

  • {{Customer Name}}
  • {{Address}}
  • {{Grand Total}}

When we're generating our PDF, these {{ }} variables are going to be replaced by the data in our Airtable table.

The names of the {{ }} variables in your DocuPotion template MUST exactly match the names of the fields in your Airtable table. For example, if one of your Airtable fields is called 'Name', the dynamic variable in your DocuPotion template must be called {{Name}} (with an uppercase 'N')

Optional: Mapping data to linked records in Airtable

We also have a dynamic table in our DocuPotion template that includes the following variables:

  • {{Name}}
  • {{Price}}
  • {{Quantity}}
  • {{Total}}

The dynamic table component can be used to display data from linked records. In our example, we want to show the records in our 'Line Items' table. In order to link the dynamic table to a linked record in our Airtable table, you need to set the data source to the name of the linked record:

Setting data source for dynamic table

Setting data source for dynamic table

Setting up the Automation in Airtable

Click on the 'Automations' tab in your Airtable dashboard and 'Add a Trigger'. In our example, we're using the 'Generate PDF' checkbox field to trigger the automation. Whenever a user checks the checkbox, the automation is going to be run.

Setting up automation trigger in Airtable

Setting up automation trigger in Airtable

Next, add a 'Run Script' action to the automation. This is where we're going to paste in the script that calls the DocuPotion API and uploads the output PDF to our Airtable table.

Generating the Airtable Automation script

Go back to your DocuPotion editor, navigate to the 'Integrations' tab and select the Airtable option. A popup will open:

Airtable integration popup in DocuPotion

Airtable integration popup in DocuPotion

Add the URL of your Airtable table to the 'Table URL' input and the name of the Attachment field you want your PDF to be uploaded to in the 'PDF Attachment Field' input. You can also choose whether you want newly generated PDFs to overwrite any existing PDFs.

Once you've provided this info, click on the 'Generate Script' button to get your Automation script:

Generating Airtable automation script

Generating Airtable automation script

Copy this script into the code editor for the 'Run Script' action in your Airtable Automation.

Pasting script into Airtable automation

Pasting script into Airtable automation

Next, link the automation to a specific record by adding an input variable called 'record_id'. Link this input variable to the 'Airtable record ID' that was the trigger in step 1.

Adding record_id input variable

Adding record_id input variable

Click on the 'Finish editing' button and turn the Automation on.

Running the automation

Navigate to your data tab and check one of the 'Generate PDF' checkboxes. After a few seconds, you should see a PDF appearing in your Attachment field.

Generated PDF in Airtable table

Generated PDF in Airtable table

Debugging issues with the automation

If you're not seeing a PDF appear, you can check the 'Automations' tab for details on what caused the issue. Click on 'History' and take a look at the 'Run history' tab on the right-hand side:

Automation run history in Airtable

Automation run history in Airtable

Click on the run instance that caused the problem and view the execution log to see what caused the issue. In the example below, we changed the name of the 'Price' column in our 'Line Items' table to 'Price of Product'.

Error details in automation history

Error details in automation history

Updating variables in DocuPotion template

If you change the names of any of the {{ }} variables in the DocuPotion template, you will need to re-generate the Automation script in DocuPotion and update the script in the Airtable Automation tab.

Ready to try DocuPotion?

Start creating beautiful PDFs for your Bubble app with our free trial. No setup required – get started in minutes.

Start Free Trial