
Replace PDF Text
Replace PDF Text is a REST API tool that changes text in a PDF using explicit search-and-replacement rules or selected matches identified by your application. Define each replacement and choose how replacement text fits the existing page layout, including reflow, shrink-to-fit, clipping, wrapping, or overwrite behavior where supported. Use direct rules for known text, or pass reviewed findings from Search PDF or AI Search PDF for occurrence-specific changes.
Key Benefits of Replace PDF Text API
- Replace known text through explicit search and replacement rules, with multiple rules supported in one request.
- Use selected results from Search PDF or AI Search PDF when each occurrence needs an individual review or replacement.
- Set replacement text for each retained occurrence to handle names, dates, identifiers, or other values individually.
- Choose a layout mode to define how replacement text behaves when its length differs from the original text.
- Limit replacement processing to selected pages when using direct replacement rules.
- Build targeted PDF update workflows by connecting discovery, review, and text replacement through your application.
Start right from your browser - upload files, choose parameters, generate code, and send API Calls directly from API Lab!
You have document processing problems, we have Solutions. Explore the many ways pdfRest can align your documents with your business objectives.
Find and Replace PDF Text with Multiple Rules
When you know what needs to change, send the search criteria and replacement text in the same request. Each rule specifies what to find and what should appear in its place:
- Exact text: Update a known product name or department label wherever the old wording appears.
- Built-in presets: Replace text that follows a common format, such as swapping email addresses for a shared contact address in a document used for training.
- Custom regular expressions: Match an internal format, such as equipment labels beginning with
EQ-PUMP-and ending with three digits, and replace each match with the same placeholder.
Combine rules to update several values in one request. You can also use page ranges to apply a rule only in the section where its wording should change.
Choose How Replacement Text Fits the PDF
An updated label may need more space than the original. Choose a layout mode based on where the text appears and how much of the surrounding layout can move:
- Reflow rearranges text within the existing text object, such as a paragraph or table cell, to accommodate a change.
- Shrink to fit reduces the font size if needed to fit the replacement in the space occupied by the original text.
- Reject keeps the original font size and applies the change only if the full replacement fits.
For example, use reflow for a longer department name in a paragraph and shrink to fit for the same name in a fixed label. Other modes support clipping the replacement, wrapping it into available space, or allowing it to overwrite following text.
Replace Individual PDF Search Matches
A single find-and-replace rule works when every match should receive the same new text. When occurrences need different edits, start with Search PDF or AI Search PDF and use the findings to prepare individual replacements.
- Find the candidate text. For a building guide, search for room labels by their existing format and get the text and page locations for each match.
- Assign the new values. Keep the rooms that were renamed and use a lookup table to assign the right new name to each retained match.
- Apply the replacements. Submit the selections with the same PDF you searched. Include the new text with each match and keep its original text and coordinates intact.
This approach updates the selected labels while leaving the rooms that kept their names as they are.
Need more help?
Start with a Tutorial for step-by-step guidance
Learn about the parameters for this tool to create your custom solution.
The replacements parameter accepts a nonempty array of find-and-replace rules. Each rule contains a search object and a replacement string. Use literal for exact text, preset for a built-in pattern such as email addresses, or regex for a custom format such as an internal equipment code.
Example rule
{
"search": {"type": "literal", "value": "North Office"},
"replacement": "Regional Office",
"layout_mode": "reflow",
"pages": "2-4"
}
An optional layout_mode determines how each rule handles the available space:
reflow(default): Rearrange text within the same text object.reject: Keep the original font size and fail if the full replacement does not fit.shrink_to_fit: Reduce the font size if needed to fit the available space.clip: Keep the portion that fits at the original font size.wrap: Continue into available space on additional lines while leaving other text in place.overwrite: Allow the replacement to overwrite following text in the same text object.
Choose either request-level or per-rule pages. Send the rules as an array in JSON or as a JSON-encoded array string in multipart. Use selections instead when you already have individual matches to edit.
Safe & Secure
Confidently process your sensitive data with pdfRest. Our platform is built for robust, Enterprise-grade security and compliance. We meet rigorous standards for GDPR and HIPAA, and our controls are independently audited to ensure strict SOC 2 Type 2 compliance. Your data's protection is our commitment.

