Generate PDF
Audience:
Low-code EngineersSkill Prerequisites:
HTML,CSS,Tokens
Creates a PDF from HTML and saves it in a portal folder. The HTML can contain tokens, so each PDF can show the data of the current record or user.
The PDF is rendered on the web server by wkhtmltopdf, which ships with Plant an App. The action saves the file and puts its URL, path and file ID in tokens. It doesn't send the file to the browser. Use a following action, such as Redirect to URL, for that.
This action requires the PDF feature to be licensed.
Typical Use Cases
- Generate receipts, invoices and order confirmations
- Generate contracts or certificates filled in with form data
- Create a PDF report and attach it to an email
Don't use it to
- Combine existing PDFs. Use Merge PDF instead.
- Stamp one PDF on top of another. Use Overlay PDF instead.
- Take pages out of an existing PDF. Use Extract PDF instead.
- Create an editable document. Use Convert from HTML to Word instead.
Related Actions
| Action Name | Description |
|---|---|
| Create/Update Tokens | Builds values or HTML fragments to use in the HTML code. |
| Run SQL Query | Loads data from the database into tokens for the HTML code. |
| Redirect to URL | Opens or downloads the generated PDF in the browser. |
| Send Email | Sends the generated PDF as an attachment. |
| Merge PDF | Combines the generated PDF with other PDFs. |
Input Parameter Reference
| Parameter | Description | Supports Tokens | Default | Required |
|---|---|---|---|---|
| Html Input Type | The editor for HTML Code. Rich Text Editor changes your markup as you edit. Pick Codemirror to paste and keep your own HTML. | No | Rich Text Editor | No |
| HTML Code | The HTML to render, including any <style> blocks. For example <h1>Invoice [InvoiceNumber]</h1>. | Yes | empty string | Yes |
| PDF Name | The file name without the extension. .pdf is always added. Accents are converted to plain letters and characters that aren't allowed in file names are removed. Leave empty to use a random name. | Yes | empty string | No |
| Generated File Destination | The portal folder to save the PDF in. Select a folder, or in expression mode enter a folder path relative to the portal root, for example Invoices/2026. The folder must already exist. | Yes | none selected | Yes |
| Orientation Landscape | Check to create landscape pages. Leave unchecked for portrait. | No | unchecked | No |
| Paper Size | The page size, for example A4, Letter or Legal. A, B and envelope sizes are also available. | No | A4 | Yes |
| Grayscale | Check to create the PDF in grayscale. | No | unchecked | No |
| Other Options | Extra wkhtmltopdf command-line options, added as-is. For example --margin-top 20mm --margin-bottom 20mm or --javascript-delay 1000. See the wkhtmltopdf documentation. Use with caution, because a wrong option makes the action fail. | Yes | empty string | No |
| Enable Force Download | Check to make the Store LinkClick Url link download the file instead of opening it in the browser. It doesn't affect the other URLs. | No | unchecked | No |
Output Parameters Reference
Each parameter is the name of a token to create. Leave any of them empty if you don't need that value.
| Parameter | Description |
|---|---|
| Store DNN FileId | The file ID of the new PDF, for example to attach it to an email. |
| Store Absolute URL | The full URL of the PDF, for example https://example.com/Portals/0/Invoices/INV-1001.pdf. |
| Store Relative URL | The URL relative to the site root, for example /Portals/0/Invoices/INV-1001.pdf. |
| Store Physical Path | The path of the PDF on the server's disk. |
| Store LinkClick Url | A LinkClick.aspx link to the file. It downloads the file when Enable Force Download is checked. |
Images, CSS and JavaScript
The HTML is saved to a temporary file on the server before it's rendered, so relative links such as /Portals/0/logo.png don't point to your site. Use absolute URLs for everything you load:
<img src="https://example.com/Portals/0/Images/logo.png" alt="Logo">
<link rel="stylesheet" href="https://example.com/Portals/0/Css/invoice.css">
Inline styles and <style> blocks in the HTML always work.
JavaScript in the HTML runs before the page is captured. If a script builds part of the page, such as a chart, give it time to finish with --javascript-delay <milliseconds> in Other Options.
Considerations
- Existing files are replaced. If a file with the same name is already in the folder, it's overwritten. Put a unique value, such as an ID or date, in
PDF Nameif you need to keep older files. - HTML entities are decoded first. The HTML is decoded before rendering, so
<b>becomes a real<b>tag. To show a literal<in the PDF, write&lt;. - Missing resources don't fail the action. If an image or stylesheet can't be loaded, the PDF is still created without it. Check the PDF if something looks wrong.
- One PDF at a time. The server renders one PDF at a time. When many users generate PDFs at once, the requests wait for each other.
- Errors. If wkhtmltopdf fails, for example because of an invalid option in
Other Options, the action fails withError generating PDF (exit code: ...)followed by wkhtmltopdf's output. - Execution continues. After the PDF is saved, the next actions run and can use the output tokens.
- Rendering engine. wkhtmltopdf uses an older WebKit engine. Modern CSS, such as flexbox and grid, may not render as in current browsers. Tables, floats and inline styles are the most reliable.
Examples
To understand how to use the below examples, please see Running Examples.
1. Create an invoice and download it
The first action creates Invoices/INV-<InvoiceNumber>.pdf from HTML with a logo and a styled table. The second action redirects the browser to the PDF so it downloads. The InvoiceNumber, CustomerName and Total tokens must exist, for example from a form or a Run SQL Query action.
[
{
"Title": "Generate PDF",
"ActionType": "GeneratePDF",
"Description": "Create the invoice PDF",
"Condition": null,
"Parameters": {
"HtmlInputType": {
"Expression": "",
"Value": "codemirror",
"IsExpression": false,
"Parameters": {}
},
"HTMLCode": "<html>\n<head>\n <style>\n body { font-family: Arial, sans-serif; }\n h1 { color: #2e7d32; }\n table { width: 100%; border-collapse: collapse; }\n td, th { border: 1px solid #ccc; padding: 6px; }\n </style>\n</head>\n<body>\n <img src=\"https://learn.plantanapp.com/img/pap-logo.png\" alt=\"Logo\" width=\"150\">\n <h1>Invoice [InvoiceNumber]</h1>\n <p>Customer: [CustomerName]</p>\n <table>\n <tr><th>Description</th><th>Total</th></tr>\n <tr><td>Services</td><td>[Total]</td></tr>\n </table>\n</body>\n</html>",
"PDFName": "INV-[InvoiceNumber]",
"PathDestination": {
"Expression": "Invoices",
"Value": "",
"IsExpression": true,
"Parameters": {}
},
"OrientationLandscape": false,
"PaperSize": {
"Expression": "",
"Value": "A4",
"IsExpression": false,
"Parameters": {}
},
"Grayscale": false,
"OtherOptions": "",
"StoreFileId": "InvoiceFileId",
"StoreAbsoluteURL": "InvoiceUrl",
"StoreRelativeURL": "",
"StorePhysicalPath": "",
"StoreLinkClick": "",
"ForceDownload": false
}
},
{
"Title": "Redirect to URL",
"ActionType": "RedirectToUrl",
"Description": "Download the invoice",
"Condition": null,
"Parameters": {
"Url": "[InvoiceUrl]",
"EscapeUrl": "",
"OpenInPopup": "",
"PopupTitle": "",
"OpenInNewTab": "",
"ForceDownload": true
}
}
]
2. Create a landscape report with margins and a footer
This action creates a landscape Letter-size report in the portal root folder. Other Options adds 20 mm top and bottom margins, a footer and a one-second delay so the page's JavaScript can finish.
{
"Title": "Generate PDF",
"ActionType": "GeneratePDF",
"Description": "Create the monthly report",
"Condition": null,
"Parameters": {
"HtmlInputType": {
"Expression": "",
"Value": "codemirror",
"IsExpression": false,
"Parameters": {}
},
"HTMLCode": "<h1 id=\"title\">Monthly report</h1>\n<p>Generated for [User:DisplayName].</p>\n<script>\n document.getElementById('title').style.color = 'red';\n</script>",
"PDFName": "report-[User:Username]",
"PathDestination": {
"Expression": "",
"Value": "/",
"IsExpression": false,
"Parameters": {}
},
"OrientationLandscape": true,
"PaperSize": {
"Expression": "",
"Value": "Letter",
"IsExpression": false,
"Parameters": {}
},
"Grayscale": false,
"OtherOptions": "--margin-top 20mm --margin-bottom 20mm --footer-center Confidential --footer-font-size 8 --javascript-delay 1000",
"StoreFileId": "",
"StoreAbsoluteURL": "ReportUrl",
"StoreRelativeURL": "",
"StorePhysicalPath": "",
"StoreLinkClick": "",
"ForceDownload": false
}
}
Revised 09/26/2026