# Generate PDF from HTML, no data without refreshing the page

**URL:** <https://discourse.nodered.org/t/generate-pdf-from-html-no-data-without-refreshing-the-page/31465>\
**Category:** General\
**Created:** [12 August 2020 10:04 UTC](https://discourse.nodered.org/t/generate-pdf-from-html-no-data-without-refreshing-the-page/31465 "2020-08-12T10:04:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArneR](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/arner/32/95658_2.png) [@ArneR](https://discourse.nodered.org/u/ArneR)\
**Post date:** [12 August 2020 10:04 UTC](https://discourse.nodered.org/t/generate-pdf-from-html-no-data-without-refreshing-the-page/31465/1 "2020-08-12T10:04:29Z")

</div>

Hey

Currently I am working on exporting data to a PDF file.  
Creating the file is no problem. When I press the button "generate report", the file is created.  
However, it does not contain any data (name, first name).

If I visit the template (localhost: 1880 / report-test), and reload the page manually, the data is written out as desired.

Is it possible to read in the data after pressing the button, so that the data is placed in the PDF when generating the file? I can't find a solution.

Note: I copied the "buffer" from a manual, I don't know if there are better options. (I only have limited (to no) knowledge of Javascript)

Thank you very much!

A part of my flow is shown below. This is only part of the entire flow. In my flow more data is added to the buffer / HTML, but the principle remains the same.

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

```auto
[{"id":"6bf9122b.78d5ac","type":"http in","z":"24d31ef4.bdf632","name":"Web: Rapport","url":"/rapport-Test","method":"get","upload":false,"swaggerDoc":"","x":330,"y":2460,"wires":[["67b06ed2.b6407"]]},{"id":"67b06ed2.b6407","type":"function","z":"24d31ef4.bdf632","name":"buffer some data","func":"context.rapport = context.rapport || new Object();\nswitch (msg.topic) {\n case \"voornaam\":\n context.rapport.voornaam = msg.payload;\n msg = null;\n break;\n case \"achternaam\":\n context.rapport.achternaam = msg.payload;\n msg = null;\n break;\n default:\n \tmsg.rapport = context.rapport;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":530,"y":2460,"wires":[["bfd31967.74f428"]]},{"id":"bfd31967.74f428","type":"template","z":"24d31ef4.bdf632","name":"HTML-template Rapport","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<!doctype html>\n\n<html lang=\"nl\">\n<head>\n <meta charset=\"utf-8\">\n\n <title>Hydroland: Rapport</title>\n <meta name=\"Omschrijving\" content=\"Test Flow\">\n <meta name=\"Auteur\" content=\"Arne\">\n\n<style>\n\tbody{\n\t height: 200mm;\n\t width: 190mm;\n\t margin: 5mm 10mm 10mm 10mm;\n\t}\n\t\t\n\ttable {\n\t width:100%;\n\t border: 3 px;\n\t}\n\ttable, th, td {\n\t border: 2px solid black;\n\t border-collapse: collapse;\n\t}\n\tth, td {\n\t padding: 15px;\n\t text-align: left;\n\t border: 0px;\n\t \n\t}\n\t#rapport tr:nth-child(even) {\n\t background-color: #eee;\n\t border: 3px;\n\t}\n\t#.raport rapport tr:nth-child(odd) {\n\t background-color: #fff;\n\t border: 3px;\n\t}\n\t#rapport th {\n\t background-color: black;\n\t color: white;\n\t text-align: center;\n\t}\n\t\n\tp.insprong {\n\t margin-left: 5%;\n\t}\n\t\n\th1 { \n\t display: block;\n\t font-size: 2em;\n\t margin-top: 0.67em;\n\t margin-bottom: 0.67em;\n\t margin-left: 0;\n\t margin-right: 0;\n\t font-weight: bold; \n\t color: blue; \n\t}\n</style>\n\n</head>\n\n\n<body> \n <!-- Tabel persoonsgegevens --> \n\t<table id=\"rapport\">\n\t <tr>\n\t\t<th colspan=\"2\">Persoonsgegevens</th>\n\t </tr>\n\t <tr>\n\t\t<td width=\"35%\">Voornaam:</td>\n\t\t<td>{{rapport.voornaam}}</td>\n\t </tr>\n\t <tr>\n\t\t<td>Achternaam:</td>\n\t\t<td>{{rapport.achternaam}}</td>\n\t </tr>\n\t</table><br>\n <!-- Einde Tabel persoonsgegevens --> \n</body>\n</html>","output":"str","x":770,"y":2460,"wires":[["60feb78b.5a6cb8","1a704985.0c3406"]]},{"id":"1a704985.0c3406","type":"function","z":"24d31ef4.bdf632","name":"Variabele bestandsnaam Rapport","func":"function formatDate(date) {\n var d = new Date(date),\n month = '' + (d.getMonth() + 1),\n day = '' + d.getDate(),\n year = d.getFullYear();\n\n if (month.length < 2) month = '0' + month;\n if (day.length < 2) day = '0' + day;\n\n return [year, month, day].join('-');\n}\nvar tempString =formatDate(Date().toString());\n\nvar tempString1 = \"C:/Users/arne/Desktop/\";\nvar tempString2 = tempString1.concat(tempString);\nvar finalPath = tempString2.concat(\".pdf\");\nmsg.filename=finalPath;\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":800,"y":2520,"wires":[["5a5ca642.4a6d78","5269be58.327fb"]]},{"id":"60feb78b.5a6cb8","type":"http response","z":"24d31ef4.bdf632","name":"","statusCode":"","headers":{},"x":1030,"y":2460,"wires":[]},{"id":"5a5ca642.4a6d78","type":"HTML-PDF","z":"24d31ef4.bdf632","name":"HTML-PDF","output":"file","x":1050,"y":2520,"wires":[["de4f6bc9.fc7f18"]]},{"id":"de4f6bc9.fc7f18","type":"change","z":"24d31ef4.bdf632","name":"Opstellen meldingsparameters","rules":[{"t":"set","p":"topic","pt":"msg","to":"Rapport","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"Rapport succesvol aangemaakt.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":2580,"wires":[["c420d11.96c333"]]},{"id":"c420d11.96c333","type":"ui_toast","z":"24d31ef4.bdf632","position":"top right","displayTime":"5","highlight":"green","sendall":false,"outputs":0,"ok":"OK","cancel":"","raw":false,"topic":"","name":"Melding: Rapport aangemaakt.","x":1110,"y":2580,"wires":[]},{"id":"814a1ca7.0cdcd","type":"ui_button","z":"24d31ef4.bdf632","name":"Raport genereren","group":"c4745898.da08e8","order":6,"width":0,"height":0,"passthru":false,"label":"Rapport","tooltip":"Druk op de knop om een rapport van de sessie te genereren.","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"tijd","x":350,"y":2520,"wires":[["bfd31967.74f428"]]},{"id":"6abbc1cf.fc71f","type":"ui_text_input","z":"24d31ef4.bdf632","name":"Voornaam","label":"Voornaam","tooltip":"","group":"51404579.1d62dc","order":0,"width":0,"height":0,"passthru":true,"mode":"text","delay":300,"topic":"voornaam","x":330,"y":2300,"wires":[["67b06ed2.b6407"]]},{"id":"131037f2.b02eb8","type":"ui_text_input","z":"24d31ef4.bdf632","name":"","label":"Achternaam","tooltip":"","group":"51404579.1d62dc","order":1,"width":0,"height":0,"passthru":true,"mode":"text","delay":300,"topic":"achternaam","x":330,"y":2340,"wires":[["67b06ed2.b6407"]]},{"id":"5269be58.327fb","type":"debug","z":"24d31ef4.bdf632","name":"Filename","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1040,"y":2400,"wires":[]},{"id":"c4745898.da08e8","type":"ui_group","z":"","name":"Instellingen","tab":"787c087.3687bf8","order":6,"disp":true,"width":"6","collapse":false},{"id":"51404579.1d62dc","type":"ui_group","z":"","name":"Persoonsgegevens","tab":"42c0724c.82676c","order":1,"disp":true,"width":"6","collapse":false},{"id":"787c087.3687bf8","type":"ui_tab","z":"","name":"Automatische Mode","icon":"loop","order":2,"disabled":false,"hidden":false},{"id":"42c0724c.82676c","type":"ui_tab","z":"","name":"Persoonsgegevens","icon":"group","order":1,"disabled":false,"hidden":false}]

```

---

<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:** [12 August 2020 19:15 UTC](https://discourse.nodered.org/t/generate-pdf-from-html-no-data-without-refreshing-the-page/31465/2 "2020-08-12T19:15:58Z")

</div>

each msg that passes thru a flow is independent of other messages. If you have two messages with data that needs to be combined, you need to use a `join` node or write the data from one msg to a place the next msg can get it from.

Before you go any further, you should read thru the documentation [Working with messages](https://nodered.org/docs/user-guide/messages). Pay partoicular attention to the section `Message sequences`

---

<div class="post-metadata">

**Author:** ![ArneR](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/arner/32/95658_2.png) [@ArneR](https://discourse.nodered.org/u/ArneR)\
**Post date:** [13 August 2020 07:31 UTC](https://discourse.nodered.org/t/generate-pdf-from-html-no-data-without-refreshing-the-page/31465/3 "2020-08-13T07:31:58Z")

</div>

Hey

Thank you for your answer. The reason why I didn't use 'join' is because I can't pass the 'http in' in this way (I know this should work anyway, but I have to figure that out).

I suspect that 'generate report' in my flow must also be placed before my 'join node', so that it takes the data from the message into account when generating the file? This is where things go wrong.

Thank you for your time and effort!

**EDIT:**  
Maybe I can provide a 'gate' just before creating the PDF? This should open (once) when pressing "generate report". The only problem is still that there is no data on the HTML without refreshing the page. If I can combine the "http in" with the "join node" of course.

---

<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 August 2020 09:27 UTC](https://discourse.nodered.org/t/generate-pdf-from-html-no-data-without-refreshing-the-page/31465/4 "2020-08-13T09:27:36Z")

</div>

Maybe you want to use the `http-request` node instead of the `http-in` and `http-response` nodes. Have the button connect to the `http-request` and then process the resulting data.

Take a look at the the documentation: [https://cookbook.nodered.org/#http-requests](https://cookbook.nodered.org/#http-requests)

---

<div class="post-metadata">

**Author:** ![ArneR](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/arner/32/95658_2.png) [@ArneR](https://discourse.nodered.org/u/ArneR)\
**Post date:** [13 August 2020 15:45 UTC](https://discourse.nodered.org/t/generate-pdf-from-html-no-data-without-refreshing-the-page/31465/5 "2020-08-13T15:45:38Z")

</div>

Dear Zenofmud

Thanks for your comment. I have adjusted my flow and got it working.  
The image below contains my flow.

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

- **Dutch --\> English**
- Samenvoegen data -\> Join data
- Variabele bestandsnaam Rapport -\> Variable filename Report
- Opstellen meldingsparameters -\> Generate notification parameters
- Melding: Rapport aangemaakt -\> Notification: Report created

**Extra information:**

> [@Pass over msg.payload to html](https://discourse.nodered.org/t/pass-over-msg-payload-to-html/14828/8):
>
> Ah ok. So... You'll have to store the value somewhere ready for the GET request. Connect your morbus output to a change node and set a flow variable e.g. flow.data from msg.payload[0]. That will keep a copy. Next add a http in and out node with a change node between them setting msg.payload from flow.data.

---

<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:** [27 August 2020 15:45 UTC](https://discourse.nodered.org/t/generate-pdf-from-html-no-data-without-refreshing-the-page/31465/6 "2020-08-27T15:45:48Z")

</div>

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