New: PDF to E-Invoice for Factur-X/ZUGFeRD, and PDF to PDF/A for archive-ready PDF/A-3b.

Automate Invoice Splitting and Data Extraction Using AI Invoice Parser and Zapier

This tutorial demonstrates how to automate invoice processing using the PDF.co AI Invoice Parser and Zapier. The workflow will:

  1. Split a multi-invoice PDF into individual invoice files. Extract data from each invoice using PDF.co’s AI Invoice Parser.
  2. Save the extracted data into a Google Sheets.

Sample Input

This example uses a PDF containing five invoices, with exactly one complete invoice per page. Splitting with * creates one PDF per page.

For a multipage invoice, keep all pages belonging to that invoice together before parsing it.

Sample Input

Step-by-Step Instructions

Step 1: Trigger on New File in Google Drive

  • App: Google Drive
  • Trigger: New File in Folder
  • Purpose: Detect when a new PDF file is added to a specific folder.

Note: Make sure the folder contains only the target PDF file with multiple invoices.

Step 2: Configure Google Drive

  • Drive: Select My Google Drive.
  • Folder: Choose the folder where the multi-invoice PDF will be uploaded.
Configure Google Drive

Step 3: Test the Trigger

Run a test to confirm that Zapier detects the uploaded PDF file correctly.

Test the Trigger

Step 4: Add PDF.co App – Split PDF

  • App: PDF.co
  • Action Event: Split PDF Into Multiple Files
Add PDF.co App – Split PDF

Step 5: Configure PDF.co Split Action

  • File Source: Use the file from Step 3.
  • Page Numbers/Ranges: Enter * (asterisk) to split all pages into separate files.
Configure PDF.co Split Action

Step 6: Test the Split Action

Confirm that each page of the original PDF is split into a separate invoice PDF.

Test the Split Action

Step 7: Add Looping by Zapier

  • App: Looping by Zapier
  • Action: Create Loop From Line Items
  • Purpose: Iterate through the list of individual invoice URLs.
Add Looping by Zapier

Step 8: Configure Looping

  • Values to Loop: Use the output array of URLs from the Split PDF action.
Configure Looping

Step 9: Test the Looping Setup

Run a test to ensure that each invoice PDF is processed in the loop.

Test the Looping Setup

Step 10: Add PDF.co AI Invoice Parser

  • App: PDF.co
  • Action Event: AI Invoice Parser
Add PDF.co AI Invoice Parser

Step 11: Configure Invoice Parser

Set Source File URL to the current invoice URL from the looping step.

Leave Custom Fields empty. In Line Item Structure, enter:

{
  "description": "string",
  "quantity": "number",
  "unitPrice": "number",
  "totalPrice": "number"
}

This defines consistent line-item keys for the spreadsheet columns. Without a configured structure, the returned names can vary between invoices.

See the AI Invoice Parser documentation for these settings.

Step 12: Inspect One Invoice Result

Test the parser and check for an error. Inspect the invoice data returned in body, including:

  • invoice.invoiceNo
  • invoice.invoiceDate
  • vendor.name
  • lineItems

Confirm that the line items contain the four configured keys. Empty or default values still need review against the PDF.

The invoice header applies to the whole invoice; each line item needs a separate spreadsheet row.

Step 13: Map the Invoice JSON

Add Code by Zapier → Run Python.

Create an Input Data key named invoice_json. Map the parser’s complete invoice body as JSON text, including its header and line items.

Inspect the test input before continuing. It must be valid JSON—not a PDF URL, a comma-joined description list, or [object Object].

If the editor does not expose the complete body as serialized JSON, you can paste the complete test JSON temporarily to check the transformation. Confirm a working dynamic JSON mapping before enabling automatic runs; pasted test data must not remain in the live workflow.

Step 14: Build the Spreadsheet Columns

Paste this code into the Python step:

import json

payload = json.loads(input_data["invoice_json"])

if isinstance(payload, dict) and payload.get("error"):
    raise ValueError("Expected a successful invoice JSON object")

