Skip to main content
A common flow is “find this text, then redact it”: search a PDF with the Text Bounding Boxes method, then pass the boxes it found to the Redact method. The boxes the search returns already have what Redact needs — a zero-based 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:
To turn it into Redact parameters:
  1. 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.
  2. Keep each box’s pageIndex and boundingBox. You can add a label if you want text drawn on the redaction box.
  3. Ignore groups. Their boxes cover parts of the match, which the match’s own boxes already cover.
  4. Send the list as {"redactions": [...]}.
For the result above, the Redact parameters are:
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.
If the search found nothing, the list is empty: skip the Redact call and keep the original file.

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']
In the innermost loop, add Append to array variable 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.
Action names in the expressions (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 own boxes. To redact only the captured part, such as the amount in Total: \$(\d+\.\d{2}), take the boxes from matches[].groups[].boxes[] instead of matches[].boxes[].
  • Labels. If you add a label, don’t use matchedText or textPiece for 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 (Doe and John 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-case flag — see Text Bounding Boxes.
  • Text split across lines. A literal query such as John Doe doesn’t match when the line breaks between John and Doe. To catch those too, use a regular expression with \s between the words (John\sDoe); the match then has one box per line, and the steps above redact both.