Skip to main content

Prepare Parse Info for Document

What this guide covers

Prepare Parse Info is the dashboard setup that turns a raw PDF into automated PDF data extraction. You define capture keys, draw zones on a sample document, and assign each key an extraction rule using either Regex Expression for stable patterns or JavaScript Expression for conditional logic. Once saved, the same template runs from the REST API, Make, Zapier, Power Automate, and n8n by referring to its TemplateId.

Related Blog Posts(5)
Static Lines Stayed in the PDF. n8n Gave Them a Spreadsheet to Live In.
n8n workflow: Dropbox download PDF, PDF4me OCR to editable PDF, PDF4me Convert PDF to Excel, Dropbox upload XLSX. For teams automating table extraction, invoice PDFs, and cloud handoff without copy-paste.
Read post
Having difficulty in dynamically renaming files ? Rename PDFs in Power Automate Using Parsed Data !
Put invoice number, PO, or contract ID in the PDF filename automatically. Power Automate + PDF4me Parse Document: get file from Dropbox, extract the field, create file with that name. No code. Step-by-step with screenshots.
Read post
Your Scan Already Hid a Spreadsheet. You Just Needed a Door to Excel.
Power Automate flow: Dropbox PDF in, PDF4me OCR plus PDF to Excel, XLSX back to Dropbox. Built for intelligent document processing, table extraction from invoices, and Microsoft 365 automation without manual copy-paste.
Read post

Authenticating Your Setup

Parse template creation happens in the PDF4me developer dashboard. Sign in with your account, then create or copy an API key for the Parse Document API calls that use the template you build here.

Important Facts You Should Not Miss

Regex first, JavaScript only where needed
Use Regex Expression for any field with a stable shape (invoice number, date, total, tax ID). Use JavaScript Expression only when you need conditional logic, multi-rule branching, or document classification. Mixing the two in the same template is fine and recommended.
One template per stable layout family
A single template handles small variations such as font changes or shifted positions. For genuinely different layouts (two vendors with different invoice designs) create separate templates and route files to the right one by classifier or source system before calling Parse Document.
Save the TemplateId, not the name
After Save Changes, the dashboard generates a GUID TemplateId for the template. Always pass TemplateId in production API calls. TemplateName works too but renaming the template breaks any automation referencing it by name.

Step 1: Create the parse template

  1. Open the Parse Document dashboard.
  2. Click Add and enter a clear template name (for example, invoice or vendor-statement).
  3. Click Save to create the empty template.
  4. Open the template in Edit mode to start configuring capture keys.
PDF4me Parse Document template list in the developer dashboard, with the Add button to create a new parse template for automated PDF data extraction

Step 2: Upload a sample and configure capture keys

The dashboard renders an uploaded PDF on the right and shows the Parse Info form on the left. Use real production-shaped samples, not synthetic test files, so the capture areas match what you will see in live traffic.

  1. Click Upload Template File and pick a representative sample (invoice, contract, form).
  2. Under Keys, click + to add a capture key. Give it a name in camelCase: invoiceNumber, customerName, totalAmount.
  3. Choose Choose expression type for the key: Javascript Expression or Regex Expression.
  4. Paste the expression body in the field that appears.
  5. Set Pages to all to scan every page, or to a specific page number (1, 2, etc.) to limit the scope.
  6. Toggle Search Whole Page on when the value is not at a fixed position. With it off, only the drawn capture area is searched.
PDF4me Parse Document configuration UI. Left panel shows Parse Info with Template Name invoice, Parse Id, and a KeyName key with Choose expression type Javascript Expression, Javascript Expression body, Pages all, and Search Whole Page toggle. Right panel shows the uploaded invoice PDF rendered with the action buttons Upload Template File, Test Parse, and Save Changes at the top in left-to-right execution order

Parse Document setup screen. Left: Parse Info form with Keys and expression type. Right: uploaded sample PDF. Action buttons run left to right: Upload Template File, Test Parse, Save Changes.

Step 3: Pick the expression type per key

Expression TypeBest forTypical useComplexity
Regex ExpressionFixed text patternsInvoice number, dates, totals, tax IDs, postal codesLow
JavaScript ExpressionConditional and multi-rule extractionDocument classification, fallback logic, rule orchestrationMedium to High

