# Pdfmake returns always blank pdf even with the example flow

**URL:** <https://discourse.nodered.org/t/pdfmake-returns-always-blank-pdf-even-with-the-example-flow/72893>\
**Category:** General\
**Created:** [29 December 2022 13:29 UTC](https://discourse.nodered.org/t/pdfmake-returns-always-blank-pdf-even-with-the-example-flow/72893 "2022-12-29T13:29:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DidoMarchet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/didomarchet/32/73199_2.png) [@DidoMarchet](https://discourse.nodered.org/u/DidoMarchet)\
**Post date:** [29 December 2022 13:29 UTC](https://discourse.nodered.org/t/pdfmake-returns-always-blank-pdf-even-with-the-example-flow/72893/1 "2022-12-29T13:29:29Z")

</div>

Hi guys,  
I'm trying to generate a pdf from an html template and get it via api url.  
So I use pdfmake and I generate the pdf of the example (I rename the pdf bordero.pdf).

```auto
[
    {
        "id": "ba55707c1c8a4554",
        "type": "pdfmake",
        "z": "bba181f313928b6c",
        "name": "",
        "outputType": "Buffer",
        "inputProperty": "payload",
        "options": "{}",
        "outputProperty": "payload",
        "x": 500,
        "y": 820,
        "wires": [
            [
                "b1510b53716a05c8"
            ]
        ]
    },
    {
        "id": "6165da421edf2ca3",
        "type": "inject",
        "z": "bba181f313928b6c",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"content\":[\"First paragraph\",\"Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines\"]}",
        "payloadType": "json",
        "x": 330,
        "y": 820,
        "wires": [
            [
                "ba55707c1c8a4554"
            ]
        ]
    },
    {
        "id": "b1510b53716a05c8",
        "type": "file",
        "z": "bba181f313928b6c",
        "name": "",
        "filename": "bordero.pdf",
        "appendNewline": true,
        "createDir": false,
        "overwriteFile": "true",
        "encoding": "none",
        "x": 690,
        "y": 820,
        "wires": [
            []
        ]
    },
    {
        "id": "d0615b28b4dcf66e",
        "type": "comment",
        "z": "bba181f313928b6c",
        "name": "Simple Example PDF",
        "info": "This is the simplest PDF test as seen in the pdfmake examples [here](http://pdfmake.org/playground.html)",
        "x": 380,
        "y": 780,
        "wires": []
    }
]

```

and after I expose the file creating a get endpoint MYNODERED/bordero.pdf:

```auto
[
    {
        "id": "26de497f9ebb6e55",
        "type": "http in",
        "z": "bba181f313928b6c",
        "name": "",
        "url": "/bordero.pdf",
        "method": "get",
        "upload": false,
        "swaggerDoc": "",
        "x": 140,
        "y": 440,
        "wires": [
            [
                "061fc71f38cab67e"
            ]
        ]
    },
    {
        "id": "061fc71f38cab67e",
        "type": "file in",
        "z": "bba181f313928b6c",
        "name": "",
        "filename": "bordero.pdf",
        "format": "utf8",
        "chunk": false,
        "sendError": false,
        "encoding": "none",
        "allProps": false,
        "x": 390,
        "y": 440,
        "wires": [
            [
                "163eec4dba8ab5f7"
            ]
        ]
    },
    {
        "id": "163eec4dba8ab5f7",
        "type": "http response",
        "z": "bba181f313928b6c",
        "name": "",
        "statusCode": "",
        "headers": {},
        "x": 590,
        "y": 440,
        "wires": []
    }
]

```

In the frontend I get the pdf stream and I open it in a new window but it is blank.  
If I try to change the direction of the page (from portrait to landscape for example) I can see the uptade but the content still white.

This is how I get the stream:

```auto
const bordero = await axios({
    url: `MYENDPOINT/bordero.pdf`,
    method: "GET",
    responseType: "blob",
  }).then(({ data }) => data);

  const file = new Blob([bordero], { type: "application/pdf" });
  const fileURL = URL.createObjectURL(file);
  window.open(fileURL);

```

I try in to different nodered implementation and the result is the same.

Did you have any advice?

Thanks in advance and kind regards,

Davide

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [30 December 2022 06:57 UTC](https://discourse.nodered.org/t/pdfmake-returns-always-blank-pdf-even-with-the-example-flow/72893/2 "2022-12-30T06:57:42Z")

</div>

Hello .. i did some tests and managed to get it to work by changing two things

When you read the pdf file with the file read node, in order to serve it with **http-in**  
.. set it to read as a buffer

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

and also set the appropriate Content-type header for pdf in the **http response node**

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/4/84cca2a9d52d8d6bdc044dd1283ef2a4138b5edf.png)

**test Flow changes :**

```auto
[{"id":"26de497f9ebb6e55","type":"http in","z":"54efb553244c241f","name":"","url":"/bordero.pdf","method":"get","upload":false,"swaggerDoc":"","x":340,"y":2200,"wires":[["061fc71f38cab67e"]]},{"id":"061fc71f38cab67e","type":"file in","z":"54efb553244c241f","name":"","filename":"c:\\share\\bordero.pdf","filenameType":"str","format":"","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":630,"y":2200,"wires":[["163eec4dba8ab5f7"]]},{"id":"163eec4dba8ab5f7","type":"http response","z":"54efb553244c241f","name":"","statusCode":"","headers":{"content-type":"application/pdf"},"x":830,"y":2200,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![DidoMarchet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/didomarchet/32/73199_2.png) [@DidoMarchet](https://discourse.nodered.org/u/DidoMarchet)\
**Post date:** [30 December 2022 21:05 UTC](https://discourse.nodered.org/t/pdfmake-returns-always-blank-pdf-even-with-the-example-flow/72893/3 "2022-12-30T21:05:37Z")

</div>

@UnborN thanks!  
It works like a charme!

Really thanks and happy new year,

Davide

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 January 2023 21:05 UTC](https://discourse.nodered.org/t/pdfmake-returns-always-blank-pdf-even-with-the-example-flow/72893/4 "2023-01-13T21:05:48Z")

</div>

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