This quick tutorial guides you on how to strike out text in Adobe PDF using Python. It shares all the necessary steps to establish the environment and a list of steps to be followed along with the runnable sample code that demonstrates how to strike out in Adobe Acrobat using Python. You will learn the process to develop the application from the scratch using a few API calls along with the description of all the steps.
Steps to Strike Out Text in Adobe PDF using Python
- Set the IDE to use Aspose.PDF for Python via .NET to strike out the text
- Load the source PDF file where some text is to be struck out using the Document class object
- Define the search word in the PDF using the TextFragmentAbsorber class object
- Run the visit() method on the target page to search the instances of the target word
- Create a StrikeOutAnnotation object using the rectangular area of the first instance of the searched word
- Set the color and title of the strike-out annotation before adding it to the annotations collection of the page
- Save the resultant PDF file with the strike out on the first occurrence of the desired word
These steps define the process of how to strike out text in PDF using Python. It requires loading the target PDF file and then searching for the occurrences of the desired word that is to be stricken out on a particular page. Once the searching is done, the rectangular area of the first occurrence is used to instantiate a StrikeOutAnnotation object that will actually create a strike-out line on the text having the desired color, and the title if required.
Code to Strike Out Text in PDF using Python
This sample piece of code can be used as a basis for a complete application to strike out in Adobe Acrobat using Python. Use the TextFragmentAbsorber class for searching the target word on a particular page to get the list of all the occurrences of that word. In the next step, you have to create a StrikeOutAnnotation object within the rectangular area of the target occurrence so that the line is displayed within that enclosing rectangle.
This short guide has taught us to display strike-out lines on one or more words on a PDF page. If you want to learn the process to insert a table in a PDF, refer to the article on how to insert table in PDF using Python.