Regex Expression patterns (regex pdf parser basics)

Use Regex Expression when the field has a stable, predictable shape. The captured area is scanned for the first match.

INV-\d{6,10}
\d{2}/\d{2}/\d{4}
\$?\d{1,3}(?:,\d{3})*(?:\.\d{2})?

Common key mappings for an invoice:

  • invoiceNumberINV-\d{6,10}
  • invoiceDate\d{2}/\d{2}/\d{4}
  • totalAmount\$?\d{1,3}(?:,\d{3})*(?:\.\d{2})?

These same patterns also work for the same fields in vendor statements, purchase orders, and shipping documents because invoice numbers, dates, and amounts share the same shape across most business documents.

JavaScript Expression for conditional logic

Use JavaScript Expression when the output depends on the presence or combination of multiple markers in the document. PDF4me passes the extracted text into your function as the variable text. Your function evaluates the text and returns a string that becomes the value for the key.

Example 1: classify by content markers

Distinguishes a Terms and Conditions document from an Order document by checking which marker phrases appear:

function functionFormatTextDate1(text) {
console.log("Hello");
var term = [...text.matchAll(/General Terms and Conditions/gi)];
var order = [...text.matchAll(/your ordernumber/gi)];

if (term.length) {
if (order.length) {
return "Order document";
} else {
return "Terms and Conditions";
}
} else {
return "Not Terms and Conditions";
}
}

return functionFormatTextDate1(text);

Example 2: invoice vs order detection

A short classifier that decides whether the document is an invoice or an order based on the presence of the words invoice and ordernumber:

function functionGetInvoiceOrder(text) {
// You get all PDF text in `text`
var invoice = [...text.matchAll(/invoice/gi)];
var order = [...text.matchAll(/ordernumber/gi)];

if (invoice.length) {
if (order.length) {
return "Order document";
} else {
return "invoice";
}
} else {
return "";
}
}

return functionGetInvoiceOrder(text);

Implementation tip: Wrap your logic in a named function and call it with return functionName(text); at the bottom. The dashboard executes the expression body as a function whose final returned value populates the key.

Step 4: Test Parse and Save Changes

The action buttons at the top of the editor run left to right in the order you use them:

  1. Upload Template File loads the sample PDF used for drawing capture areas.
  2. Test Parse runs all keys against the uploaded sample and shows the extracted values inline. Use this to validate each Regex or JavaScript expression before saving.
  3. Save Changes persists the template and assigns a stable TemplateId (GUID). Copy that GUID for use in API calls and automation platforms.

Iterate on each key until Test Parse returns the expected value for every field. Tighten the capture area if you see neighbour text, or refine the expression if pattern matches are too loose.

Use the template in API or automation calls

Once Save Changes assigns a TemplateId, the same parse template runs anywhere by reference. You do not need to recreate the configuration on each platform.

FieldSourcePurpose
TemplateIdGUID shown in the template detail panel after savingStable identifier for production automation. Always prefer this over TemplateName.
TemplateNameThe name you typed in Step 1Alternative for lookup. Renaming the template breaks calls that reference it by name.
ParseIdA GUID you generate client-side (one per call)Correlates your request with the parse output, useful for logging and audit trails.
docNameSource PDF filenameUsed for tracking and error messages.
docContentSource PDF encoded as Base64The file to parse.
asyncfalse for synchronous, true for pollingControls response delivery.

Example REST request body:

{
"docName": "invoice.pdf",
"docContent": "BASE64_ENCODED_PDF_CONTENT",
"TemplateId": "12345678-1234-1234-1234-123456789abc",
"ParseId": "87654321-4321-4321-4321-cba987654321",
"async": false
}

The response contains one field per key you defined in the template. Route that JSON into any downstream node: Google Sheets, Airtable, a database, Excel, or a webhook.

Common workflows

Typical parse-template patternsHow a saved parse template moves from dashboard to production.
Invoice inbox to accounting spreadsheet
  1. A vendor invoice PDF arrives in a watched email or cloud folder.
  2. Make, Zapier, Power Automate, or n8n calls Parse Document with your TemplateId.
  3. The structured JSON output (invoiceNumber, totalAmount, invoiceDate) is appended as a row in Google Sheets or Excel.
  4. Accounting reviews and approves directly from the spreadsheet.
