Putting different images in a pdf, duplication error

Again I'm here with this PDF issue, I can put the images inside the PDF, but even though I put the directory of different images one always overlaps the other, I've tried several things and so far I haven't been able to solve this problem


I believe that the crucial part is within the template node

specifically on this line, but I don't know how to differentiate the payloads here in a way that accepts it, whenever I try node-red dies
image

My flow down:

[{"id":"54ef025d.56fccc","type":"template","z":"2521f04f9179ef7d","name":"","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\n    \"pageSize\": \"A4\",\n    \"pageOrientation\": \"portrait\",\n    \"pageMargins\": [\n        40,\n        60,\n        40,\n        60\n    ],\n    \"info\": {\n        \"title\": \"awesome Document\",\n        \"author\": \"john doe\",\n        \"subject\": \"subject of document\",\n        \"keywords\": \"keywords for document\"\n    },\n    \"content\": [\n        {\n            \"text\": \"Logo São Paulo Skills\",\n            \"alignment\": \"center\",\n            \"margin\": [\n                0,\n                0,\n                0,\n                20\n            ]\n        },\n        {\n            \"image\": \"data:image/jpeg;base64,{{{payload}}}\",\n            \"width\": 200,\n            \"alignment\": \"center\",\n            \"margin\": [\n                0,\n                0,\n                0,\n                20\n            ] \n        },\n        {\n            \"image\": \"data:image/jpeg;base64,{{{payload}}}\",\n            \"width\": 201,\n            \"alignment\": \"center\"\n        }\n    ]\n}","output":"json","x":900,"y":300,"wires":[["bdd7feab.d9412"]]}]

The is a basic and fundamental node-red thing you need to get to grips with - messages will NEVER arrive from 2 wires into a node at the same time. i.e. your template will see 2 messages, each with a payload


As established above, msg.payload is msg.payload. Unless you move/rename that property that is all it will ever be. So I recommend putting the file+base64 nodes in series (you have them in parallel currently) and use change nodes after the base64 nodes to move msg.payload into msg.image1 and msg.image2

inject → file → base64 → change node (move payload to image1) → file → base64 → change node (move payload to image2) → template

Add a debug node BEFORE the template to check you have msg.image1 and msg.image2 in a single msg entering the template, then you can use {{{image1}}} and {{{image2}}}

Thank you for the answer, I did what you recommended but the value appears as "undefined" in the debug, I tried it in parallel by joining with a join but it didn't work either


I did this for both
image
It seems that the payload is lost when converting the payload

The series way as you said didn't work either

Now I did it, I replaced the changes with two functions, and it worked, thank you very much for your help, another question, do you know how I could put a text object with the value of the current time at which the pdf was generated in the pdf??

No, you have missed the point I'm afraid.

Read this again...


This is in series...


Also, please try to do as recommended:


EDIT

PS:
Your join version could work if you set it up correctly (i.e. added topics and joined to a key/value pair)

@Steve-Mcl

I'm not able to put the datetime value in the pdf yet, I even have an idea of ​​how to put the value of my input into the pdf, I just don't know what the code would look like inside the template, because when I try to put a var inside it I get an error , does not accept

Exactly the same as the images. Get a time string into the msg (the same msg that the images are in) in any property you wish to invent (e.g. msg.datetime) then use the curly brackets as before. "Generated: {{{datetime}}}"

1 Like

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