如何将带图像的微信官方账号转换为pdf

问题描述 投票:0回答:1

对于一般的html,当使用pdfkit将html转换为pdf时,html中的图像可以保存为pdf。

而对于微信官方账号的文章,我发现网址中的图片丢失了。以下代码是一个实例。

如何保存微信官方账号文章与图像到PDF?

import pdfkit
url='https://mp.weixin.qq.com/s?__biz=MzA3NDMyOTcxMQ==&mid=2651249314&idx=1&sn=5338576a80a4145b9808ff06cc980c14'
path_wkthmltopdf = 'C:/Anaconda3/Lib/site-packages/wkhtmltopdf/bin/wkhtmltopdf.exe'
pdfkit.from_url(url=url,output_path='c:/test.pdf',configuration=pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf))'

我认为其中一个解决方案是滚动网址以加载所有图像,然后将其转换为pdf。如何下载以加载pdfkit中的所有图像?

python-3.x pdfkit wechat
1个回答
0
投票

以下应该可以在不修改Windows环境变量的情况下工作:

import pdfkit
path_wkthmltopdf = r'C:\Python27\wkhtmltopdf\bin\wkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
url = 'https://mp.weixin.qq.com/s?timestamp=1515570589&src=3&ver=1&signature=xsZdozV1JPS2K8SuXJ8TKeqfuczP2z78*LCVu32ljt1NSa8oF41X88W0JYguTbLUwHHyt0ksUy8l9ljM5*uGOSH-GBjlVipz4a1aIeg9xNQgwlxuCV*9dURcg-U8UvR78C2RV6B5CIeA0n1jIaiFiqrQTIuel5IW-HYAcQsOT0g='
pdfkit.from_url(url, "out.pdf", configuration=config)

假设路径是正确的(例如在我的情况下它是r'C:\ Program Files(x86)\ wkhtmltopdf \ bin \ wkhtmltopdf.exe')。

结果:

Loading page (1/2)
Printing pages (2/2)                                               
Done   

PDF Link

© www.soinside.com 2019 - 2024. All rights reserved.