Link Search Menu Expand Document

PDF Search and Replace Text

Description: Search and replace text of your choice in a pdf file

Status Errors

CodeDescription
200The request has succeeded
400bad input parameters
401unauthorized
403not enough credits
405Timeout error. To process large documents or files please use asynchronous mode ( set async parameter to true) and then check the status using /job/check endpoint. If file contains many pages then specify a page range using pages parameter. The number of pages of the document can be obtained using the endpoint /pdf/info

Example 1: single text replacement

GET

https://api.pdf.co/v1/pdf/edit/replace-text?url=https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/pdf-split/sample.pdf&searchString=conspicuous&replaceString=replaced&x-api-key=YOUR-API-KEY

or

POST

{
  "url": "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/pdf-split/sample.pdf",
  "searchString": "conspicuous feature",
  "replaceString": "Replaced1",
  "caseSensitive": true,
  "name": "finalFile"
}

or

cURL (uploading your file along with the request)

curl -F "x-api-key=PASTE_YOUR_API_KEY_HERE" -F "searchString=conspicuous feature" -F "replaceString=Replaced1"  -F "file=@./sample.pdf" https://api.pdf.co/v1/pdf/edit/replace-text

Example 2: batch texts replacement

Sample Request:

! Don’t forget to set x-api-key url param or http header param (preferred) to API key, get yours here

POST

{
  "url": "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/pdf-split/sample.pdf",
  "searchStrings": [
    "conspicuous feature",
    "Martian"
  ],
  "replaceStrings": [
    "Replaced1",
    "Replaced2"
  ],
  "caseSensitive": true,
  "name": "finalFile"
}

Available methods

[POST] /pdf/edit/replace-text (mutliple replacements)

  • url required. URL to the source file. Supports links from Google Drive, Dropbox and from built-in PDF.co files storage. For uploading files via API please check Files Upload section. If you are randomly getting Too Many Requests or Access Denied error for your input url, please try to add cache: to enable built-in url caching.
  • searchStrings[] array of strings to search.
  • replaceStrings[] arrao of replacements strings.
  • caseSensitive optional. Set to false to use case-insensitive search.
  • name optional. File name for generated output. Must be a String.
  • password optional. Password of PDF file. Must be a String.
  • pages optional. Comma-separated list of page indices (or ranges) to process. IMPORTANT: the very first page starts at 0 (zero). To set a range use the dash -, for example: 0,2-5,7-. To set a range from index to the last page use range like this: 2- (from page #3 as the index starts at zero and till the of the document). For ALL pages just leave this param empty. Example: 0,2-5,7- means first page, then 3rd page to 6th page, and then the range from 8th (index = 7) page till the end of the document. Must be a String.
  • encrypt optional. Enable encryption for output file. Must be one of: true, false.
  • async optional. Runs processing asynchronously. Returns Use JobId that you may use with /job/check to check state of the processing (possible states: working, failed, aborted and success). Must be one of: true, false.
  • profiles optional. Must be a String. You can set additional and extra options using this parameter that allows you to set custom configuration. See profiles samples for examples.

Description

  • Method: POST
  • URL: /v1/pdf/edit/replace-text

Query parameters

No query parameters accepted.

Body payload

{
  "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" 
}

Example responses

/pdf/edit/replace-text
{
    "url": "https://pdf-temp-files.s3.amazonaws.com/5e02856782ea4f90b0c47c052565ae01/finalFile.pdf",
    "pageCount": 4,
    "error": false,
    "status": 200,
    "name": "finalFile",
    "remainingCredits": 98298
}

Code Snippets

CURL
curl --location --request POST 'https://api.pdf.co/v1/pdf/edit/replace-text' \
--header 'Content-Type: application/json' \
--header 'x-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" 
}'
JavaScript
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("x-api-key", "");

var raw = JSON.stringify({
 "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"
});

var requestOptions = {
	method: 'POST',
	headers: myHeaders,
	body: raw,
	redirect: 'follow'
};

fetch("https://api.pdf.co/v1/pdf/edit/replace-text", requestOptions)
	.then(response => response.text())
	.then(result => console.log(result))
	.catch(error => console.log('error', error));
