【问题标题】:wkhtmltopdf configure pathwkhtmltopdf 配置路径
【发布时间】:2020-04-30 00:06:10
【问题描述】:

所以我想设置一个脚本,它将获取一个网页并将其转换为 pdf。我的 wkhtmltopdf 配置似乎有问题。这是我不知道该怎么做的部分:“并将带有 wkhtmltopdf 二进制文件的文件夹添加到 PATH。”我会很感激这个脚本的一些帮助。谢谢!

这是我的代码:

import pdfkit
pdfkit.from_url('https://grapaes.com/282-newsletter/', 'news282.pdf')
print("I did it!")

这是我的错误信息:

Traceback (most recent call last):
  File "C:/Users/Gittel/PycharmProjects/untitled1/website as pdf", line 2, in <module>
    pdfkit.from_url('https://grapaes.com/282-newsletter/', 'news282.pdf')
  File "C:\Users\Gittel\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pdfkit\api.py", line 23, in from_url
    r = PDFKit(url, 'url', options=options, toc=toc, cover=cover,
  File "C:\Users\Gittel\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pdfkit\pdfkit.py", line 42, in __init__
    self.configuration = (Configuration() if configuration is None
  File "C:\Users\Gittel\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pdfkit\configuration.py", line 24, in __init__
    raise IOError('No wkhtmltopdf executable found: "%s"\n'
OSError: No wkhtmltopdf executable found: "b''"
If this file exists please check that this process can read it. Otherwise please install wkhtmltopdf - https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf

Process finished with exit code 1

【问题讨论】:

标签: python wkhtmltopdf


【解决方案1】:
import pdfkit
from pdfkit.api import configuration

wkhtml_path = pdfkit.configuration(wkhtmltopdf = "C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe")  #by using configuration you can add path value.

pdfkit.from_url('https://stackoverflow.com/questions/33705368/unable-to-find-wkhtmltopdf-on-this-system-the-report-will-be-shown-in-html', 'C:/Users/Admin/Desktop/Trial1.pdf', configuration = wkhtml_path)

【讨论】:

  • 请您帮我制作 TOC 吗?我相信我需要通过toc = {'xsl-style-sheet': 'toc.xsl'},但我不知道该文件中应该包含什么...
猜你喜欢
  • 2015-08-19
  • 2018-10-03
  • 2013-05-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-26
  • 2016-03-30
  • 2018-06-14
相关资源
最近更新 更多