I cant convert HTML to PDF or Print the HTML content

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}

<span style="position:relative;z-index:40"> <img width=107 height=107 src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/61/QR_deWP.svg/1200px-QR_deWP.svg.png">

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":
}
]

Hi

After a long search I was able to solve my problem.
I don't want to withhold my solution from you, maybe one of you may need this information.

I now create my PDF with the HTML-PDF node (node-red-contrib-pdf). Here, however, I always had the error "Auto configuration failed", so I left this node and was looking for other solutions.

To fix this "Auto configuration failed" error, you just have to do the following steps.

  1. Go to /etc/ssl/openssl.cnf
  2. Find the following line and comment it.
# System default
openssl_conf = default_conf
  1. Restart your node-red server

After that the HTML-PDF node works fine.

I hope I can make someone's life easier with this.

Kind regards, Fire

2 Likes

@fireboyff FYI
I would be wary of this node since it:

  1. hasn't been updated (as of the date of this post) in over SIX years
  2. the repository on GitHub is gone
  3. the GitHub user seems to be missing.

So realize that if anything goes wrong (say a future NR or node.js update breaks it), you're on your own with it.

1 Like

Hi zenofmud

Yes, I'm aware of that, but I haven't found a better solution after more than a week of searching.

The integration of e.g. jsPDF.js in the function node does not work.
Unfortunately, all other attempts didn't work either.

Best regards Fire

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.