Macros for text, built-in macros and using custom data for custom macros for auto text replacement#
You can use built-in and custom macros inside text when using the /pdf/edit/add endpoint or Fill PDF
or Add Text and Images to PDF
modules in Zapier, Make and others.
Macros may look like this: {{$$newLine}}
, [[$$newLine]]
or {{object.property}}
(when referencing custom data from JSON
).
Built-in macros#
Built-in macros always use $$
prefix.
Available built-in macros#
{{$$PageNumber}}
outputs current page number (starts with1
).{{$$PageCount}}
will be outputting page count astxt
.{{$$newLine}}
will be replaced with a new line.
Special macros style switch from curly brackets to square brackets (for use in Zapier, Make and other integrations.)#
Some popular automation platforms use {{ .. }}
style macros for their internal purpose.
To fix this you can use [[ ..]]
square brackets instead. Just add the command ##replaceSquareBracketsToCurlyBrackets##
at the beginning of the text (just once).
For example, use this:
##replaceSquareBracketsToCurlyBrackets##[[macro1]]
instead of:
{{macro1}}
Custom macros#
You can also put JSON
with custom data into a templateData
property. Then you can use data from this JSON
as {{name}}
or {{object.property}}
macros (or as [[name]]
or [[object.property]]
if you enabled square brackets to curly conversion too)
v1/pdf/edit/add#
{
"url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-edit/sample.pdf",
"templateData": "{ \"firstName\": \"John\", \"lastName\": \"Doe\", \"age\": 26, \"address\": { \"streetAddress\": \"Market Street\", \"city\": \"San-Francisco\", \"postalCode\": \"94100\" }, \"phoneNumbers\": [ { \"type\": \"iPhone\", \"number\": \"0123-4567-8888\" }, { \"type\": \"home\", \"number\": \"0123-4567-8910\" } ]}",
"annotations": [
{
"text": "{{firstName}} {{lastName}}\n{{address.streetAddress}}{{$$newLine}}{{phoneNumbers[0].number}}",
"x": 250,
"y": 100,
"width": 150,
"height": 100,
"size": 12,
"pages": "0-",
"type": "TextFieldMultiline",
"id": "multiline1"
},
{
"text": "##replaceSquareBracketsToCurlyBrackets##Company: [[firstName]][[$$NewLine]][[lastName]]",
"x": 50,
"y": 50,
"size": 12,
"pages": "0-"
}
]
}
Note
JSON
loaded into .templateData
should be escaped (with JSON.stringify(dataObject)
in JS). Escaping is when every "
is replaced with \"
(most programming languages do this automatically).
Non-escaped JSON
:
"templateData": "{ 'paid': true, 'invoice_id': '0002', 'total': '$999.99' }"
Escaped JSON
(with "
be escaped as \"
):
"templateData": "{ \"paid\": true, \"invoice_id\": \"0002\", \"total\": \"$999.99\" }"
Custom Pragma#
You can disable HTML
rendering support using pragma at the beginning of text.
v1/pdf/edit/add#
{
"url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-edit/sample.pdf",
"annotations":[
{
"text":"##disableHtmlFormatting##html formatting disabled: <b>bold</b>, <u>underline</u> and <i>italic</i> styles.",
"x": 10,
"y": 10,
"size": 12,
"pages": "0-"
},
{
"text":"html formatting auto enabled: <b>bold</b>, <u>underline</u> and <i>italic</i> styles.",
"x": 10,
"y": 25,
"size": 12,
"pages": "0-"
}
]
}