# Generate a PDF-file with variable filename

**URL:** <https://discourse.nodered.org/t/generate-a-pdf-file-with-variable-filename/64228>\
**Category:** General\
**Created:** [22 June 2022 08:22 UTC](https://discourse.nodered.org/t/generate-a-pdf-file-with-variable-filename/64228 "2022-06-22T08:22:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mauri](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@Mauri](https://discourse.nodered.org/u/Mauri)\
**Post date:** [22 June 2022 08:22 UTC](https://discourse.nodered.org/t/generate-a-pdf-file-with-variable-filename/64228/1 "2022-06-22T08:22:40Z")

</div>

Hello Community

I want to generate a pdf in node red and want to enter the file name (and maybe the location) with variables. I heard that this could work with the msg.filename, but I couldn't find anything. can someone help me?

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

So I can generate a pdf but the file name is fixed.  
Thanks for your help!

Mauri

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [22 June 2022 09:52 UTC](https://discourse.nodered.org/t/generate-a-pdf-file-with-variable-filename/64228/2 "2022-06-22T09:52:38Z")

</div>

remove the hard coded filename from the file node & in your function add something like...

```auto
// your code
const reportDate = new Date().toISOString().replace(/[TG]/g,'_').replace(/:/g,'-').substring(0,19);
const reportName = 'mydata'
msg.filename = `c/reports/report-${reportName}-${reportDate}.pdf`
return msg;

```

---

<div class="post-metadata">

**Author:** ![Mauri](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@Mauri](https://discourse.nodered.org/u/Mauri)\
**Post date:** [22 June 2022 12:23 UTC](https://discourse.nodered.org/t/generate-a-pdf-file-with-variable-filename/64228/3 "2022-06-22T12:23:38Z")

</div>

Thanks for your answer! 🙏🏾  
It works! 🥳

---

<div class="post-metadata">

**Author:** ![Mauri](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@Mauri](https://discourse.nodered.org/u/Mauri)\
**Post date:** [22 June 2022 13:51 UTC](https://discourse.nodered.org/t/generate-a-pdf-file-with-variable-filename/64228/4 "2022-06-22T13:51:43Z")

</div>

How can i program if there is no data the line should not be written?

For example this line:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/b/0bb4a094fc3ce7af12f65c57bbc7def9d37a9a55.png)  
If there is no data from "0x\_0x\_we\_id", then the column should not be written...

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [22 June 2022 15:30 UTC](https://discourse.nodered.org/t/generate-a-pdf-file-with-variable-filename/64228/5 "2022-06-22T15:30:04Z")

</div>

If you post code/flow instead of pictures I can show you.

PS...

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

PS2  
If you dont reply to my comment I have no idea you have replied (there are 2 reply buttons, 1 at the bottom and one on a users last comment - this one notifies the user you are replying to them)

---

<div class="post-metadata">

**Author:** ![Mauri](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@Mauri](https://discourse.nodered.org/u/Mauri)\
**Post date:** [24 June 2022 17:58 UTC](https://discourse.nodered.org/t/generate-a-pdf-file-with-variable-filename/64228/6 "2022-06-24T17:58:18Z")

</div>

> [@Steve-Mcl](#):
>
> If you post code/flow instead of pictures I can show you.

This is my flow:  
[Flow\_Mauri.txt](https://discourse.nodered.org/uploads/short-url/aRZ8MvxVUSxpM4YgRjdmaxfu66p.txt) (50.3 KB)

The flow is in a -txt file, 'cause it's to big to share with the ```

I hope you can understand it...  
Thanks

---

<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:** [8 July 2022 17:58 UTC](https://discourse.nodered.org/t/generate-a-pdf-file-with-variable-filename/64228/7 "2022-07-08T17:58:48Z")

</div>

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