A Document Parser template describes the fields and tables to extract from a document. Use the Template Editor to build and test the rules before applying the template to other files.
Create and test a template
Open the Document Parser Template Editor from your PDF.co dashboard and load a representative document.
Add the fields or tables you want to extract. Use rectangle selection for fixed positions, text search for values located by text, or a static field for a constant value.
Set each object's name and extraction settings. Expressions can use macros, regular expressions, or special functions. Enable the regex option when using regular expressions, including expressions that combine regex with macros.
Test the template, inspect the extracted values, and adjust the rules. Repeat with documents whose layout or contents vary.
Save the template and use it with Document Parser in your API request or automation.
For all object types, table settings, and editor details, see the complete developer guide.
Built-in macro reference
Use macros in the field's Expression value. A macro uses double braces, for example {{SmartDate}} or {{Digits}}.
Macro | Description |
|---|---|
| Tries to detect the date in the most common formats. |
| Decimal number like the following: "12.34", "-123,456.78", "123.456". Decimal separator and thousands separator are automatically taken from the template culture. |
| Decimal number with currency symbol like the following: "USD 12.34", "$123,456.78", "123.45 €". Decimal separator and thousands separator are automatically taken from the template culture. |
| Tries to detect US phone number. |
| Single space. |
| One or more spaces. |
| Two spaces. |
| Three spaces. |
| Four spaces. |
| Five spaces. |
| Six spaces. |
| Seven spaces. |
| Eight spaces. |
| Nine spaces. |
| Ten spaces. |
| One digit. |
| One or more digits. |
| Two digits. |
| Three digits. |
| Four digits. |
| Five digits. |
| Six digits. |
| Seven digits. |
| Eight digits. |
| Nine digits. |
| Ten digits. |
| One digit or symbol ("_ - + = /"). |
| One or more digits or symbols ("_ - + = /"). |
| Two digits or symbols ("_ - + = /"). |
| Three digits or symbols ("_ - + = /"). |
| Four digits or symbols ("_ - + = /"). |
| Five digits or symbols ("_ - + = /"). |
| Six digits or symbols ("_ - + = /"). |
| Seven digits or symbols ("_ - + = /"). |
| Eight digits or symbols ("_ - + = /"). |
| Nine digits or symbols ("_ - + = /"). |
| Ten digits or symbols ("_ - + = /"). |
| One letter from any language. |
| One or more letters from any language. |
| Two letters from any language. |
| Three letters from any language. |
| Four letters from any language. |
| Five letters from any language. |
| Six letters from any language. |
| Seven letters from any language. |
| Eight letters from any language. |
| Nine letters from any language. |
| Ten letters from any language. |
| One uppercase letter from any language. |
| One or more uppercase letters from any language. |
| Two uppercase letters from any language. |
| Three uppercase letters from any language. |
| Four uppercase letters from any language. |
| Five uppercase letters from any language. |
| Six uppercase letters from any language. |
| Seven uppercase letters from any language. |
| Eight uppercase letters from any language. |
| Nine uppercase letters from any language. |
| Ten uppercase letters from any language. |
| One letter or digit. |
| One or more letters or digits. |
| Two letters or digits. |
| Three letters or digits. |
| Four letters or digits. |
| Five letters or digits. |
| Six letters or digits. |
| Seven letters or digits. |
| Eight letters or digits. |
| Nine letters or digits. |
| Ten letters or digits. |
| One uppercase letter or digit. |
| One or more uppercase letters or digits. |
| Two uppercase letters or digits. |
| Three uppercase letters or digits. |
| Four uppercase letters or digits. |
| Five uppercase letters or digits. |
| Six uppercase letters or digits. |
| Seven uppercase letters or digits. |
| Eight uppercase letters or digits. |
| Nine uppercase letters or digits. |
| Ten uppercase letters or digits. |
| One letter, or digit, or symbol ("_ - + = /"). |
| One or more letters, or digits, or symbols ("_ - + = /"). |
| Two letters, or digits, or symbols ("_ - + = /"). |
| Three letters, or digits, or symbols ("_ - + = /"). |
| Four letters, or digits, or symbols ("_ - + = /"). |
| Five letters, or digits, or symbols ("_ - + = /"). |
| Six letters, or digits, or symbols ("_ - + = /"). |
| Seven letters, or digits, or symbols ("_ - + = /"). |
| Eight letters, or digits, or symbols ("_ - + = /"). |
| Nine letters, or digits, or symbols ("_ - + = /"). |
| Ten letters, or digits, or symbols ("_ - + = /"). |
| One uppercase letter, or digit, or symbol ("_ - + = /"). |
| One or more uppercase letters, or digits, or symbols ("_ - + = /"). |
| Two uppercase letters, or digits, or symbols ("_ - + = /"). |
| Three uppercase letters, or digits, or symbols ("_ - + = /"). |
| Four uppercase letters, or digits, or symbols ("_ - + = /"). |
| Five uppercase letters, or digits, or symbols ("_ - + = /"). |
| Six uppercase letters, or digits, or symbols ("_ - + = /"). |
| Seven uppercase letters, or digits, or symbols ("_ - + = /"). |
| Eight uppercase letters, or digits, or symbols ("_ - + = /"). |
| Nine uppercase letters, or digits, or symbols ("_ - + = /"). |
| Ten uppercase letters, or digits, or symbols ("_-+=/"). |
| Dollar sign ($). |
| Euro sign (€). |
| Pound sign (£). |
| Yen sign (¥). |
| Yuan sign (¥). |
| Any currency symbol ($, €, £, ¥, etc.) |
| Single dot symbol ("."). |
| Single comma symbol (","). |
| Single colon symbol (":"). |
| Single semicolon symbol (";"). |
| Single minus (dash, hyphen) symbol ("-"). |
| Slash symbol ("/"). |
| Backslash symbol ("\"). |
| Percent symbol ("%"). |
| Start of line (virtual symbol). |
| End of line (virtual symbol). |
| Single-space-separated sequence of words and symbols. Breaks on double space. |
| Extended {{SentenceWithSingleSpaces}} macro allowing two spaces between words. Breaks on triple space. |
| End of page or end of document. |
| Start or end of word (virtual symbol). |
| Opening curly brace symbol ("{"). |
| Closing curly brace symbol ("}"). |
| Opening parenthesis symbol ("("). |
| Closing parenthesis symbol (")"). |
| Opening square bracket symbol ("["). |
| Closing square bracket symbol ("]"). |
| Opening angle bracket symbol ("<"). |
| Closing angle bracket symbol (">"). |
| Date in format "01/01/19" (with leading zero). |
| Date in format "1/1/19" (without leading zero). |
| Date in format "01/01/2019" (with leading zero). |
| Date in format "1/1/2019" (without leading zero). |
| Date in format "01-01-19" (with leading zero). |
| Date in format "1-1-19" (without leading zero). |
| Date in format "01-01-2019" (with leading zero). |
| Date in format "1-1-2019" (without leading zero). |
| Date in format "01.01.19" (with leading zero). |
| Date in format "1.1.19" (without leading zero). |
| Date in format "01.01.2019" (with leading zero). |
| Date in format "1.1.2019" (without leading zero). |
| Date in format "01/01/19" (with leading zero). |
| Date in format "1/1/19" (without leading zero). |
| Date in format "01/01/2019" (with leading zero). |
| Date in format "1/1/2019" (without leading zero). |
| Date in format "01-01-19" (with leading zero). |
| Date in format "1-1-19" (without leading zero). |
| Date in format "01-01-2019" (with leading zero). |
| Date in format "1-1-2019" (without leading zero). |
| Date in format "01.01.19" (with leading zero). |
| Date in format "1.1.19" (without leading zero). |
| Date in format "01.01.2019" (with leading zero). |
| Date in format "1.1.2019" (without leading zero). |
| Date in format "20190101". |
| Date in format "2019/01/01" (with leading zero). |
| Date in format "2019/1/1" (without leading zero). |
| Date in format "2019-01-01" (with leading zero). |
| Date in format "2019-1-1" (without leading zero). |
| Any characters up to the next macro in the expression. |
| Any characters up to the next macro in the expression or to the end of line. Greedy version. |
| Enables or disables single-line mode. In single-line mode, {{Anything}} and {{AnythingGreedy}} macros do not stop at the end of the line and proceed to the next line of text. |
| Enables or disables case-insensitive mode. |
Special Functions
You can also insert so called special function which looks like this: $$functionName. Special functions are created for AI-powered value detection, like a company name, max number in a whole document, max date or even finding and decoding QR Code barcode value inside document.
All special functions are listed here
Sample template and output
DigitalOcean invoice example
Sample document text:
DigitalOcean
101 Avenue of the Americas, 10th Floor
New York, NY 10013Date Issued: February 1, 2016
Period: January 1 - 31, 2016
Invoice Number: 1234567Description Hours Start End USD
Website-Dev (1GB) 744 01-01 00:00 01-31 23:59 $10.00
Website-Live (1GB) 744 01-01 00:00 01-31 23:59 $10.00
Database-Live (2GB) 744 01-01 00:00 01-31 23:59 $20.00
Tasks-Dev (1GB) 744 01-01 00:00 01-31 23:59 $10.00
Total: $50.00Bill To:
Samee Sikka <admin@meee.org>
meee.org
GouranIf you have a credit card on file it will be automatically charged within 24 hours.Sample template (JSON):
{
"templateVersion": 4,
"templatePriority": 0,
"templateName": "DigitalOcean Invoice",
"objects": [
{
"name": "companyName",
"objectType": "field",
"fieldProperties": {
"fieldType": "static",
"expression": "DigitalOcean"
}
},
{
"name": "invoiceId",
"objectType": "field",
"fieldProperties": {
"fieldType": "macros",
"expression": "Invoice Number: ({{Digits}})",
"regex": true
}
},
{
"name": "dateIssued",
"objectType": "field",
"fieldProperties": {
"fieldType": "macros",
"expression": "Date Issued: ({{SmartDate}})",
"dataType": "date",
"dateFormat": "auto-mdy"
}
},
{
"name": "total",
"objectType": "field",
"fieldProperties": {
"fieldType": "macros",
"expression": "Total: {{Dollar}}({{Number}})",
"dataType": "decimal"
}
},
{
"name": "currency",
"objectType": "field",
"fieldProperties": {
"fieldType": "static",
"expression": "USD"
}
},
{
"name": "table1",
"objectType": "table",
"tableProperties": {
"start": {
"expression": "Description{{Spaces}}Hours"
},
"end": {
"expression": "Total:"
},
"row": {
"expression": "{{LineStart}}{{Spaces}}(?<description>{{SentenceWithSingleSpaces}}){{Spaces}}(?<hours>{{Digits}}){{Spaces}}(?<start>{{2Digits}}{{Minus}}{{2Digits}}{{Space}}{{2Digits}}{{Colon}}{{2Digits}}){{Spaces}}(?<end>{{2Digits}}{{Minus}}{{2Digits}}{{Space}}{{2Digits}}{{Colon}}{{2Digits}}){{Spaces}}{{Dollar}}(?<unitPrice>{{Number}})",
"regex": true
},
"columns": [
{
"name": "hours",
"type": "integer"
},
{
"name": "unitPrice",
"type": "decimal"
}
]
}
}
]
}Result (JSON):
{
"templateName": "DigitalOcean Invoice",
"templateVersion": "4",
"objects": [
{
"name": "companyName",
"objectType": "field",
"value": "DigitalOcean"
},
{
"name": "invoiceId",
"objectType": "field",
"value": "1234567",
"pageIndex": 0
},
{
"name": "dateIssued",
"objectType": "field",
"value": "2016-02-01T00:00:00",
"pageIndex": 0
},
{
"name": "total",
"objectType": "field",
"value": 50,
"pageIndex": 0
},
{
"name": "currency",
"objectType": "field",
"value": "USD"
},
{
"name": "table1",
"objectType": "table",
"rows": [
{
"description": {
"value": "Website-Dev (1GB)",
"pageIndex": 0
},
"hours": {
"value": 744,
"pageIndex": 0
},
"start": {
"value": "01-01 00:00",
"pageIndex": 0
},
"end": {
"value": "01-31 23:59",
"pageIndex": 0
},
"unitPrice": {
"value": 10,
"pageIndex": 0
}
},
{
"description": {
"value": "Website-Live (1GB)",
"pageIndex": 0
},
"hours": {
"value": 744,
"pageIndex": 0
},
"start": {
"value": "01-01 00:00",
"pageIndex": 0
},
"end": {
"value": "01-31 23:59",
"pageIndex": 0
},
"unitPrice": {
"value": 10,
"pageIndex": 0
}
},
{
"description": {
"value": "Database-Live (2GB)",
"pageIndex": 0
},
"hours": {
"value": 744,
"pageIndex": 0
},
"start": {
"value": "01-01 00:00",
"pageIndex": 0
},
"end": {
"value": "01-31 23:59",
"pageIndex": 0
},
"unitPrice": {
"value": 20,
"pageIndex": 0
}
},
{
"description": {
"value": "Tasks-Dev (1GB)",
"pageIndex": 0
},
"hours": {
"value": 744,
"pageIndex": 0
},
"start": {
"value": "01-01 00:00",
"pageIndex": 0
},
"end": {
"value": "01-31 23:59",
"pageIndex": 0
},
"unitPrice": {
"value": 10,
"pageIndex": 0
}
}
]
}
]
}Copyright (c) 2018-2022 ByteScout, Inc.