问题描述
我能够使用 this
在 .pdf 文件中突出显示单个单词的所有出现次数但无法突出显示 .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))
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",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
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)