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

python 复制代码
import fitz

doc = fitz.open(r"e:/test.pdf")
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(r"e:/test.pdf",incremental=True,encryption=0)
# 注意打开文本和保存文本为一个文件

效果如图:

相关推荐
还是鼠鼠3 分钟前
AI掘金头条新闻系统 (Toutiao News)-缓存相关推荐新闻
后端·python·mysql·fastapi·web
骑士雄师7 分钟前
大模型:runnable
python·embedding
2401_8685347813 分钟前
系统分析师案例分析题常考知识点
python·计算机网络
逝水无殇16 分钟前
C# 枚举(Enum)详解
开发语言·后端·c#
nianniannnn28 分钟前
c++复习自存--标准模板库STL
开发语言·c++·windows
努力努力再努力wz37 分钟前
【高性能网络库与HTTP Server系列】:基于主从 Reactor 模型实现高性能 C++ 网络库与 HTTP Server
开发语言·网络·数据结构·数据库·c++·网络协议·http
什巳1 小时前
JAVA练习275-乘积最大子数组
java·开发语言·数据结构·算法
lang201509281 小时前
Apache POI Word(docx) 实战教程:从入门到精通表格合并、图片插入与文档合并
java·开发语言·word
江华森1 小时前
Python 实现 2048 游戏(三):面向对象重构与AI模拟
python
可以飞的话2 小时前
五、数据处理1
python