Form intake to database record
  1. A customer uploads a filled PDF form through your portal.
  2. Your backend calls Parse Document with TemplateId and the Base64 PDF.
  3. The parsed JSON is mapped into a database INSERT, with one column per template key.
  4. A confirmation email goes back to the customer using the parsed name and reference number.
Document classifier plus extractor
  1. A single watched folder receives mixed documents (invoices, orders, contracts).
  2. A JavaScript Expression key in the template returns the document type (see Example 2 above).
  3. Your workflow routes each file to the right downstream system based on the returned type.
  4. Files identified as invoices continue to Regex-based field extraction in the same template call.

Template configuration best practices

  • Draw capture areas slightly larger than the expected value so font or position drift does not push the value out of frame.
  • Keep key names consistent in camelCase across templates so downstream mapping in spreadsheets, databases, and webhooks stays predictable.
  • Test every key against at least three real samples, including edge cases like missing optional fields, second-page invoices, and OCR-derived text from scanned PDFs.
  • Use JavaScript Expression only where Regex cannot express the rule. Keeping logic simple makes the template easier to debug.
  • Version your templates by name (invoice-v1, invoice-v2) when making breaking changes, so production automation can migrate at its own pace.
  • Run scanned PDFs through OCR first (the PDF4me OCR endpoint) before parsing. Templates extract from the text layer, which scanned PDFs do not have until OCR is applied.

Frequently Asked Questions

Should I use Regex Expression or JavaScript Expression first?+
Start with Regex Expression for fixed-shape fields like invoice numbers, dates, totals, and tax IDs. Move to JavaScript Expression when extraction depends on multiple conditions, fallback rules, or document classification. Most production templates use Regex for around 80% of keys and JavaScript for the rest.
Where does the text variable in JavaScript Expression come from?+
PDF4me passes the extracted text of the captured region (or the full PDF when Search Whole Page is enabled) into the expression context as the variable named text. Your function evaluates that string and returns a string for the configured key.
Does parse template extraction work on scanned PDFs?+
Yes, when the PDF has been OCR-processed first. Scanned PDFs are images until OCR is applied. Run the source file through the PDF4me OCR endpoint or upload an already-OCR'd PDF to the dashboard before drawing capture areas. The template then extracts from the OCR text layer.
Can one template handle multiple invoice layouts?+
It can absorb small differences in font, position, or page count. For genuinely different layouts (two vendors with different invoice designs) create separate templates and route files to the right one by classifier or source system before calling Parse Document.
What do I need to call the parse template from the API?+
Send docName, docContent (the PDF as Base64), TemplateId (the GUID copied from the dashboard after Save Changes), ParseId (a client-generated GUID), and async (false for immediate response, true for polling). TemplateName works instead of TemplateId but TemplateId is recommended for stable automation.
How do I move extracted data into Excel, Google Sheets, or a database?+
The parse output is structured JSON, with one field per key you defined in the template. Route that JSON to any destination from your automation platform: Add Row in Google Sheets, Insert Row in Airtable or a database, or write to Excel via the Excel module in Make, Power Automate, n8n, or Zapier. The same TemplateId works on every platform.
How does this compare with Python PDF data extraction libraries?+
Tools like pdfplumber, PyMuPDF, and pdfminer give you raw extraction primitives in Python, but you write and maintain the matching logic yourself. PDF4me parse templates give you a saved, named template you configure once in a dashboard and call from any language or platform. Use Python libraries when you need full programmatic control inside a single codebase; use PDF4me parse templates when you want the same extraction running across the REST API, Make, Zapier, Power Automate, and n8n without copying logic between systems.
How should I test a parse template before production?+
Validate each key against at least three real samples, including edge cases such as missing optional fields, alternate fonts, multi-page documents, and second-page positions. Use Test Parse in the dashboard for each sample, confirm the output matches expectations, then run a small automation against live files in monitor mode before enabling end-to-end automation.
How do I connect this setup to no-code platforms?+
Use the platform-specific guides under Related actions. Each platform exposes the same TemplateId and ParseId fields so the parsing logic stays identical to what you tested in the dashboard. The output structure also matches across platforms.

Get Help