我需要删除使用Python的pdf文档中的文本“草稿”。我可以找到包含文本的文本框,但找不到如何使用pymupdf编辑pdf文本元素的示例。
在下面的示例中,草案对象包含草稿文本元素的和弦和文本。
import fitz
fname = r"original.pdf"
doc = fitz.open(fname)
page = doc.load_page(0)
draft = page.search_for("DRAFT")
# insert code here to delete the DRAFT text or replace it with an empty string
out_fname = r"final.pdf"
doc.save(out_fname)
添加了4/28/2022,我找到了一种删除文本的方法,但不幸的是,它也删除了草稿周围框下的任何重叠文本。我只是想在不修改底层的情况下删除字母草稿
# insert code here to delete the DRAFT text or replace it with an empty string
rl = page.search_for("DRAFT", quads = True)
page.add_redact_annot(rl[0])
page.apply_redactions()
发布于 2022-09-26 08:25:52
你可以试试这个。
import fitz
doc = fitz.open("xxxx")
for page in doc:
for xref in page.get_contents():
stream = doc.xref_stream(xref).replace(b'The string to delete', b'')
doc.update_stream(xref, stream)
https://stackoverflow.com/questions/72033672
复制相似问题