Getting error while converting html to pdf

Hello,
I am converting JSON data into HTML table and HTML table into PDF.
I am saving PDF file on my local machine using write file node.

To convert to HTML into PDF, I am using html to pdf node.(Library name: node-red-contrib-html-to-pdf)

image

While converting HTML to pdf it in throwing below error:

Please help me out to resolve this error.

Thank you!

node-red-contrib-html-to-pdf 1.0.1

Node-RED node for converting HTML files to PDF, using the Puppeteer library.

npm install node-red-contrib-html-to-pdf

A Node-RED node that converts HTML to PDF, using the Puppeteer library.

The node really should state you need to install Puppeteer. Click on the Puppeteer link and do the install and see if that fixes the error.

Still getting same error.

  • have you searched the forum using Puppeteer as the search term?
  • did any of the posts save your issue?

if not:

  • What device is NR running on?

  • What OS is are you running?

  • What version of NR and node.js? (you can get these from the startup log)

  • are you using Docker or Home Assistant?

  • please report a small flow demonstrating the issue and paste it to a response.

  • What OS is are you running?
    ---->> Windows

  • What device is NR running on?
    ----> Computer

  • What version of NR and node.js? (you can get these from the startup log)
    ------> Node-RED version: v3.0.2 Node.js version: v16.14.2

  • are you using Docker or Home Assistant?
    -------> Docker

I think you will need to install puppeteer inside the container. Unless you have to use docker then generally the recommendation is not to do that, for exactly this sort of reason.

I have installed puppeteer in docker using docker terminal

Is there anyone who can help me to resolve the error.

Can you provide a small flow demonstrating the issue? If you do, I can try it out but I run NR on my Mac and raspberry pi’s and I don’t use Docker.

[
    {
        "id": "fdad3a950dd5fd3e",
        "type": "function",
        "z": "0b2e638f231defea",
        "name": "function 22",
        "func": "var jsonData = msg.ExternalDataSourceResult;\nmsg.payload = jsonData;\n//msg.filename =\"E:\\\\Mili Data\\\\Node-RED\\\\Topdf.pdf\";\nnode.warn(msg.payload);\nmsg.keyss = Object.keys(jsonData[0]);\n//msg.keyss = Object.keys(msg.payload[0]);\n//node.warn(msg.keyss[0]);\n\nmsg.payload=jsonData;\n//node.warn(msg.payload);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 430,
        "y": 1080,
        "wires": [
            [
                "8723b2bec6ede8d6"
            ]
        ]
    },
    {
        "id": "8723b2bec6ede8d6",
        "type": "tableify",
        "z": "0b2e638f231defea",
        "name": "",
        "before": "",
        "after": "",
        "tableStyle": "",
        "theadStyle": "",
        "tbodyStyle": "",
        "trStyle": "",
        "tdStyle": "",
        "x": 600,
        "y": 1080,
        "wires": [
            [
                "f3c7f920a31ca82c"
            ]
        ]
    },
    {
        "id": "6375da3bf750e4c3",
        "type": "debug",
        "z": "0b2e638f231defea",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1450,
        "y": 1100,
        "wires": []
    },
    {
        "id": "ace60e4013c49e31",
        "type": "file",
        "z": "0b2e638f231defea",
        "name": "",
        "filename": "E:\\Mili Data\\Node-RED\\Topdf.pdf",
        "filenameType": "str",
        "appendNewline": true,
        "createDir": true,
        "overwriteFile": "true",
        "encoding": "none",
        "x": 1160,
        "y": 1100,
        "wires": [
            [
                "aa2c8b269e509e7e"
            ]
        ]
    },
    {
        "id": "aa2c8b269e509e7e",
        "type": "file in",
        "z": "0b2e638f231defea",
        "name": "",
        "filename": "E:\\Mili Data\\Node-RED\\Topdf.pdf",
        "filenameType": "str",
        "format": "utf8",
        "chunk": false,
        "sendError": false,
        "encoding": "none",
        "allProps": false,
        "x": 1200,
        "y": 1040,
        "wires": [
            [
                "6375da3bf750e4c3"
            ]
        ]
    },
    {
        "id": "f3c7f920a31ca82c",
        "type": "html-to-pdf",
        "z": "0b2e638f231defea",
        "name": "",
        "format": "A4",
        "zoom": 100,
        "orientation": "Portrait",
        "width": "",
        "height": "",
        "marginTop": 1,
        "marginLeft": 1,
        "marginBottom": 1,
        "marginRight": 1,
        "marginTopUnits": "cm",
        "marginLeftUnits": "cm",
        "marginBottomUnits": "cm",
        "marginRightUnits": "cm",
        "omitBackground": false,
        "printGraphics": true,
        "x": 770,
        "y": 1080,
        "wires": [
            [
                "ace60e4013c49e31",
                "c911ebd3933e6196"
            ]
        ]
    },
    {
        "id": "c911ebd3933e6196",
        "type": "link out",
        "z": "0b2e638f231defea",
        "name": "link out 10",
        "mode": "link",
        "links": [
            "e2d4cb22beca5d21"
        ],
        "x": 935,
        "y": 1040,
        "wires": []
    }
]
  1. I had to edit your post to make the flow importable - see footnote (1) below
  2. why do you have two file-out nodes witting to the same file?
  3. what does the data entering the function node look like? (please provide some sample data)