NodeJs
var request = require('request');
var options = {
	'method': 'POST',
	'url': 'https://api.pdf.co/v1/pdf/edit/replace-text',
	'headers': {
		'Content-Type': 'application/json',
		'x-api-key': ''
	},
	body: JSON.stringify({
	 "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"
	})

};
request(options, function (error, response) {
	if (error) throw new Error(error);
	console.log(response.body);
});

PHP
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
	CURLOPT_URL => 'https://api.pdf.co/v1/pdf/edit/replace-text',
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => '',
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 0,
	CURLOPT_FOLLOWLOCATION => true,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => 'POST',
	CURLOPT_POSTFIELDS =>'{
  "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" 
}',
	CURLOPT_HTTPHEADER => array(
		'Content-Type: application/json',
		'x-api-key: '
	),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Java
import java.io.*;
import okhttp3.*;
public class main {
	public static void main(String []args) throws IOException{
		OkHttpClient client = new OkHttpClient().newBuilder()
			.build();
		MediaType mediaType = MediaType.parse("application/json");
		RequestBody body = RequestBody.create(mediaType, "{\r\n  \"url\": \"https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-text/sample.pdf\",\r\n  \"searchStrings\": [\r\n    \"Your Company Name\",\r\n    \"Client Name\"\r\n  ],\r\n  \"replaceStrings\": [\r\n    \"XYZ LLC\",\r\n    \"ABCD\"\r\n  ],\r\n  \"caseSensitive\": true,\r\n  \"pages\": \"\",\r\n  \"password\":\"\",\r\n  \"name\": \"finalFile\" \r\n}");
		Request request = new Request.Builder()
			.url("https://api.pdf.co/v1/pdf/edit/replace-text")
			.method("POST", body)
			.addHeader("Content-Type", "application/json")
			.addHeader("x-api-key", "")
			.build();
		Response response = client.newCall(request).execute();
		System.out.println(response.body().string());
	}
}

C#
using System;
using RestSharp;
namespace HelloWorldApplication {
	class HelloWorld {
		static void Main(string[] args) {
			var client = new RestClient("https://api.pdf.co/v1/pdf/edit/replace-text");
			client.Timeout = -1;
			var request = new RestRequest(Method.POST);
			request.AddHeader("Content-Type", "application/json");
			request.AddHeader("x-api-key", "");
			var body = @"{
" + "\n" +
			@"  ""url"": ""https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-text/sample.pdf"",
" + "\n" +
			@"  ""searchStrings"": [
" + "\n" +
			@"    ""Your Company Name"",
" + "\n" +
			@"    ""Client Name""
" + "\n" +
			@"  ],
" + "\n" +
			@"  ""replaceStrings"": [
" + "\n" +
			@"    ""XYZ LLC"",
" + "\n" +
			@"    ""ABCD""
" + "\n" +
			@"  ],
" + "\n" +
			@"  ""caseSensitive"": true,
" + "\n" +
			@"  ""pages"": """",
" + "\n" +
			@"  ""password"":"""",
" + "\n" +
			@"  ""name"": ""finalFile"" 
" + "\n" +
			@"}";
			request.AddParameter("application/json", body,  ParameterType.RequestBody);
			IRestResponse response = client.Execute(request);
			Console.WriteLine(response.Content);
		}
	}
}

Python
import requests
import json

url = "https://api.pdf.co/v1/pdf/edit/replace-text"

