How to Strike Out Text in Adobe PDF using Python

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

  1. Set the IDE to use Aspose.PDF for Python via .NET to strike out the text
  2. Load the source PDF file where some text is to be struck out using the Document class object
  3. Define the search word in the PDF using the TextFragmentAbsorber class object
  4. Run the visit() method on the target page to search the instances of the target word
  5. Create a StrikeOutAnnotation object using the rectangular area of the first instance of the searched word
  6. Set the color and title of the strike-out annotation before adding it to the annotations collection of the page
  7. 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.

 English