pageIndex and a
boundingBox as [x, y, width, height] in points (see the Bounding Box Guide).
But they are nested inside the search result, and Redact expects one flat redactions list, so the
search result can’t be sent to Redact as it is. Doing so is rejected with a 422 error.
From search result to redactions
The search result groups boxes by query, then by match:- Take every box from
textBoxes[].matches[].boxes[], across all queries and all matches. A match that spans several lines has one box per line, so keep them all. - Keep each box’s
pageIndexandboundingBox. You can add alabelif you want text drawn on the redaction box. - Ignore
groups. Their boxes cover parts of the match, which the match’s own boxes already cover. - Send the list as
{"redactions": [...]}.
The search result is under
result in a JSON response and in an asynchronous job’s result. When you
download the result as a file (Accept: application/octet-stream), textBoxes is at the top level
instead. The Python and JavaScript functions below take the object that holds textBoxes: pass
result from a JSON response, or the downloaded file’s content as it is.Examples
Each example removes duplicate boxes. They only occur when two of your queries match the same text, for example a keyword listed twice, or a literal query and a regular expression that find the same value. Redact would accept the duplicates, but there is no reason to send them.Power Automate
In Power Automate, Extract searched Text from PDF returns the nested result, and Redact PDF Pages takes the redactions as two lists, Redaction Pages and Redaction Boxes, matched by position. To connect them:1
Collect the boxes
Add Initialize variable with name
boxes and type Array. Then nest three Apply to
each loops:- over
body('Extract_searched_Text_from_PDF')?['result']?['textBoxes'] - inside it, over
items('Apply_to_each')?['matches'] - inside that, over
items('Apply_to_each_2')?['boxes']
boxes with the value
items('Apply_to_each_3').2
Build Redaction Pages
Add a Select with From
variables('boxes'). Switch Map to text mode and enter
item()?['pageIndex']. Set Redaction Pages on Redact PDF Pages to
join(body('Select'), ',').3
Build Redaction Boxes
Add a second Select with From
variables('boxes'). Switch Map to text mode and
enter join(item()?['boundingBox'], ','). Set Redaction Boxes on Redact PDF Pages to
join(body('Select_2'), ';').4
Skip empty results
Put Redact PDF Pages inside a Condition that checks
length(variables('boxes')) is
greater than 0, so a search with no matches doesn’t call Redact with empty lists.Apply_to_each_2, Select_2, …) must match the names in your
flow. If two of your queries can match the same text, the lists may contain the same box twice.
Redact accepts that, so there is no need to remove them in a flow.
In Zapier, Text Bounding Box Extract From PDF already returns a flat Redactions JSON field
you can map straight into Redact PDF — see
Working with files.
Good to know
- Redacting only part of a match. For a regular expression with capture groups, each match
also has
groups, each with its ownboxes. To redact only the captured part, such as the amount inTotal: \$(\d+\.\d{2}), take the boxes frommatches[].groups[].boxes[]instead ofmatches[].boxes[]. - Labels. If you add a
label, don’t usematchedTextortextPiecefor it: the label is drawn on the redaction box, so it would print the redacted text back onto the page. - Overlapping queries. A shorter query inside a longer one (
DoeandJohn Doe) returns a smaller box inside the bigger one. Both are kept, which is harmless. - Matching rules. Literal queries are case-sensitive. To match regardless of case, use a regular
expression with the
ignore-caseflag — see Text Bounding Boxes. - Text split across lines. A literal query such as
John Doedoesn’t match when the line breaks betweenJohnandDoe. To catch those too, use a regular expression with\sbetween the words (John\sDoe); the match then has one box per line, and the steps above redact both.