payload = json.dumps({
 "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"
})
headers = {
	'Content-Type': 'application/json',
	'x-api-key': ''
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Powershell
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$headers.Add("x-api-key", "")

$body = "{
`n  `"url`": `"https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-text/sample.pdf`",
`n  `"searchStrings`": [
`n    `"Your Company Name`",
`n    `"Client Name`"
`n  ],
`n  `"replaceStrings`": [
`n    `"XYZ LLC`",
`n    `"ABCD`"
`n  ],
`n  `"caseSensitive`": true,
`n  `"pages`": `"`",
`n  `"password`":`"`",
`n  `"name`": `"finalFile`" 
`n}"

$response = Invoke-RestMethod 'https://api.pdf.co/v1/pdf/edit/replace-text' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json

[POST] /pdf/edit/replace-text (single replacement)

  • url required. URL to the source file. Supports links from Google Drive, Dropbox and from built-in PDF.co files storage. For uploading files via API please check Files Upload section. If you are randomly getting Too Many Requests or Access Denied error for your input url, please try to add cache: to enable built-in url caching.
  • searchString required for single text replacement. Word or phrase to be replaced. Must be a String.
  • replaceString required for single text replacement. Word to be replaced with. Must be a String.
  • caseSensitive optional. Set to false to use case-insensitive search.
  • name optional. File name for generated output. Must be a String.
  • password optional. Password of PDF file. Must be a String.
  • pages optional. Comma-separated list of page indices (or ranges) to process. IMPORTANT: the very first page starts at 0 (zero). To set a range use the dash -, for example: 0,2-5,7-. To set a range from index to the last page use range like this: 2- (from page #3 as the index starts at zero and till the of the document). For ALL pages just leave this param empty. Example: 0,2-5,7- means first page, then 3rd page to 6th page, and then the range from 8th (index = 7) page till the end of the document. Must be a String.
  • encrypt optional. Enable encryption for output file. Must be one of: true, false.
  • async optional. Runs processing asynchronously. Returns Use JobId that you may use with /job/check to check state of the processing (possible states: working, failed, aborted and success). Must be one of: true, false.
  • profiles optional. Must be a String. You can set additional and extra options using this parameter that allows you to set custom configuration. See profiles samples for examples.

Description

  • Method: POST
  • URL: /v1/pdf/edit/replace-text

Query parameters

No query parameters accepted.

Body payload

keyvaluedescriptiondisabled 
x-api-key Optional. Please use http headers instead when possible because passing your API key as parameter for POST or GET is not secure and is for legacy app compatibility only.  
true    
async optional. Runs processing asynchronously. Returns Use JobId that you may use with /job/check to check state of the processing (possible states: working, failed, aborted and success). Must be one of: true, false.texttrue
encrypt optional. Enable encryption for output file. Must be one of: true, false.texttrue
urlhttps://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-text/sample.pdfrequired. URL of the source file. Must be a String. To use your file please upload it first to the temporary storage, see Upload and Manage Files section below to learn how to do it.text 
namefinalFileoptional. File name for generated output. Must be a String.text 
caseSensitivetrueoptional. true or false. Set to false by defaulttext 
searchStringYour Company Namerequired for single text replacement. Word to be replaced. Must be a Stringtext 
replaceStringXYZ LLCrequired for single text replacement. Word to be replaced with. Must be a Stringtext 
password optional. Password of PDF file. Must be a String.texttrue
pages optional. Comma-separated list of page indices (or ranges) to process. IMPORTANT: the very first page starts at 0 (zero). To set a range use the dash -, for example: 0,2-5,7-. To set a range from index to the last page use range like this: 2- (from page #3 as the index starts at zero and till the of the document). For ALL pages just leave this param empty. Example: 0,2-5,7- means first page, then 3rd page to 6th page, and then the range from 8th (index = 7) page till the end of the document. Must be a String.texttrue

Example responses

/pdf/edit/replace-text
{
    "url": "https://pdf-temp-files.s3.amazonaws.com/1a0e9a51e2d04fe4bcce0a6a31c365a8/finalFile.pdf",
    "pageCount": 4,
    "error": false,
    "status": 200,
    "name": "finalFile",
    "remainingCredits": 98310
}

Code Snippets

CURL
curl --location --request POST 'https://api.pdf.co/v1/pdf/edit/replace-text' \
--header 'x-api-key: ' \
--form 'url="https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-text/sample.pdf"' \
--form 'name="finalFile"' \
--form 'caseSensitive="true"' \
--form 'searchString="Your Company Name"' \
--form 'replaceString="XYZ LLC"'
JavaScript
var myHeaders = new Headers();
myHeaders.append("x-api-key", "");

var formdata = new FormData();
formdata.append("url", "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-text/sample.pdf");
formdata.append("name", "finalFile");
formdata.append("caseSensitive", "true");
formdata.append("searchString", "Your Company Name");
formdata.append("replaceString", "XYZ LLC");

var requestOptions = {
	method: 'POST',
	headers: myHeaders,
	body: formdata,
	redirect: 'follow'
};

fetch("https://api.pdf.co/v1/pdf/edit/replace-text", requestOptions)
	.then(response => response.text())
	.then(result => console.log(result))
	.catch(error => console.log('error', error));
NodeJs
var request = require('request');
var options = {
	'method': 'POST',
	'url': 'https://api.pdf.co/v1/pdf/edit/replace-text',
	'headers': {
		'x-api-key': ''
	},
	formData: {
		'url': 'https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-text/sample.pdf',
		'name': 'finalFile',
		'caseSensitive': 'true',
		'searchString': 'Your Company Name',
		'replaceString': 'XYZ LLC'
	}
};
request(options, function (error, response) {
	if (error) throw new Error(error);
	console.log(response.body);
});

PHP
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
	CURLOPT_URL => 'https://api.pdf.co/v1/pdf/edit/replace-text',
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => '',
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 0,
	CURLOPT_FOLLOWLOCATION => true,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => 'POST',
	CURLOPT_POSTFIELDS => array('url' => 'https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-text/sample.pdf','name' => 'finalFile','caseSensitive' => 'true','searchString' => 'Your Company Name','replaceString' => 'XYZ LLC'),
	CURLOPT_HTTPHEADER => array(
		'x-api-key: '
	),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Java
import java.io.*;
import okhttp3.*;
public class main {
	public static void main(String []args) throws IOException{
		OkHttpClient client = new OkHttpClient().newBuilder()
			.build();
		MediaType mediaType = MediaType.parse("text/plain");
		RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
			.addFormDataPart("url","https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-text/sample.pdf")
			.addFormDataPart("name","finalFile")
			.addFormDataPart("caseSensitive","true")
			.addFormDataPart("searchString","Your Company Name")
			.addFormDataPart("replaceString","XYZ LLC")
			.build();
		Request request = new Request.Builder()
			.url("https://api.pdf.co/v1/pdf/edit/replace-text")
			.method("POST", body)
			.addHeader("x-api-key", "")
			.build();
		Response response = client.newCall(request).execute();
		System.out.println(response.body().string());
	}
}

C#
using System;
using RestSharp;
namespace HelloWorldApplication {
	class HelloWorld {
		static void Main(string[] args) {
			var client = new RestClient("https://api.pdf.co/v1/pdf/edit/replace-text");
			client.Timeout = -1;
			var request = new RestRequest(Method.POST);
			request.AddHeader("x-api-key", "");
			request.AlwaysMultipartFormData = true;
			request.AddParameter("url", "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-text/sample.pdf");
			request.AddParameter("name", "finalFile");
			request.AddParameter("caseSensitive", "true");
			request.AddParameter("searchString", "Your Company Name");
			request.AddParameter("replaceString", "XYZ LLC");
			IRestResponse response = client.Execute(request);
			Console.WriteLine(response.Content);
		}
	}
}

Python
import requests

url = "https://api.pdf.co/v1/pdf/edit/replace-text"

payload={'url': 'https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-text/sample.pdf',
'name': 'finalFile',
'caseSensitive': 'true',
'searchString': 'Your Company Name',
'replaceString': 'XYZ LLC'}
files=[

]
headers = {
	'x-api-key': ''
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)

Powershell
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("x-api-key", "")

$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()
$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "url"
$stringContent = [System.Net.Http.StringContent]::new("https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-text/sample.pdf")
$stringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)

$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "name"
$stringContent = [System.Net.Http.StringContent]::new("finalFile")
$stringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)

$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "caseSensitive"
$stringContent = [System.Net.Http.StringContent]::new("true")
$stringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)

$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "searchString"
$stringContent = [System.Net.Http.StringContent]::new("Your Company Name")
$stringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)

$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "replaceString"
$stringContent = [System.Net.Http.StringContent]::new("XYZ LLC")
$stringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)

$body = $multipartContent

$response = Invoke-RestMethod 'https://api.pdf.co/v1/pdf/edit/replace-text' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json