需求描述:
在做本地知识库的时候,大模型对pdf的文件比较友好,好多官方文档没有直接提供pdf文件,这个时候需要将html内容转换为pdf,供模型去学习。
实现原理:
1. 用selenium打开html文件或url
2. 将html内容用 pyhtml2pdf 进行转换
#前提条件:
selenium 用到的浏览器和驱动需要自行配置
代码实现:
# pip install pyhtml2pdf
from pyhtml2pdf import converter
converter.convert('index.html', 'output.pdf')
converter.convert(url, 'output.pdf')