modify_pdf_content
Find and replace text in PDF files while preserving original font styling. Supports regex, hyperlinks, and page ranges for targeted modifications.
Instructions
Find and replace text in a PDF while preserving font styles.
This tool performs text replacement by:
Locating all occurrences of the search text
Redacting the original text (white fill)
Inserting the replacement text with matched styling
IMPORTANT BEHAVIORS:
Text is matched within individual text spans
Font style is approximated using Base 14 fonts (Helvetica, Times, Courier)
Replacement text should be similar length to avoid overlap
Multiple replacements can be specified in a single call
HYPERLINK SUPPORT:
Append "|URL" to create a clickable link: "Click Here|https://example.com"
Use "|void(0)" to neutralize existing links: "Product|void(0)"
REGEX SUPPORT:
Set use_regex=true to treat keys as regex patterns
Useful for matching dates, IDs, or variable content
Example: {"Order #\d+": "Order #REDACTED"}
PAGE RANGE:
Use pages="1-3" to process only pages 1 through 3 (1-indexed, inclusive)
Use pages="5" to process only page 5
Omit to process all pages
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input_path | Yes | Absolute path to the source PDF file. | |
| output_path | Yes | Absolute path where the modified PDF will be saved. Parent directory must exist. | |
| replacements | Yes | Dictionary mapping old text to new text. Keys are search strings (or regex if use_regex=true). Values are replacement strings (optionally with |URL). | |
| use_regex | No | If true, treat replacement keys as regex patterns. Default is false for literal string matching. | |
| password | No | Optional password if the source PDF is encrypted. | |
| pages | No | Optional page range, e.g. "1-3" or "5". Defaults to all pages. | |
| max_file_size | No | Maximum allowed input file size in bytes (default: 100 MB). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |