This quick tutorial explains how to strike out text in PDF using C#. It contains information about all the necessary resources, a step-wise process, and a runnable sample code to strike out text in Adobe PDF using C#. It shares process details such that loading the PDF file, searching for target text on the page, and then striking out it with the desired color.
Steps to Strike Out Text in PDF using C#
- Establish the environment to add Aspose.PDF for .NET to strike out text in PDF
- Load the target PDF file having some sample text in it using the Document class object
- Declare a TextFragmentAbsorber class object by providing the target text to search
- Parse the desired page and find all the text fragments in it
- Create a StrikeOutAnnotation object to strike out the target text fragments found on the page
- Add this annotation to the annotations collection on the page and save the PDF
These steps describe how to strike out in Adobe Acrobat using C#. All the important classes, methods and properties are identified and used in a well-defined sequence to achieve the desired output like Document class is used for loading the Pdf file, the TextFragmentAbsorber class is used for searching the desired text in the PDF, the StrikeOutAnnotation class is used to create a strike out annotation for the text and then this annotation is added to the annotations collection of the selected page.
Code to Strike Out Text in PDF using C#
The above code demonstrates how to strike out text in Adobe PDF using C#. It uses TextFragmentAbsorber class object that creates an object for performing a search that is further used to search the text on the first page of the target PDF file. Once the collection of text fragments is obtained using the TextFragmentAbsorber.Visit() method, now we are ready to create a StrikeOutAnnotation object for any of the text fragments by providing the annotation title and color.
This tutorial has guided us to strike out particular text in a PDF. If you want to learn the process to highlight a text in a PDF, refer to the article on how to search text and highlight in PDF using C#.