【发布时间】:2020-10-28 19:23:27
【问题描述】:
我有一个 pdf 文件,需要删除其中的某些文本。然后将下面的新文本添加到现有文本中。
我正在尝试使用PyMuPDF library - fitz。打开文件,设置要搜索的文本,但我没有找到如何删除它并添加新文本。
请你帮我如何删除找到的文本并添加到现有的文本中。
使用库并不重要,我们可以使用 PyPDF2 等。
带有描述的示例pdf文件是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)
【问题讨论】:
-
问题解决了吗?
标签: python python-3.x pdf