Why Use PDF Search API?

The PDF.co PDF Search API can help you replace a specific text inside your PDF with another text or an image.

All the documents sent through our Web API are encrypted and secure. We use SSL, TLS, and file encryption security to protect your data. To learn more, please read our security page https://pdf.co/security

PDF Search API Benefits

Text and Image Replacement Support

PDF Search API can search text and replace it with another text or image. The search can be narrowed down to specific pages and page range or do a whole document search.

On-Premise Server for Enterprise

We have an on-premise server that enables businesses and enterprises to run the PDF.co Web API modules to their on-premise servers. This provides them with more control over file storage and additional customizations.

PDF Search API Sample & Demo

We’ll be using this sample PDF that we prepared for this demo.

Screenshot of Sample PDF
Screenshot of Sample PDF

Using the code snippets below in different programming languages. We can replace a text inside the sample PDF with another text or an image.

The result will look like this.

Screenshot of the Output PDF
Screenshot of the Output PDF

Before we proceed with the code. Let us first check the v1/pdf/edit/replace-text parameters and their uses.

Endpoint

URL: https://api.pdf.co/v1/pdf/edit/replace-text
Method: POST
Parameter Description
url required. Link to the source file.
searchStrings[] required. array of strings to search.
replaceStrings[] required. array of replacement strings.
caseSensitive optional. Set to false to use case-insensitive search.
pages optional. Comma-separated list of page indices (or ranges) to process. IMPORTANT: the very first page starts with (zero). To set a range use the dash , for example: 0, 2-5, 7-.
expiration optional. Output link expiration in minutes. Default is 60 (i.e. 60 minutes or 1 hour). After this delay generated output file(s) (if any) will be auto-removed from PDF.co temporary files storage. Max allowed expiration period depends on your current subscription plan. To store permanent input files (e.g. re-usable images, pdf, documents), please use PDF.co built-in Files Storage instead.
encrypt optional. Enable encryption for the output file: true or false
async optional. Runs processing asynchronously. Returns jobId to use with job/checktrue or false
name optional. Output file name.
profiles optional. Must be a String. Set custom configuration. See profiles examples here

Now we are ready to write some codes.

cURL Code Snippet

curl --location --request POST 'https://api.pdf.co/v1/pdf/edit/replace-text' \
--header 'Content-Type: application/json' \
--header 'x-api-key: YOUR_API_KEY' \
--data-raw '{
"url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-text/sample.pdf",
"searchStrings": [
"Your Company Name",
"Client Name"
],
"replaceStrings": [
"XYZ LLC",
"ABCD"
],
"caseSensitive": true,
"pages": "",
"password":"",
"name": "finalFile" 
}'

This sample code and other cURL sample codes are available here.

Now let’s see this program in action.

Output PDF using cURL
Output PDF using cURL

The Sample code for replacing text in JavaScript is available here.

The Sample code for replacing text in PHP is available here.

The Sample code for replacing text in Python is here.

The Sample code for replacing text in Java is available here.

The Sample code for replacing text in C# is available here.

Related Samples: