对于一般的html,当使用pdfkit将html转换为pdf时,html中的图像可以保存为pdf。
而对于微信的公众号文章,我发现urls中的图片丢失了。以下代码是一个实例。
如何将带有图片的微信公众号文章保存到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))'我认为其中一个解决方案是滚动url来加载所有图像,然后将其转换为pdf。如何滚动加载pdfkit中的所有图像?
发布于 2018-01-10 17:12:13
在不修改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
https://stackoverflow.com/questions/48183138
复制相似问题