但无法突出显示 .pdf 文件中的多个关键字。这是我的代码
import fitz
import os
keywords = ["remote","setup"]
pdfFile = "\D:\Python_Scripts\Email Analysis\certification-ACDA.pdf"
for keyword in keywords:
pdf = fitz.open(pdfFile)
for page in pdf:
text_instances = page.searchFor(keyword)
if len(text_instances) > 0:
for inst in text_instances:
highlight = page.addHighlightAnnot(inst)
highlight.setColors(stroke=(1, 0, 0))
highlight.update()
pdf.save(f"{os.path.splitext(os.path.basename(pdfFile))[0]}.pdf", garbage=4, deflate=True, clean=True)
完成对单个关键字的搜索但收到此错误后,我正在覆盖文件
Traceback (most recent call last): File "D:/Python_Scripts/Email Analysis/PDF.py", line 19, in <module> pdf.save(f"{os.path.splitext(os.path.basename(pdfFile))[0]}.pdf", garbage=4, deflate=True, clean=True) File "D:\Python_Scripts\Email Analysis\venv\lib\site-packages\fitz\fitz.py", line 4209, in save user_pw, RuntimeError: cannot remove file 'certification-ACDA.pdf': Permission denied