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
  [solved] how to delete the 10 first lines of an ascii file paul18fr 7 2,183 Aug-07-2024, 08:18 PM
Last Post: Gribouillis
  Delete file with read-only permission, but write permission to parent folder cubei 6 26,196 Jun-01-2024, 07:22 AM
Last Post: Eleanorreo
  FileNotFoundError: [WinError 2] The system cannot find the file specified NewBiee 2 3,237 Jul-31-2023, 11:42 AM
Last Post: deanhystad
  Cannot find py credentials file standenman 5 3,673 Feb-25-2023, 08:30 PM
Last Post: Jeff900
  selenium can't find a file in my desk ? SouAmego22 0 1,369 Feb-14-2023, 03:21 PM
Last Post: SouAmego22
  Pypdf2 will not find text standenman 2 1,968 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 2,165 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Find (each) element from a list in a file tester_V 3 2,376 Nov-15-2022, 08:40 PM
Last Post: tester_V
  read a text file, find all integers, append to list oldtrafford 12 10,771 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  what will be the best way to find data in txt file? korenron 2 2,051 Jul-25-2022, 10:03 AM
Last Post: korenron

Forum Jump:

User Panel Messages

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