溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Python3轉(zhuǎn)換html到pdf的不同解決方案

發(fā)布時(shí)間:2020-09-23 01:31:47 來源:腳本之家 閱讀:206 作者:網(wǎng)絡(luò)整理 欄目:開發(fā)技術(shù)

問題:python3 如何轉(zhuǎn)換html到pdf

描述:

我的電腦是windows764位,python3.4

我想用python 轉(zhuǎn)換html到pdf.

我嘗試了html2pdf,貌似它只支持Python2

我又嘗試了wkhtmltox-0.12.2.2_msvc2013-win64和pdfkit,并用下面的例子測試。

import pdfkit
pdfkit.from_url('http://google.com', 'out.pdf')

報(bào)錯(cuò)信息

Traceback (most recent call last):
 File "E:\Python34\lib\site-packages\pdfkit\configuration.py", line 21, in __init__
  with open(self.wkhtmltopdf) as f:
FileNotFoundError: [Errno 2] No such file or directory: b''
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
 File "<pyshell#2>", line 1, in <module>
  pdfkit.from_url('http://google.com', 'out.pdf')
 File "E:\Python34\lib\site-packages\pdfkit\api.py", line 22, in from_url
  c
 File "E:\Python34\lib\site-packages\pdfkit\pdfkit.py", line 38, in __init__
  self.configuration = (Configuration() if configuration is None
 File "E:\Python34\lib\site-packages\pdfkit\configuration.py", line 27, in __init__
  'https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf' % self.wkhtmltopdf)
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

請(qǐng)大神們告訴我,該怎么做呢?

解決方案1:

直接使用里邊的wkhtmltopdf即可

wkhtmltopdf http://google.com a.pdf

解決方案2:

把可執(zhí)行文件的路徑加入到環(huán)境變量里

以上介紹了“python3 如何轉(zhuǎn)換html到pdf”的問題解答,希望對(duì)有需要的網(wǎng)友有所幫助。

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)億速云的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI