Skip to main content
Version: 1.28 (Current)

Generate PDF

Audience: Low-code Engineers

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

note

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​

Action NameDescription
Create/Update TokensBuilds values or HTML fragments to use in the HTML code.
Run SQL QueryLoads data from the database into tokens for the HTML code.
Redirect to URLOpens or downloads the generated PDF in the browser.
Send EmailSends the generated PDF as an attachment.
Merge PDFCombines the generated PDF with other PDFs.

Input Parameter Reference​

ParameterDescriptionSupports TokensDefaultRequired
Html Input TypeThe editor for HTML Code. Rich Text Editor changes your markup as you edit. Pick Codemirror to paste and keep your own HTML.NoRich Text EditorNo
HTML CodeThe HTML to render, including any <style> blocks. For example <h1>Invoice [InvoiceNumber]</h1>.Yesempty stringYes
PDF NameThe 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.Yesempty stringNo
Generated File DestinationThe 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.Yesnone selectedYes
Orientation LandscapeCheck to create landscape pages. Leave unchecked for portrait.NouncheckedNo
Paper SizeThe page size, for example A4, Letter or Legal. A, B and envelope sizes are also available.NoA4Yes
GrayscaleCheck to create the PDF in grayscale.NouncheckedNo
Other OptionsExtra 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.Yesempty stringNo
Enable Force DownloadCheck to make the Store LinkClick Url link download the file instead of opening it in the browser. It doesn't affect the other URLs.NouncheckedNo

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.

ParameterDescription
Store DNN FileIdThe file ID of the new PDF, for example to attach it to an email.
Store Absolute URLThe full URL of the PDF, for example https://example.com/Portals/0/Invoices/INV-1001.pdf.
Store Relative URLThe URL relative to the site root, for example /Portals/0/Invoices/INV-1001.pdf.
Store Physical PathThe path of the PDF on the server's disk.
Store LinkClick UrlA 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 Name if you need to keep older files.
  • HTML entities are decoded first. The HTML is decoded before rendering, so &lt;b&gt; becomes a real <b> tag. To show a literal < in the PDF, write &amp;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 with Error 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​

tip

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
}
}
]

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