highlight

Highlight text matching a regex pattern

Usage

pdftl <input> highlight [<spec>...] output <output>

Details

The highlight operation searches for text matching a regular expression and superimposes a highlight annotation over its exact visual coordinates.

Note: This operation requires the ‘pypdfium2’ library. If not installed, run: pip install pdftl[highlight].

A highlight specification (<spec>) has the format:

[optional page range]<delimiter><regex><delimiter>[<options>]

<delimiter> must be a single, non-alphanumeric character (e.g., /, !, #).

Options

Options are provided as a comma-separated list enclosed in parentheses at the end of the spec.

  • author: The author of the annotation (default: empty).

  • contents: Pop-up text associated with the highlight.

  • color: Space-separated RGB values, e.g., 1 1 0 for yellow (default).

  • print: yes or no. Whether the highlight prints (default: yes).

  • opacity: Float between 0.0 and 1.0.

Examples of specifications:

  • 1-3/CONFIDENTIAL/

  • /Jane Doe/(author=Legal, color=0 1 0)

  • odd!INV-\d{5}!(contents=Check this invoice, print=no)

Examples

Highlight all instances of “CONFIDENTIAL” on all pages

pdftl in.pdf highlight '/CONFIDENTIAL/' output out.pdf

Highlight specific invoice number formats on pages 1 through 5

pdftl in.pdf highlight '1-5/INV-\d{4,5}/' output out.pdf

Highlight in green, with custom author and pop-up note

pdftl in.pdf highlight '/URGENT/(author=Jane, color=0 1 0, contents=Fix this)' output out.pdf

Tags: in_place, text, annotations

Source: pdftl.operations.highlight

Read online: https://pdftl.readthedocs.io/en/stable/operations/highlight.html

Type: Operation