Find and Replace Text - Content Editor API
PDF4me Find and Replace Text enables you to find and replace specific text patterns in PDF documents. This API service processes PDF files and searches for text to replace with new content on specified pages. The API receives PDF content and replacement parameters through REST API calls, utilizing Base64 encoding for secure transmission. With support for flexible page targeting and text pattern matching, this solution is ideal for document updates and content management workflows.
Authenticating Your API Request
To access the PDF4me REST API, every request must include proper authentication credentials. Authentication ensures secure communication and validates your identity as an authorized user of the REST API.
Key Features
- Text Pattern Matching: Find and replace specific text patterns in PDF documents
- Flexible Page Targeting: Process specific pages or entire documents with custom page sequences
- Page Sequence Support: Target individual pages, page ranges, or mixed page selections
- Base64 Encoding: Secure file content transmission using Base64 encoding
- Simple API Integration: RESTful API designed for automated PDF text editing workflows
REST API Endpoint
The PDF4me REST API uses standard HTTP methods to interact with resources. All text find and replace operations are performed through a single endpoint:
- Method: POST
- Endpoint:
/api/v2/FindAndReplace
REST API Parameters
Complete list of parameters for the Find and Replace Text REST API. Parameters are organized by category for better understanding and implementation.
Important: Parameters marked with an asterisk (*) are required and must be provided for the API to function correctly.
Required Parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
| docContent* | Base64 | The content of the input PDF file encoded in Base64 | JVBERi... |
| docName* | String | Source PDF file name with .pdf extension | output.pdf |
| oldText* | String | Text to be searched and replaced | This is some |
| newText* | String | Text to replace with | Here is few |
| pageSequence* | String | Page options: "1" for page 1, "1,3,5" for specific pages, "2-5" for page range, "1,3,7-10" for mixed, "1-" for pages from 1 to end | 1 |
Optional Parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
| async | Boolean | Enable asynchronous processing. When true, the API returns a 202 status and provides a polling URL in the Location header | true |
Output
The PDF4me Find and Replace Text REST API returns different responses based on the processing mode. The API returns the PDF as binary data for synchronous processing or provides a polling URL for asynchronous processing.
- Success Response
- Asynchronous Processing
- Error Responses
- Response Format Details
Synchronous Processing (Default)
When async is not set or set to false, the API processes the request immediately:
Status Code: 200 OK
Content-Type: application/pdf or application/octet-stream
Response Body:
The API returns the PDF file directly as binary data (not JSON).
How to Use:
- The response body contains the binary PDF data
- Save the response content directly as a PDF file
- No Base64 decoding is needed for binary responses
Example (JavaScript):
const response = await fetch(url, options);
const pdfBlob = await response.blob();
// Save or process pdfBlob directly
Asynchronous Processing
When async: true is set, the API processes the request asynchronously:
Status Code: 202 Accepted
Response Headers:
Location: https://api.pdf4me.com/api/v2/FindAndReplace/poll/12345-abcde-67890
Polling Process:
- Extract the
Locationheader from the 202 response - Poll the URL using GET requests
- Continue polling until you receive a 200 OK status
- The final response contains the binary PDF data
Polling Example:
// Initial request returns 202 with Location header
const response = await fetch(url, options);
const location = response.headers.get('Location');
// Poll until complete
while (true) {
const pollResponse = await fetch(location, { headers: { 'Authorization': 'Basic ' + apiKey } });
if (pollResponse.status === 200) {
const pdfBlob = await pollResponse.blob();
// Process binary PDF
break;
}
await new Promise(resolve => setTimeout(resolve, 2000)); // Wait 2 seconds
}
Error Responses
| Status Code | Description | Example Response |
|---|---|---|
| 400 Bad Request | Invalid request parameters or missing required fields | {"error": "Missing required parameter: oldText"} |
| 401 Unauthorized | Invalid or missing API key | {"error": "Unauthorized"} |
| 500 Internal Server Error | Server error during processing | {"error": "Internal server error"} |
Understanding the Response
- Synchronous (200): Returns binary PDF data directly
- Asynchronous (202): Returns Location header for polling, final response is binary PDF
- No JSON Wrapper: The API returns PDF as binary, not wrapped in JSON with Base64 encoding
Request Example
Header
Content-Type: application/json
Authorization: Basic YOUR_BASE64_ENCODED_API_KEY
Note: The API key must be Base64 encoded. Get your API key from the PDF4me Dashboard
Payload
{
"docContent": "JVBERi...",
"docName": "output.pdf",
"oldText": "input_old_text",
"newText": "output_new_text",
"pageSequence": "1"
}
Code Samples
The PDF4me Find and Replace Text REST API provides code samples in multiple programming languages. Choose the language that best fits your development environment:
- C#
- Java
- JavaScript
- Python
- Salesforce
- n8n
- Google Script
- AWS Lambda
Google Script Sample
Google Apps Script implementation for Google Workspace integration:
Text Replacement Features
Text Pattern Processing
- Exact Matching: Case-sensitive text pattern matching for precise identification
- Pattern Recognition: Support for specific words, phrases, and text patterns
- Custom Patterns: Flexible pattern creation for specific text replacement requirements
- Professional Results: Reliable text replacement with accurate pattern matching
- Advanced Processing: Support for complex text structures and formatting
Page Processing
- Page Targeting: Replace text on specific pages or entire documents
- Page Sequences: Support for custom page ranges and individual page selection
- Flexible Processing: Process any combination of pages with precise control
- Batch Processing: Handle multiple pages efficiently in single API calls
- Professional Layout: Consistent text replacement across all target pages
Advanced Features
- Text Analysis: Comprehensive text pattern analysis and identification
- Content Management: Advanced content editing and text replacement options
- Professional Editing: High-quality text replacement with clear visibility
- Flexible Patterns: Support for any text pattern and replacement requirements
Industry Use Cases & Applications
- Business & Enterprise
- Legal & Professional Services
- Finance & Banking
- Government & Compliance
Business & Enterprise Use Cases
- Document Updates: Automatically update text content across multiple PDF documents
- Content Management: Replace outdated information with current data in PDF files
- Template Processing: Update placeholder text with actual content in document templates
- Brand Management: Update company names, logos, and branding elements across PDFs
Legal & Professional Services Use Cases
- Legal Document Editing: Replace specific terms and clauses in legal PDF documents
- Contract Updates: Update contract terms and clauses across legal documents
- Compliance Updates: Replace regulatory information and compliance data in documents
- Legal Document Standardization: Standardize legal terminology across documents
Finance & Banking Use Cases
- Report Generation: Update metrics, dates, and data points in generated PDF reports
- Financial Document Updates: Update financial information in PDF documents
- Compliance Updates: Replace regulatory information in financial documents
- Financial Report Standardization: Standardize financial terminology across reports
Government & Compliance Use Cases
- Compliance Updates: Replace regulatory information and compliance data in documents
- Regulatory Documentation: Update regulatory information in government documents
- Document Standardization: Standardize terminology and formatting across document collections
- Public Records: Update information in public records and government documents