ยังแฟ้ม Html ที่เอกสาร PDF ในปลั๊กอินสำหรับไพธอนโดยไม่มี wkhtmltopdf

0

คำถาม

ฉันมี Plotly Multipage(แท็บ)วิ่งโปรแกรม ฉันต้องการจะแปลงเป็นเรื่องนี้ PDF แฟ้ม ฉันรู้ว่ามันเป็น dash_snapshot_engine ศูนย์ควบคุม kde ในโมดูลซึ่งมันไม่ใช่สำหรับอิสระแล้ว ดังนั้นฉันกำลังมองหาอิสระทางเลือก เป็นของฉันวิ่งโปรแกรมจะเป็นสามารถสั่งประมวลผลได้ฉันไม่สามารถใช้เว็บเบราว์เซอร์ภายนอกโปรแกรมอย่างเช่น 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? ฉันสามารถเพิ่ม.pgm แฟ้มแบบเดียวกัน?
abc

@เอบีซี:ฉันไม่เคยใช้ cx_freezeแค่ PyInstaller, nuitka หรือ py2exe (สำหรับไพธอน 2 ต่อได้.x) อาจต้องการความช่วยเหลือเห: stackoverflow.com/questions/2553886/...
Maurice Meyer

มันเป็นไปได้ว่า wkhtmltopdf ใช้เว็บบริการเปลี่ยนเป็นแบบ html ที่เอกสาร pdf? -ในกรณีนี้มันไม่ใช่ทางเลือกเหมือนอย่างที่ converter ควรจะใช้"ไม่ได้เชื่อมต่อ"วิธีการของ...
abc

ไม่ wkhtmltpdf ทำได้ทุกอกำลังประมวลผลในตัวมันเอง
Ryan

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

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

ดังอยู่ในนี้หมวดหมู่

ดังคำถามอยู่ในนี้หมวดหมู่