This short tutorial explains how to replace text in PDF with C# REST API. You will learn to replace words in PDF with C# RESTful Service using a .NET-based Cloud SDK. It will guide you in finding words by comparing strings or using regex and perform this task on a single page or the entire PDF file.
Prerequisite
- Create an account API credentials to replace text inside a PDF
- Download Aspose.PDF Cloud SDK for Dotnet to replace text in a PDF file
- Setup C# project with the above SDK for finding and replacing text
Steps to Replace Text in PDF Online with C# REST Interface
- Configure the PdfApi object using the key and application SID to replace the text
- Upload the source PDF file into the Cloud storage for finding and replacing text
- Create the list of TextReplace objects with a pair of old and new strings
- Create the text replace request using the TextReplaceListRequest class by providing the TextReplace list
- Call the PostDocumentTextReplace to replace all the old strings with new strings
- Download the output file on the successful response from the API
The above steps describe how to find and replace word in PDF with C# REST API. Create the PdfApi object containing the features to work with a PDF file, upload the source PDF file to online Cloud storage, create a list of pairs of words of old and new strings, and create a request object using this pair of lists. Call the PostDocumentTextReplace() method to replace the listed words and save the output file.
Code to Find and Replace Text in PDF with C# .NET-based API
This code demonstrates the process to replace text in PDF file with C# REST Interface. You may use the list of strings or Regex expression while searching the strings in the complete document. If you want to replace text in a single page of the uploaded PDF file, use the PostPageTextReplace() method with the target page number.
This article has taught us to search and replace text in a PDF file. If you want to add a new page to a PDF file, refer to the article on Add new page in PDF with C# REST API.