Làm thế nào để chuyển đổi HTML sang PDF với python3? tôi viết một số mã về webView với pyqt5, và tôi muốn chuyển đổi html trong webView sang pdf, tôi nên làm gì?Làm thế nào để chuyển đổi HTML sang PDF với python3
tôi đã cố gắng sử dụng html2pdf, nhưng dường như chỉ hỗ trợ python2.x và tôi đã cố gắng cài đặt wkhtmltox-0.12.2.2_msvc2013-win64.exe và pdfkit, sau đó sử dụng mã ví dụ.
import pdfkit
pdfkit.from_url('http://google.com', 'out.pdf')
pdfkit.from_file('test.html', 'out.pdf')
pdfkit.from_string('Hello!', 'out.pdf')
nhưng tôi cũng không thành công và lỗi xảy ra.
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
configuration=configuration)
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
nhưng tôi cũng không thành công. Tôi nên làm gì? Hệ thống của tôi là window7 x64, phiên bản python là 3.4
tôi cài đặt lại wkhtmltox và đặt đường dẫn, tôi hoạt động tốt !! – zonzely
Hi zonzely, tôi đã có cùng một vấn đề. Làm thế nào bạn làm cho nó hoạt động? Ý của bạn là gì? – mikeqfu