Python Forum
Find, delete and add text into pdf file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find, delete and add text into pdf file
#1
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)
Reply
#2
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?
Regards
-------- *
“Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read.”
Reply
#3
(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]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  FileNotFoundError: [WinError 2] The system cannot find the file specified NewBiee 2 1,490 Jul-31-2023, 11:42 AM
Last Post: deanhystad
  Cannot find py credentials file standenman 5 1,553 Feb-25-2023, 08:30 PM
Last Post: Jeff900
  selenium can't find a file in my desk ? SouAmego22 0 701 Feb-14-2023, 03:21 PM
Last Post: SouAmego22
  Pypdf2 will not find text standenman 2 877 Feb-03-2023, 10:52 PM
Last Post: standenman
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,061 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Find (each) element from a list in a file tester_V 3 1,155 Nov-15-2022, 08:40 PM
Last Post: tester_V
  read a text file, find all integers, append to list oldtrafford 12 3,367 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  what will be the best way to find data in txt file? korenron 2 1,126 Jul-25-2022, 10:03 AM
Last Post: korenron
  Delete multiple lines from txt file Lky 6 2,201 Jul-10-2022, 12:09 PM
Last Post: jefsummers
  Delete empty text files [SOLVED] AlphaInc 5 1,510 Jul-09-2022, 02:15 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020