Hi
I've been trying to convert HTML content that is created in my flow to a PDF for days. Unfortunately, all attempts have failed.
I also display this HTML content in the dashboard in a Ui_Tamplet, it would also be enough for me if I could print the content via the web browser via the Print button. However, in this case he always wants to print the whole page (including the menus and the other UI_Elements)
So my goal would be to print out the HTML content that is also displayed in the Ui_Tamplet, either via browser or as a PDF download and print out the PDF.
I've tried the Html->PDF Node. However, I have the problem when I send the HTML content via msh.payload and send the necessary settings with msg.config. Crashes Node-Red completely, I haven't found a log about it yet. Export below.
My other attempt was via Functions Node. I have included the jspdf.js library in the settings.js and wanted to solve it via script.
Test Code:
var doc = jsPDF();
doc.text(20, 20, 'Hello, world.');
msg.payload = doc.save('Test.pdf', function(err){console.log('saved!');});
return msg;
However, I get the error: "ReferenceError: jsPDF is not defined (line 1, col 11)"
All other solutions that I found via Google or in this forum either didn't work or gave an error.
I guess the solution will definitely be very simple and afterwards I'll be annoyed why I didn't think of it myself, but at the moment I don't know what to do next. So I would ask for your help.
Thanks
Fire
Export from html->PDF node Test:
Summary
[
{
"id": "0df5361b58930300",
"type": "inject",
"z": "4b32b97b46f1f41f",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "options",
"v": "{"format":"A4","orientation":"portrait","border":{"top":"2in","right":"1in","bottom":"2in","left":"1.5in"},"header":{"height":"45mm"},"zoomFactor":"1","type":"pdf","quality":"75","phantomPath":"./node_modules/phantomjs/bin/phantomjs"}",
"vt": "json"
},
{
"p": "filename",
"v": "test.pdf",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": " /* Font Definitions / @font-face \t{font-family:"Cambria Math"; \tpanose-1:2 4 5 3 5 4 6 3 2 4;} @font-face \t{font-family:Calibri; \tpanose-1:2 15 5 2 2 2 4 3 2 4;} / Style Definitions / p.MsoNormal, li.MsoNormal, div.MsoNormal \t{margin-top:0cm; \tmargin-right:0cm; \tmargin-bottom:8.0pt; \tmargin-left:0cm; \tline-height:107%; \tfont-size:11.0pt; \tfont-family:"Calibri",sans-serif; \t} p.MsoNoSpacing, li.MsoNoSpacing, div.MsoNoSpacing \t{margin:0cm; \tfont-size:11.0pt; \tfont-family:"Calibri",sans-serif; \t} .MsoChpDefault \t{font-family:"Calibri",sans-serif;} .MsoPapDefault \t{margin-bottom:8.0pt; \tline-height:107%;} / Page Definitions */ @page WordSection1 \t{size:595.3pt 841.9pt; \tmargin:36.0pt 36.0pt 36.0pt 36.0pt;} div.WordSection1 \t{page:WordSection1; \t} \tdiv.A4O { \twidth: 210mm; \theight: 297mm; \tborder-style: outset; \tborder-width: 3px; \tbox-shadow: 5px 5px 5px black; \t} div.Abst{ \tmargin: 15mm 15mm 15mm 15mm; \t}
Combies: ___
{{Tabel_Select_Infos.CU_contact}}
Auftrag AU{{Tabel_Select_Infos.AU_pk}}
Â
{{Tabel_Select_Infos.CU_name}}
Liefterm: {{Tabel_Select_Infos.AU_shipment_date}} 08:00
Erstellt: xxx
Â
Positionen
Â
{{{tabelle}}} Teil | Anzahl | Referenz | Notiz |
"payloadType": "str",
"x": 3760,
"y": 440,
"wires": [
[
"e2addfc797a30765",
"6907616fbfbd56b0"
]
]
},
{
"id": "6907616fbfbd56b0",
"type": "HTML-PDF",
"z": "4b32b97b46f1f41f",
"name": "HTML-PDF",
"output": "file",
"x": 3930,
"y": 440,
"wires": [
[
"ff3519cc83848547"
]
]
},
{
"id": "ff3519cc83848547",
"type": "debug",
"z": "4b32b97b46f1f41f",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 4110,
"y": 440,
"wires":
},
{
"id": "e2addfc797a30765",
"type": "debug",
"z": "4b32b97b46f1f41f",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 3900,
"y": 400,
"wires":
}
]