Pdfmake returns always blank pdf even with the example flow

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

[
    {
        "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:

[
    {
        "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:

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

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

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

image

test Flow changes :

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

@UnborN thanks!
It works like a charme!

Really thanks and happy new year,

Davide

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