Replace Text - Facades

Replace Text in an Existing PDF File

In order to replace text in an existing PDF file, you need to create an object of PdfContentEditor class and bind an input PDF file using BindPdf method. After that, you need to call ReplaceText method. You need to save the updated PDF file using Save method of PdfContentEditor class. The following code snippet shows you how to replace text in an existing PDF file.

Check how it’s looks in the original document:

Replace Text

And check the result after replacing the text:

Result of replacing Text

In the second example, you will see how, in addition to replacing the text, you can also increase or decrease the font size:

For more advanced possibilities for working with our text, we will use the TextState method. With this method, we can make text bold, italic, colored, and so on.

In case you need to replace all the specified text in the document, use the following code snippet. That is, the replacement of the text will take place wherever the text specified for replacement will be encountered, and it will also count the number of such replacements.

Replace all Text

The following code snippet shows how to make all the text replacements but on a specific page of your document.

In the next code snippet, we will show how to replace, for example, a given number with the letters we need.