Replace Text in PDF with Java REST API

This short tutorial demonstrates how to replace text in PDF files using Java REST API, leveraging the Aspose.PDF Cloud SDK to locate words via string comparison or regular expressions and apply the changes to a single page or the entire document.

Prerequisite

Steps to Replace Text in PDF Online with Java REST Interface

  1. Configure the PdfApi object using the key and application SID to replace the text
  2. Upload the source PDF file into the Cloud storage for finding and replacing text
  3. Create the list of TextReplace objects with a pair of old and new strings
  4. Create the text replace request using the TextReplaceListRequest class by providing the TextReplace list
  5. Call the PostDocumentTextReplace endpoint to replace all the old strings with new strings
  6. Download the output file on the successful response from the API

The above steps describe how to find and replace words in a PDF with Java 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 old and new strings, and build a request object using this list. Call the PostDocumentTextReplace() method to replace the listed words and save the output file.

Code to Find and Replace Text in PDF with Java-based API

This code demonstrates the process to replace text in a PDF file with Java REST Interface. You may use a list of strings or a regex expression while searching the document. If you want to replace text on a single page of the uploaded PDF file, use the PostPageTextReplace() method with the target page number.

If you want to add a new page to a PDF file, refer to the article on Add new page in PDF with Java REST API.

Keywords: replace text in pdf with Java REST API; replace words in pdf with Java RESTful Service; find and replace word in pdf with Java REST API; replace text in pdf file with Java REST Interface.