import aspose.pdf as pdf # Load License license = pdf.License() license.set_license("Aspose.Total.lic") # Open the PDF document inputPDFFile = pdf.Document("input.pdf") # Instantiate a TextFragmentAbsorber object txtAbsorber = pdf.text.TextFragmentAbsorber("my_data") # Search text inputPDFFile.pages.accept(txtAbsorber) # Get reference to the found list textFragmentCollection = txtAbsorber.text_fragments # Parse all the searched text fragments for txtFragment in textFragmentCollection: txtFragment.text = "MY_DATA" # Save the output PDF inputPDFFile.save("output.pdf") print("Text found and replaced successfully")