Skip to main content

Retool

Prerequisites

  • A PolyDoc account and API key — sign up for free, no credit card required. The free plan includes 150 PDF conversions per month.
  • A Retool account — sign up for free.

Use Case 1: Generate PDFs from Internal Tool

Add a "Generate PDF" button to any Retool app that sends form or table data to PolyDoc and downloads the result.
Button click → REST API query (PolyDoc) → Download / display PDF

Add a REST API resource for PolyDoc

Go to Resources and click Create a new resource. Choose REST API and configure:

  • Name: PolyDoc
  • Base URL: https://api.polydoc.tech
  • Default headers:
    • Authorization = Bearer YOUR_API_KEY (get your key from the Dashboard)
    • Content-Type = application/json
    • X-Sandbox = true

Click Save. This resource is now available across all your Retool apps.

Screenshot placeholder: /img/guides/retool/retool-uc1-create-resource.png

Create a query to generate PDFs

In your app, open the Query Editor and create a new query using the PolyDoc resource:

  • Action: POST
  • Path: /pdf/convert
  • Body: JSON referencing component values, e.g.:
{
  "templateId": "YOUR_TEMPLATE_ID",
  "data": {
    "name": {{ nameInput.value }},
    "amount": {{ amountInput.value }},
    "date": {{ dateInput.value }}
  }
}
Screenshot placeholder: /img/guides/retool/retool-uc1-create-query.png

Build the UI

Drag components onto the canvas to build your UI: a Form or Table for data entry and a Button labeled "Generate PDF". Optionally add a PDF Viewer component to preview the result inline.

Screenshot placeholder: /img/guides/retool/retool-uc1-build-ui.png

Wire the button to the query

Select the button and add an Event Handler:

  • Action: Run Query → select your PolyDoc query
  • On success: add a second handler with Trigger Download to save the PDF binary response as a file

Click the button in preview mode to test. The PDF will download automatically.

Screenshot placeholder: /img/guides/retool/retool-uc1-event-handler.png

Use Case 2: Bulk PDF Generation

Select multiple rows from a table and generate a PDF for each one in a single batch.
Table selection → JavaScript query (loop) → PolyDoc API → Download

Load records into a Table component

Add a Table component and connect it to your data source (SQL query, REST API, or Google Sheets resource). Enable Multiple row selection in the table settings.

Screenshot placeholder: /img/guides/retool/retool-uc2-table.png

Create a JavaScript query for bulk generation

Create a JavaScript query that iterates over selected rows and calls PolyDoc for each:

const rows = table1.selectedRows;
const results = [];

for (const row of rows) {
  const resp = await PolyDocQuery.trigger({
    additionalScope: {
      rowData: row,
    },
  });
  results.push(resp);
}

return results;
Screenshot placeholder: /img/guides/retool/retool-uc2-js-query.png

Collect results and download

After the loop completes, use utils.downloadFile() for each result, or zip the PDFs together and trigger a single download. A progress indicator (e.g., a Statistic component) helps users track the batch status.

Screenshot placeholder: /img/guides/retool/retool-uc2-download.png

Add a "Generate All" button

Add a Button labeled "Generate All" and set its event handler to run the JavaScript query. Users can now select rows, click the button, and receive all PDFs at once.

Screenshot placeholder: /img/guides/retool/retool-uc2-generate-all.png