data = payload.get("body", payload) if isinstance(payload, dict) else payload

if isinstance(data, list) and len(data) == 1:
    data = data[0]

if not isinstance(data, dict) or data.get("error") or "lineItems" not in data:
    raise ValueError("Expected one invoice with a lineItems collection")

invoice = data.get("invoice") or {}
vendor = data.get("vendor") or {}

if not isinstance(invoice, dict) or not isinstance(vendor, dict):
    raise ValueError("Unexpected invoice or vendor structure")


def flatten_items(value):
    if not isinstance(value, list):
        raise ValueError("Expected lineItems to be a list")

    result = []
    for item in value:
        if isinstance(item, list):
            result.extend(flatten_items(item))
        elif isinstance(item, dict):
            result.append(item)
        else:
            raise ValueError("Unexpected line-item value")

    return result


def cell(value):
    if value is None:
        return ""
    if isinstance(value, (dict, list)):
        raise ValueError("A spreadsheet cell must be a scalar value")
    return str(value)


items = flatten_items(data["lineItems"])

columns = {
    "invoice_no": [],
    "invoice_date": [],
    "vendor_name": [],
    "description": [],
    "quantity": [],
    "unit_price": [],
    "total_price": [],
}

for item in items:
    required = {"description", "quantity", "unitPrice", "totalPrice"}

    if not required.issubset(item):
        raise ValueError("Line-item keys do not match lineItemStructure")

    columns["invoice_no"].append(cell(invoice.get("invoiceNo")))
    columns["invoice_date"].append(cell(invoice.get("invoiceDate")))
    columns["vendor_name"].append(cell(vendor.get("name")))
    columns["description"].append(cell(item["description"]))
    columns["quantity"].append(cell(item["quantity"]))
    columns["unit_price"].append(cell(item["unitPrice"]))
    columns["total_price"].append(cell(item["totalPrice"]))

return {"row_count": len(items), **columns}

The code accepts one invoice object, a one-element invoice array, or a response containing the invoice under body. It flattens nested line-item lists and repeats the invoice header for every item.

It preserves missing cell values as blanks and numeric zero as "0". It shapes the data but does not verify extraction accuracy or recalculate totals.

Step 15: Handle Empty Results

Add Filter by Zapier after the code step.

Continue only when row_count is greater than 0.

An empty collection produces no item rows. Review that invoice separately rather than inventing an item or treating missing values as zero.

Step 16: Create the Spreadsheet Rows

Add Google Sheets → Create Multiple Spreadsheet Rows after the filter, within the existing invoice iteration.

Select your spreadsheet and worksheet. Create these column headers and map the matching code outputs:

  • Invoice No: invoice_no
  • Invoice Date: invoice_date
  • Vendor: vendor_name
  • Description: description
  • Quantity: quantity
  • Unit Price: unit_price
  • Line Total: total_price

Map each output as its complete line-item array. Corresponding positions across the arrays form one spreadsheet row.

Do not add another invoice loop or combine all descriptions into a single cell.

Step 17: Check the Row Mapping

For an illustrative invoice numbered EXAMPLE-101, dated 2026-10-01, from Example Studio, two items should produce two rows:

  • First row: Review; quantity 2; unit price 10; line total 20.
  • Second row: Delivery; quantity 1; unit price 5; line total 5.

Both rows should repeat the same invoice number, date, and vendor.

Compare your actual rows with the corresponding PDF. Confirm that the row count matches the accepted line-item count and that descriptions, quantities, and prices remain aligned.

Test an empty collection and an unexpected structure as well. Review existing test rows before repeating an insertion so duplicates are not mistaken for newly extracted items.

Enable the Zap only after confirming the dynamic JSON mapping, invoice boundaries, and spreadsheet results.

Result Summary

You have successfully automated your invoice processing pipeline using:

  • PDF.co to split and parse invoices
  • Zapier to handle workflow automation
  • Google Sheets to store extracted invoice data

Related Tutorials

See Related Tutorials