Skip to main content

Generate PDFs

Learn how to generate PDFs using the built-in PDF exporter resource.

Retool provides a built-in PDF exporter to generate PDFs based on data in your Retool apps. To download the entire view of your Retool app as a PDF, you can instead use the utils.downloadPage() method.

PDF exporter example

Write queries using the PDF resource

Select the PDF Exporter (exporter) resource in the query editor and configure the following fields. On query success, a PDF file with the given contents is downloaded to the user's browser.

PDF content

The PDF content field accepts Markdown for formatting. To convert data, such as the contents of a table, to a format usable for Markdown, you may need to write additional transformers.

The following transformer constructs Markdown table formatting for {{ table1.data }}.

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

Filename

Use the Filename field to specify a PDF file name. This field accepts dynamic inputs. For example, set it to user_{{ usersTable.selectedRow.id }}_data to download the file as user_<selected_user_ID>_data.pdf.