Html 파일을 PDF 파이썬없이 wkhtmltopdf

0

질문

나는 Plotly 다중(탭)대시니다. 나는 이것을 변환 PDF 파일입니다. 내가 알고 있는 dash_snapshot_engine 모듈는지에 대한 무료입니다. 그러므로 내가 찾는 있습니다. 으로 대 응용 프로그램이 실행,나는 사용할 수 없 외부와 같은 소프트웨어 wkhtmltopdf는,나만 사용할 수 있습니다 Python 만 라이브러리입니다.

는 사람에 어떤 제안을 변환하는 방법 html 파일 pdf Python 라이브러리?

사전에 감사합니다!

html pdf plotly-dash python
2021-11-22 09:53:01
1

최고의 응답

0

추가할 수 있습니다 wkhtmltopdf 귀하의 exePyInstaller:

import subprocess
import sys

htmlPath = 'C:/temp/test.html'
pdfPath = 'C:/temp/test_through_exe.pdf'

if getattr(sys, 'frozen', False):
    # Change wkhtmltopdf path for exe!
    wkPath = os.path.join(sys._MEIPASS, "wkhtmltopdf.exe")
else:
    wkPath = 'C:/.../Downloads/wkhtmltopdf.exe'

with open(htmlPath, 'w') as f:
    f.write('<html><body><h1>%s</h1></body></html>' % sys.version)

cmd = '%s %s %s' % (wkPath, htmlPath, pdfPath)
print(cmd)

proc = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
stdout, stderr = proc.communicate()

print(proc.returncode, stdout)
print(proc.returncode, stderr)

건설 exe (wkhtmltopdf 고 스크립트와 동일한 디렉터리에):

PyInstaller --onefile --add-data ./wkhtmltopdf.exe;. test.py

아웃:

C:\Users\xxx\AppData\Local\Temp\_MEI33842\wkhtmltopdf.exe C:/temp/test.html C:/temp/test_through_exe.pdf
0 b''
0 b'Loading pages (1/6)\r\n[>                                                           ] 0%\r[======>
     ] 10%\r[==============================>                             ] 50%\r[============================================================] 100%\rCounting pages (2/6)                                               \r\n[============================================================] Object 1 of 1\rResolving links (4/6)                                                       \r\n[============================================================] Object 1 of 1\rLoading headers and footers (5/6)                                           \r\nPrinting pages (6/6)\r\n[>
                     ] Preparing\r[============================================================] Page 1 of 1\rDone
                                  \r\n'

enter image description here

2021-11-22 11:18:13

당신을 감사한 이러한 개념을 파악할 수 있습니다. 그것은 또한 작업 cx_freeze? 추가 할 수 있습니.exe 파일을 동일한 방법이 있을까?
abc

@abc:나는 결코 사용 cx_freeze그냥 PyInstaller, nuitkapy2exe (예 Python2.x). 도움이 될 수 있다: stackoverflow.com/questions/2553886/...
Maurice Meyer

그것은 가능 wkhtmltopdf 사용하는 웹 서비스로 변환하 html to pdf? -이 경우에는 옵션이 없으로,변환기를 사용해야"오프라인"방법을...
abc

no wkhtmltpdf 는 모든 처리를 로컬에 자체입니다.
Ryan

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................