Python Forum

Full Version: Find, delete and add text into pdf file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dear forum users!

There is a pdf file, it is necessary to delete certain text in it. Then add new text below to the existing one.
I'm trying to use the PyMuPDF library - fitz. Open the file, set the text to search, but I did not find how to delete it and add new text.
Please could you help me how to delete the found text and add to the existing one.
Using libraries is not important, we can use PyPDF2 and others.
The sample pdf file with description is attached.
import fitz
 
doc = fitz.open(MyFilePath)
page = doc[0]
 
text1 = “ANA”
text_instances1 = page.searchFor(text1)
 
# found text should be deleted …
 
text_to_add = “Text”
text2 = “TAIL NO.”
text_instances2 = page.searchFor(text2)
 
# should be added "text_to_add" after found text "text2"
 
doc.save(OutputFilePath, garbage=4, deflate=True, clean=True)
you have obviously read some of the package functionality to get this far, it might be easier to explain what isn't happening and let a solution be found, or is it a case of none of the above code works for you at all?
(Jul-08-2020, 10:39 AM)nuffink Wrote: [ -> ]code works for you at all?
code working in part of opening, finding required text and save however I need also delete some text and add new one. For this part I'm asking help :)

[Image: view?usp=sharing]