当前位置:   article > 正文

python - 更改pdf中文本的字体高亮颜色(fitz模块)_python pdf高亮

python pdf高亮
import fitz

file_name = r"e:/test.pdf"
# 注意打开文本和保存文本均为一个文件,最好做好原数据备份

doc = fitz.open(file_name )
page=doc[0]

# 方法一:按照指定的位置设置颜色
highlight = page.add_highlight_annot((20, 500,60, 520))  # 左上,左下,右上,右下
highlight.set_colors(stroke=[1, 1, 0]) # light red color (r, g, b)  颜色rgb每个除以255得出
highlight.update()

# 方法二:按照查找的文本设置颜色
text="2024 年是龙年"
text_instances = page.search_for(text,quads=True)
for inst in text_instances:
    highlight = page.add_highlight_annot(inst)
    highlight.update()

doc.save(file_name, incremental=True, encryption=0)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

效果如图:
请添加图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/880000
推荐阅读
相关标签
  

闽ICP备14008679号