(footnote 1)

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - How to share code or flow json

two file out node because link out node is connecting to the further NR flow.
function node returns JSON data.

I want to store JSON data into PDF and the generated PDF is to be email to recipient.

Sorry but that makes no sense to me, You flow looks like this:


The output of the html to pdf node sends a msg to the link-out node and a copy. of the msg to the first file-out node and it then goes to the second file-out node writing the file to the same file.

You also did not respond to my item 3

One additional thing, if I send an javascript object into the function node, I get a PDF out.
Screenshot 2023-02-13 at 5.40.19 AM

I have used write to file node for temporary purpose just to cross check whether I am getting PDF in desired format or not

Answer of your 3rd question is function node returns JSON data.

I want to store JSON data into PDF and the generated PDF is to be email to recipient.

Above is the data that is entered to function node

Please provide the actual data not a screen shot. Here is how you can copy data from a message

There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

[{"ID":3979257,"NAME":"Assessment","DESCRIPTION":"Assessment"},{"ID":3339935,"NAME":"Budget","DESCRIPTION":"Budget"},{"ID":4106781,"NAME":"Employee Count","DESCRIPTION":"Employee Count"},{"ID":3788971,"NAME":"Employee Performance","DESCRIPTION":"Employee Performance"},{"ID":3339936,"NAME":"Occupancy","DESCRIPTION":"Occupancy"},{"ID":3392157,"NAME":"Rental Rate","DESCRIPTION":"Rental Rate"},{"ID":3392159,"NAME":"Revenue","DESCRIPTION":"Revenue"},{"ID":3733020,"NAME":"Time To Resolve","DESCRIPTION":"Time To Resolve"},{"ID":3719173,"NAME":"Turnover","DESCRIPTION":"Turnover"},{"ID":3598311,"NAME":"Utility","DESCRIPTION":"Utility"}]

Above is the data

It's working fine for me:
Screenshot 2023-02-13 at 7.08.05 AM

The error msgs you are getting indicate you have an issue with the 'puppeteer' install. If you look at your first post it points you to a TROUBLESHOOTING webpage.

Did you go there and search for your issue?

yes, I searched and installed Puppeter library also.

On local Node-RED it converts the data correctly without any error but while using Node-RED that is installed on Docker it gives an error

Ahhh!!! You are running in a Docker container. That would have been useful to know right at the beginning. And I wouldn't have spent so much time if you had mentioned that it worked fine in a local Node-RED.

I would guess that there is an issue with permissions in the Docker but never having used Docker, I'm not going to be able to help you out.

Maybe someone else will jump in and offer some suggestions. meanwhile I suggest you do an internet search about using puppeteer in a docker image.