我有一个Plotly多页(签)划应用程序。 我想转换这个 PDF
文件。 我知道有的 dash_snapshot_engine
模块,该模块是不是免费的。 因此,我在寻找一个免费的替代方法。
为我冲的应用程序将是可执行,我不能使用外部软件等 wkhtmltopdf
我只能使用蟒蛇只有图书馆。
有人提出任何建议如何转换一个 html
文件 pdf
与Python库?
在此先感谢!
我有一个Plotly多页(签)划应用程序。 我想转换这个 PDF
文件。 我知道有的 dash_snapshot_engine
模块,该模块是不是免费的。 因此,我在寻找一个免费的替代方法。
为我冲的应用程序将是可执行,我不能使用外部软件等 wkhtmltopdf
我只能使用蟒蛇只有图书馆。
有人提出任何建议如何转换一个 html
文件 pdf
与Python库?
在此先感谢!
你能加入 wkhtmltopdf
你的 exe
使用 PyInstaller
:
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'
cx_freeze
,只是 PyInstaller
, nuitka
或 py2exe
(Python2.x)。 可能会有所帮助: stackoverflow.com/questions/2553886/... wkhtmltopdf
使用网络的服务转换html pdf? -在这种情况下,它不是一个选项,作为转换应使用"离线"的方法... wkhtmltpdf
没有处理当地自身。