Replace PDF Text

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.
Build Your Solution

You have document processing problems, we have Solutions. Explore the many ways pdfRest can align your documents with your business objectives.

Browse all solutions
Ensure GDPR Compliance for PDF Processing with EU-Based Cloud API
Ensure GDPR Compliance for PDF Processing with EU-Based Cloud API
The pdfRest logo is added to the Microsoft Power Automate logo with a representation of a PNG to PDF conversion workflow
Integrate pdfRest with Microsoft Power Automate
The Salesforce logo with APEX programming language is connected with the pdfRest logo around a PDF toolkit icon
Integrate PDF API Tools with Salesforce Apex Code
Why is pdfRest the best API to replace PDF text?
pdfRest offers the best solution for replacing PDF text because it supports multiple replacement rules, gives you control over text layout, and lets you edit individual search matches.

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.

  1. 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.
  2. 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.
  3. 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.

Start from Code Examples
See more code examples in our GitHub repository

Need more help?

Start with a Tutorial for step-by-step guidance

Customize Your Solution

Learn about the parameters for this tool to create your custom solution.

Replacements

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.

Frequently Asked Questions
Need more help? Contact Us or visit our documentation.

Replace PDF Text updates existing text in PDF documents. Use direct rules to change consistent wording, such as a department label, or send selected matches with individual replacement values. For example, a facilities application can revise room names in a building guide and choose a layout mode based on the space each new label needs. The API produces a PDF with the requested edits.

Start with a single rule that changes a known label in a sample PDF. Open the output to see how the new wording fits, then try a layout mode that suits a longer replacement.

To test POST /pdf-with-replaced-text directly, get a pdfRest API key and send a request from your HTTP client using the Api-Key header. To explore browser-based requests for supported tools, open the API Lab. The cURL example shows a complete request for Replace PDF Text.

Upload a local PDF in the multipart file field, or pass the id of a PDF already uploaded to pdfRest. To use a JSON request body, send the resource ID together with your operation parameters. For example, you can send a PDF through Upload Files once and use its ID for multiple requests without transferring the same file each time.

The operation creates a PDF with the requested text changes. Use the output information to download it or pass the output resource ID to another pdfRest tool. For example, a document workflow can send that ID to Compress PDF before delivering the resulting PDF to users. You can set the output filename without its extension using output.

Replace PDF Text works with text embedded in the PDF, including a text layer produced by OCR. A page that contains only a scanned image needs a text layer before the tool can find words on it. First process the file with OCR PDF, then pass the resource ID of the OCR output. If you plan to use search selections afterward, generate them from that same OCR output.

Send an HTTP POST to /pdf-with-replaced-text with your API key, the PDF input, and the operation parameters. Start with replacements for a request that defines what to find or process. Any language with an HTTP client can call the endpoint. Use the Cloud API Reference for authentication, request formats, and resource handling, then keep the API key on your server when building a browser-facing application. The pdfRest code samples on GitHub show request patterns in several languages.

Send a replacements array with one rule for each change. A rule pairs a search definition with its new text and can also include layout and page settings. For example, one rule can look for an exact department name and another can match legacy equipment labels with a custom regex. Each rule applies its replacement text to the matches it finds.

First locate matches with Search PDF or AI Search PDF. Keep the intended matches and add the new wording as replacement on each one. Submit the selections with the same PDF used in the search and preserve the source text and coordinates. For example, an application can look up the new name for each room and replace the selected labels without giving every room the same name.

Choose a layout mode based on the position and length of the new text:

  • Reflow rearranges text within its existing text object.
  • Shrink to fit reduces the new text’s font size when necessary.
  • Reject requires the full replacement to fit at the original font size.
  • Clip keeps the part that fits.
  • Wrap continues the replacement onto available lines.
  • Overwrite allows the replacement to replace following text in the same text object.

For a fixed label, shrink to fit can accommodate a longer name. For a paragraph, reflow can make room within the text object.

For direct replacements, set pages in the request to apply one page range to all rules, or set it within individual rules if the ranges differ. For example, update a title on page 1 with one rule and a footer label on pages 2 through the end with another. A request that uses selections already obtains its page locations from the retained matches.

Selections identify original text at particular page coordinates. Submit them against the unchanged PDF used to generate those results, and keep the original match text and geometry intact. If an earlier edit changed the document, run a fresh search on that version with Search PDF or AI Search PDF. This gives the next replacement request locations that correspond to the PDF it will edit.

The API uses the supplied text and geometry to identify and validate what it will edit. For each retained match, keep the original text and add the new text in replacement. If an evaluation search masked part of the original text, that masked value cannot validate the source text for replacement. A direct rule with your own search criteria is another way to test a known update.

Use Replace PDF Text to revise visible wording, such as a product name or an incorrect label. Use Redact PDF when the task is to remove sensitive information before sharing a document. For example, replacing an office label handles a document update, while removing personal details from a disclosure copy calls for the redaction workflow. Both tools can use selected results from a preceding search.

The selected layout mode governs how the API handles the extra text. Reflow can rearrange text within a paragraph or cell, and shrink to fit can reduce the new text size within the original space. If the font size must stay fixed, reject mode requires the new text to fit before applying the change. The right choice depends on the available space and whether surrounding text can move.

Generate a self-service API Key now!
Create your FREE API Key to start processing PDFs in seconds, only possible with pdfRest.