Hi!
I'd like to use the npm node (node-red-contrib-npm (node) - Node-RED) to be able to use pdf-merger-js (pdf-merger-js - npm).
Unfortunately, I always get errors like TypeError: func is not a function
or similar, depending on how I connect the individual nodes in the following flow:
[{"id":"ae6cb40ae0efa2ed","type":"npm","z":"4b453fb457938d95","name":"pdf-merger-js","func":"const PDFMerger = require('pdf-merger-js');\n\nvar merger = new PDFMerger();\n\n(async () => {\n await merger.add('pdf1.pdf'); //merge all pages. parameter is the path to file and filename.\n await merger.add('pdf2.pdf');\n\n await merger.save('merged.pdf'); //save under given name and reset the internal document\n})();\nreturn npm_module(msg.payload);","npm_module":"pdf-merger-js","module_style":"custom","msg_payload":"return_val","function_name":"","x":470,"y":600,"wires":[["07e72953e011a95c"]]},{"id":"24b90b147213d017","type":"inject","z":"4b453fb457938d95","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":600,"wires":[["ed2cb1df163e8109"]]},{"id":"07e72953e011a95c","type":"debug","z":"4b453fb457938d95","name":"debug 36","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":660,"y":560,"wires":[]},{"id":"ed2cb1df163e8109","type":"npm","z":"4b453fb457938d95","name":"pdf-lib","func":"// NPM module exposed as variable, npm_module\nreturn npm_module(msg.payload);","npm_module":"pdf-lib","module_style":"cstr","msg_payload":"callback_error","function_name":"","x":230,"y":540,"wires":[["102cd5d700f07c78"]]},{"id":"102cd5d700f07c78","type":"npm","z":"4b453fb457938d95","name":"pdf-merger-js install","func":"// NPM module exposed as variable, npm_module\nreturn npm_module(msg.payload);","npm_module":"pdf-merger-js","module_style":"cstr","msg_payload":"return_val","function_name":"","x":430,"y":540,"wires":[["ae6cb40ae0efa2ed"]]}]
Any idea how I am able to get this to work?
I'd also appreciate another solution on how I would be able to generate a template output per injected payload to store each output as a page in one file using node-red-contrib-pdf (node) - Node-RED instead of the approach of combining the resulting pdfs.
Thanks!