Ik probeer vanuit een Python programma een html file om te zetten naar een pdf file. Dit levert echter een lege pdf op. hier het stukje code:
De output in het CMD venster van waaruit ik het Python programma start:
De terminal output laat zien dat het html naar pdf omzetten plaatsvindt en dat dit zonder fouten loopt, aangezien de return code 0 is. Het pdf bestand is echter leeg.
Als ik echter de commando string direct uitvoer:
dan wordt er wel een goed pdf bestand gemaakt, met daarin de inhoud van het html bestand.
Ipv een subprocess.call heb ik ook subprocess.run geprobeerd.
Verder heb ik ook geprobeerd:
Ook dit levert een lege pdf op.
De laatste poging was via een batch bestand, maar ook dan een lege pdf.
Wat gaat hier fout?
Relevante software en hardware die ik gebruik:
Windows 10
Python 3.8.10
wkhtmltopdf 0.12.6 (with patched qt)
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| cmd_line = "%s %s %s %s" % (Path(constants.RESOURCE_DIR + "wkhtmltox/bin/wkhtmltopdf.exe").resolve(),"--enable-local-file-access", Path(constants.REPORTS_DIR + invoice_name + ".html").resolve(), Path(constants.REPORTS_DIR + invoice_name + ".pdf").resolve()) cmd_str = "" for i in range(len(cmd_line)): cmd_str += '/' if cmd_line[i] == '\\' else cmd_line[i] cmd = cmd_str.split() print ("command string: %s" % cmd_str) print ("subprocess parameters:\n%s\n%s\n%s\n%s" % (cmd[0], cmd[1], cmd[2], cmd[3])) result = subprocess.call([cmd[0], cmd[1], cmd[2], cmd[3]]) print (result) |
De output in het CMD venster van waaruit ik het Python programma start:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| N:\qc>python admin_prog.py command string: //NAS/home/qc/Resources/wkhtmltox/bin/wkhtmltopdf.exe --enable-local-file-access //NAS/home/qc/Reports/Z-0002.html //NAS/home/qc/Reports/Z-0002.pdf subprocess parameters: //NAS/home/qc/Resources/wkhtmltox/bin/wkhtmltopdf.exe --enable-local-file-access //NAS/home/qc/Reports/Z-0002.html //NAS/home/qc/Reports/Z-0002.pdf Loading pages (1/6) Counting pages (2/6) Resolving links (4/6) Loading headers and footers (5/6) Printing pages (6/6) Done 0 |
De terminal output laat zien dat het html naar pdf omzetten plaatsvindt en dat dit zonder fouten loopt, aangezien de return code 0 is. Het pdf bestand is echter leeg.
Als ik echter de commando string direct uitvoer:
code:
1
2
3
4
5
6
7
| N:\qc> //NAS/home/qc/Resources/wkhtmltox/bin/wkhtmltopdf.exe --enable-local-file-access //NAS/home/qc/Reports/Z-0002.html //NAS/home/qc/Reports/Z-0002.pdf Loading pages (1/6) Counting pages (2/6) Resolving links (4/6) Loading headers and footers (5/6) Printing pages (6/6) Done |
dan wordt er wel een goed pdf bestand gemaakt, met daarin de inhoud van het html bestand.
Ipv een subprocess.call heb ik ook subprocess.run geprobeerd.
Verder heb ik ook geprobeerd:
code:
1
| os.system(cmd_str) |
Ook dit levert een lege pdf op.
De laatste poging was via een batch bestand, maar ook dan een lege pdf.
Wat gaat hier fout?
Relevante software en hardware die ik gebruik:
Windows 10
Python 3.8.10
wkhtmltopdf 0.12.6 (with patched qt)
For it is the doom of men that they forget... Huidige en vroegere hardware specs The Z80 is still alive!