# 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:** 1\
**Showing post:** 2

<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;

```

---

_[View the full topic](https://discourse.nodered.org/t/generate-a-pdf-file-with-variable-filename/64228)._
