Generate pdf of mysql data

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

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

[{"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":[]}]

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/

1 Like

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