# Generate pdf of mysql data

**URL:** https://discourse.nodered.org/t/generate-pdf-of-mysql-data/39979
**Category:** General
**Created:** [29 January 2021 05:35 UTC](https://discourse.nodered.org/t/generate-pdf-of-mysql-data/39979 "2021-01-29T05:35:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Yiez](https://avatars.discourse-cdn.com/v4/letter/y/67e7ee/32.png) [@Yiez](https://discourse.nodered.org/u/Yiez)
#### Post date: [29 January 2021 05:35 UTC](https://discourse.nodered.org/t/generate-pdf-of-mysql-data/39979/1 "2021-01-29T05:35:40Z")

</div>

Hi all,  
How can i generate a pdf file of mysql data in table format?  
I have installed the pdfmake node but not really sure how to continue with that...

---

<div class="post-metadata">

### Author: ![droberts](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/droberts/32/40295_2.png) [@droberts](https://discourse.nodered.org/u/droberts)
#### Post date: [29 January 2021 09:14 UTC](https://discourse.nodered.org/t/generate-pdf-of-mysql-data/39979/2 "2021-01-29T09:14:25Z")

</div>

Can you post a sample of the data you are returning from the mySQL node? I think you'll need to feed the data returned from the query through a function node to create a JSON object in the correct format to produce a table.

Based on the PDFMake example flows, and the below example JSON, this flow produces a table with a few rows and columns - it ends up stored in the root of your user directory. In my case C/Users/droberts/test.pdf

```auto
[{"id":"40aa0652.d1bf88","type":"pdfmake","z":"ced96e30.86933","name":"","outputType":"Buffer","inputProperty":"payload","options":"{}","outputProperty":"payload","x":580,"y":400,"wires":[["97d255cf.8bc138"]]},{"id":"30e9a280.04a94e","type":"inject","z":"ced96e30.86933","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"content\":[{\"layout\":\"lightHorizontalLines\",\"table\":{\"headerRows\":1,\"widths\":[\"*\",\"auto\",100,\"*\"],\"body\":[[\"First\",\"Second\",\"Third\",\"The last one\"],[\"First\",\"Second\",\"Third\",\"The last one\"],[\"First\",\"Second\",\"Third\",\"The last one\"],[\"Value 1\",\"Value 2\",\"Value 3\",\"Value 4\"]]}}]}","payloadType":"json","x":420,"y":400,"wires":[["40aa0652.d1bf88"]]},{"id":"97d255cf.8bc138","type":"file","z":"ced96e30.86933","name":"","filename":"test.pdf","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"none","x":740,"y":400,"wires":[[]]},{"id":"da72935b.7c159","type":"comment","z":"ced96e30.86933","name":"Simple Example PDF Table","info":"This is the simplest PDF test as seen in the pdfmake examples [here](http://pdfmake.org/playground.html)","x":470,"y":360,"wires":[]}]

```

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

```auto
var docDefinition = {
  content: [
    {
      layout: 'lightHorizontalLines', // optional
      table: {
        // headers are automatically repeated if the table spans over multiple pages
        // you can declare how many rows should be treated as headers
        headerRows: 1,
        widths: ['*', 'auto', 100, '*'],

        body: [
          ['First', 'Second', 'Third', 'The last one'],
          ['Value 1', 'Value 2', 'Value 3', 'Value 4'],
          [{ text: 'Bold value', bold: true }, 'Val 2', 'Val 3', 'Val 4']
        ]
      }
    }
  ]
};

```

[https://pdfmake.github.io/docs/0.1/document-definition-object/tables/](https://pdfmake.github.io/docs/0.1/document-definition-object/tables/)

---

<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: [30 March 2021 09:15 UTC](https://discourse.nodered.org/t/generate-pdf-of-mysql-data/39979/3 "2021-03-30T09:15:23Z")

</div>

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