Html फाइल को पीडीएफ में अजगर के बिना wkhtmltopdf

0

सवाल

मैं एक Plotly बहुल(टैब) पानी का छींटा अनुप्रयोग है । मैं होगा की तरह कन्वर्ट करने के लिए यह करने के लिए एक PDF फ़ाइल. मैं जानता हूँ कि वहाँ है dash_snapshot_engine मॉड्यूल नहीं है, जो मुक्त करने के लिए. इसलिए मैं देख रहा हूँ के लिए एक नि: शुल्क वैकल्पिक है. के रूप में मेरे पानी का छींटा हो जाएगा आवेदन एक निष्पादन योग्य है, मैं का उपयोग नहीं कर सकते बाहरी सॉफ्टवेयर इस तरह के रूप में wkhtmltopdf, मैं कर सकते हैं केवल का उपयोग अजगर केवल पुस्तकालयों.

किसी को भी किसी भी सुझाव के लिए पर ए html फाइल करने के लिए pdf के साथ अजगर पुस्तकालयों?

अग्रिम में धन्यवाद!

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

सबसे अच्छा जवाब

0

आप जोड़ सकता है 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'

enter image description here

2021-11-22 11:18:13

धन्यवाद आप इस विचार के लिए. यह भी काम के साथ cx_freeze? कर सकते हैं मैं जोड़ने के लिए .exe फ़ाइलों को एक ही तरह से?
abc

@एबीसी: मैं इस्तेमाल कभी नहीं किया cx_freeze, बस PyInstaller, nuitka या py2exe (पायथन के लिए 2.x). उपयोगी हो सकता है: stackoverflow.com/questions/2553886/...
Maurice Meyer

यह संभव है कि wkhtmltopdf का उपयोग करता है वेब सेवा कन्वर्ट करने के लिए html पीडीएफ के लिए? - इस मामले में यह एक विकल्प नहीं है, के रूप में कनवर्टर का उपयोग करना चाहिए, "ऑफलाइन तरीके"...
abc

कोई wkhtmltpdf सभी प्रसंस्करण स्थानीय स्तर पर ही है ।
Ryan

अन्य भाषाओं में

यह पृष्ठ अन्य भाषाओं में है

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................

इस श्रेणी में लोकप्रिय

लोकप्रिय सवाल इस श्रेणी में