Converting MySQL to PDF

I have read through a variety of responses in this forum and I can't get this to work:

I have a MySQL file called "Letter03" that I am trying to output as .PDF.

I am using code as below:

function convertToMarkdown(Letter03) {
const headers = [Object.keys(Letter03[0])];
const breaks = [headers[0].map(() => "---")];
const rows = => Object.values(r));
const tableEntries = headers.concat(breaks).concat(rows);
return => "|" + row.join("|") + "|").join("\n");

This generates the error message below:
ConvertToPdf1 failed (0.315s):You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'function convertToMarkdown(Letter03) { const headers = [Object.keys(Letter03[0])' at line 1

The MySql File "Letter03" is shown in the attached screen capture.

Any suggestions would be appreciated.


Hi @mdsmith1

Are you running this code in a transformer? This looks like Javascript code that should be run in either a JS query or a JS transformer.

Do you have data defined anywhere? If you run this code in a transformer on a MySQL query, data will be the response from the MySQL query.

What is the format of Letter03 when you query it from MySQL?

Hi Tess:

I solved this in 2 ways.

  1. I am routing out to PHP Code that uses FPDF code and this works well except it produces a .csv file that has to manually converted to a .xlsx file so it will hold together after emailing

  2. Retool has an app for exporting MySQL to an .xlsx which gives a stable file but the content does not extend to adjacent cells even when the adjacent cell is empty. So the headers are not good.

Generally we will use option 1) and get the user to "Save As" an Excel file (.xlsx).

I will mark this as a solution so we can close it off.



1 Like

Thanks so much for sharing! Glad you were able to move forward :blush: