# Getting error while converting html to pdf

**URL:** <https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642>\
**Category:** General\
**Created:** [3 February 2023 09:25 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642 "2023-02-03T09:25:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![MiliH](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@MiliH](https://discourse.nodered.org/u/MiliH)\
**Post date:** [3 February 2023 09:25 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642/1 "2023-02-03T09:25:52Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/b/cbfb87f48cef4e1ba7c3d5ff586ed6560fa5b797.png)

While converting HTML to pdf it in throwing below error:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/b/bb392d5b3af10a78bedbc80527dd58d080406a07.png)

Please help me out to resolve this error.

Thank you!

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [3 February 2023 09:53 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642/2 "2023-02-03T09:53:59Z")

</div>

# 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](https://nodered.org/) node that converts HTML to PDF, using the [Puppeteer](https://pptr.dev/) 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.

---

<div class="post-metadata">

**Author:** ![MiliH](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@MiliH](https://discourse.nodered.org/u/MiliH)\
**Post date:** [3 February 2023 10:02 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642/3 "2023-02-03T10:02:30Z")

</div>

Still getting same error.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [3 February 2023 10:37 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642/4 "2023-02-03T10:37:59Z")

</div>

- 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.

---

<div class="post-metadata">

**Author:** ![MiliH](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@MiliH](https://discourse.nodered.org/u/MiliH)\
**Post date:** [3 February 2023 11:15 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642/6 "2023-02-03T11:15:12Z")

</div>

- 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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [3 February 2023 11:40 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642/7 "2023-02-03T11:40:13Z")

</div>

> [@MiliH](#):
>
> -------\> 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.

---

<div class="post-metadata">

**Author:** ![MiliH](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@MiliH](https://discourse.nodered.org/u/MiliH)\
**Post date:** [3 February 2023 11:47 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642/8 "2023-02-03T11:47:20Z")

</div>

I have installed puppeteer in docker using docker terminal

---

<div class="post-metadata">

**Author:** ![MiliH](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@MiliH](https://discourse.nodered.org/u/MiliH)\
**Post date:** [10 February 2023 12:26 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642/9 "2023-02-10T12:26:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [10 February 2023 14:43 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642/10 "2023-02-10T14:43:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MiliH](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@MiliH](https://discourse.nodered.org/u/MiliH)\
**Post date:** [13 February 2023 06:43 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642/11 "2023-02-13T06:43:24Z")

</div>

```auto
[
    {
        "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": []
    }
]

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 February 2023 10:05 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642/12 "2023-02-13T10:05:00Z")

</div>

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 `````)

````auto
``` 
   code goes here 
```

````

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

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![MiliH](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@MiliH](https://discourse.nodered.org/u/MiliH)\
**Post date:** [13 February 2023 10:26 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642/13 "2023-02-13T10:26:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 February 2023 10:38 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642/14 "2023-02-13T10:38:40Z")

</div>

> [@MiliH](#):
>
> two file out node because link out node is connecting to the further NR flow.

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

 ![Screenshot 2023-02-13 at 5.30.19 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/3/d3709ffaeccc423e899cc68e4b91b5cf5e14a6fa.png)  
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

> [@zenofmud](#):
>
> 1. what does the data entering the `function` node look like? (please provide some sample data)
> 
> Also, people answering questions on the forum are volunteers. If you want help you should respond to everything someone asks you so as not to waste their time having to ask the same thing again.

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f667fe0988e7951b920916f2f106f4f97bc6046c.png)

---

<div class="post-metadata">

**Author:** ![MiliH](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@MiliH](https://discourse.nodered.org/u/MiliH)\
**Post date:** [13 February 2023 11:02 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642/15 "2023-02-13T11:02:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MiliH](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@MiliH](https://discourse.nodered.org/u/MiliH)\
**Post date:** [13 February 2023 11:05 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642/16 "2023-02-13T11:05:50Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/7/a7cfeb31b48ebeb2ac3ad7ed235f1955f3e7a8be.png)

Above is the data that is entered to function node

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 February 2023 11:12 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642/17 "2023-02-13T11:12:22Z")

</div>

> [@MiliH](#):
>
> 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](https://nodered.org/docs/user-guide/messages)) 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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

---

<div class="post-metadata">

**Author:** ![MiliH](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@MiliH](https://discourse.nodered.org/u/MiliH)\
**Post date:** [13 February 2023 11:17 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642/18 "2023-02-13T11:17:30Z")

</div>

```auto
[{"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

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 February 2023 12:22 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642/19 "2023-02-13T12:22:51Z")

</div>

It's working fine for me:  
 ![Screenshot 2023-02-13 at 7.08.05 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7a2ce488d61ccb26993ff74a8645f53250f2d894.png)

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?

---

<div class="post-metadata">

**Author:** ![MiliH](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@MiliH](https://discourse.nodered.org/u/MiliH)\
**Post date:** [13 February 2023 12:24 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642/20 "2023-02-13T12:24:58Z")

</div>

> [@zenofmud](#):
>
> 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

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 February 2023 12:30 UTC](https://discourse.nodered.org/t/getting-error-while-converting-html-to-pdf/74642/21 "2023-02-13T12:30:29Z")

</div>

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.
