pdfFile(html: $htmlContent, name: $filename,
pageSize: $size, landscape: $landscape,
pageWidth: $width, pageHeight: $height,
marginLeft: $ml, marginRight: $mr,
marginTop: $mt, marginBottom: $mb,
resolution: $dpi
)
Converts HTML content into a PDF document. The HTML is rendered as a PDF using the Flying Saucer library, which produces high-quality PDF output from well-formed XHTML.
This function accepts four types of input:
"""..."""){{{...}}})text/html or text/plain containing HTML markupThis function is particularly useful for creating reports, invoices or other documents that need to be generated dynamically from HTML templates and exported as PDF.
Important: The HTML must be well-formed XHTML. All tags must be properly closed, and self-closing tags should use XHTML syntax (e.g. <br/> instead of <br>).
| Name | Type | Type Description | Mandatory | Standard |
|---|---|---|---|---|
| html | String, HTMLFragment, StructuredText or binary data | The HTML content to be converted to PDF. Can be a simple string (with triple quotes """..."""), an HTMLFragment (with triple curly braces {{{...}}} syntax with embedded TLScript expressions), a StructuredText from WYSIWYG editor fields (with automatically embedded BASE64 images) or a binary data with content type text/html or text/plain. Must be well-formed XHTML with all tags properly closed. |
yes | |
| name | Character string | The file name for the generated PDF. The extension .pdf is automatically added if not present. | no | document.pdf |
| pageSize | Character string | Default paper size. Supported values: A0, A1, A2, A3, A4, A5, A6, LETTER, LEGAL, TABLOID. If specified, pageWidth and pageHeight are automatically calculated based on the resolution. Values are not case sensitive. |
no | A4 (if neither pageSize nor pageWidth/pageHeight is specified) |
| landscape | Boolean | If true, page width and height are swapped for landscape format. Works with both pageSize and user-defined pageWidth/pageHeight values. |
no | false |
| pageWidth | Number/string | Override of the page width in pixels or size specification such as "15cm", "150mm", "7.5in". If specified, this takes precedence over the pageSize width. |
no | null |
| pageHeight | Number/string | Override of the page height in pixels or size specification such as "15cm", "150mm", "7.5in". If specified, this takes precedence over the pageHeight height. |
no | null |
| margin | Number/string | The left margin in pixels or size specification such as "1cm", "15mm", ".5in". | no | "15mm" |
| marginLeft | Number/string | The left margin in pixels or size specification such as "1cm", "15mm", ".5in". | no | null |
| marginRight | Number/string | The right margin in pixels or size specification such as "1cm", "15mm", ".5in". | no | null |
| marginTop | number | The top margin in pixels or size specification such as "1cm", "15mm", ".5in". | no | null |
| marginBottom | Number | The bottom margin in pixels or size specification such as "1cm", "15mm", ".5in". | no | null |
| resolution | Number | The rendering resolution in DPI (dots per inch). Higher values produce better quality, but larger files. This also influences how pageSize dimensions are calculated (e.g. A4 at 150 DPI = 1240x1754 px, A4 at 300 DPI = 2480x3508 px). |
no | 150 |
Type: BinaryData
Returns a binary data object containing the generated PDF with the content type application/pdf. Returns null if the HTML input is null or empty.
If the PDF generation fails, an RuntimeException with details of the error is triggered.
pdfFile("""
<html>
<body>
<h1>Hallo Welt</h1>
<p>Dies ist ein aus HTML generiertes PDF.</p>
</body>
</html>
""")
Output: A PDF document with the name "document.pdf" containing "Hello world" as a heading and a text paragraph.
pdfFile({{{
<html>
<body>
<h1>Rechnung für {$customer.get(`my.module:Customer#name`)}</h1>
<p>Datum: {dateFormat('yyyy-MM-dd').format(now())}</p>
<p>Betrag: {$invoice.get(`my.module:Invoice#amount`)}</p>
</body>
</html>
}}}, "rechnung-" + $invoice.get(`my.module:Invoice#number`))
Output: A PDF with dynamically generated content. The {{{...}}} syntax enables the embedding of TLScript expressions directly in the HTML, which are evaluated and securely HTML-encoded before the PDF is generated.
pdfFile("""
<html>
<body>
<h1>Rechnung</h1>
<p>Rechnung #12345</p>
</body>
</html>
""", "rechnung-12345")
Output: A PDF document with the name "rechnung-12345.pdf". The .pdf extension is added automatically.
pdfFile({{{
<html>
<head>
<style>
body \{ font-family: Arial, sans-serif; \}
h1 \{ color: #333366; \}
table \{ border-collapse: collapse; width: 100%; \}
th, td \{ border: 1px solid #ddd; padding: 8px; \}
th \{ background-color: #4CAF50; color: white; \}
</style>
</head>
<body>
<h1>Verkaufsbericht</h1>
<p>Erstellt am: {dateFormat('yyyy-MM-dd').format(now())}</p>
<table>
<tr>
<th>Produkt</th>
<th>Menge</th>
</tr>
<tr>
<td>Widget A</td>
<td>150</td>
</tr>
</table>
</body>
</html>
}}}, "verkaufsbericht-" + dateFormat('yyyy-MM-dd').format(now()))
Output: A styled PDF report with the name "sales-report-2025-10-22.pdf", including table, embedded CSS styles and dynamic date.
pdfFile({{{
<html>
<body>
<h1>Rechnungspositionen</h1>
<ul>
{$items.map(item -> {{{
<li>{item.get(`my.module:Item#name`)} - {item.get(`my.module:Item#price`)}</li>
}}})}
</ul>
</body>
</html>
}}})
Output: A PDF with a dynamically generated list of invoice items.
// WYSIWYG-Editor-Inhalt in PDF konvertieren
pdfFile($object.get(`my.module:Article#content`), name: "artikel.pdf")
Output: A PDF generated from StructuredText content. All embedded images in the WYSIWYG field are automatically converted to BASE64 data URIs and inserted into the PDF.
// US Letter Papierformat
pdfFile("""
<html>
<body>
<h1>US Letter Dokument</h1>
<p>Dieses Dokument verwendet das US Letter Papierformat.</p>
</body>
</html>
""", name: "letter-doc.pdf", pageSize: "LETTER")
Output: A PDF with US Letter paper size (216 x 279 mm) at the standard resolution of 150 DPI.
// A4 Querformat für breite Inhalte
pdfFile({{{
<html>
<body>
<h1>Breiter Bericht</h1>
<table style="width: 100%">
<tr>
<th>Spalte 1</th>
<th>Spalte 2</th>
<th>Spalte 3</th>
<th>Spalte 4</th>
<th>Spalte 5</th>
</tr>
</table>
</body>
</html>
}}}, name: "breiter-bericht.pdf", pageSize: "A4", landscape: true)
Output: A PDF in A4 landscape format (297 x 210 mm), ideal for wide tables or diagrams.
// US Letter-Format bei 200 DPI mit benutzerdefinierten Rändern
pdfFile("""
<html>
<body>
<h1>Hochqualitativer Bericht</h1>
<p>Dieses Dokument wird mit höherer Auflösung gerendert.</p>
</body>
</html>
""", name: "bericht.pdf", pageSize: "LETTER", resolution: 200,
marginLeft: 100, marginRight: 100, marginTop: 100, marginBottom: 100)
Output: A PDF with US letter page size at 200 DPI and 100 pixel margins on all pages.
// A4 mit minimalen Rändern
pdfFile({{{
<html>
<body>
<h1>Ganzseitiger Inhalt</h1>
<p>Dies verwendet minimale Ränder, um den Inhaltsbereich zu maximieren.</p>
</body>
</html>
}}}, name: "vollseite.pdf", pageSize: "A4",
marginLeft: 20, marginRight: 20, marginTop: 20, marginBottom: 20)
Output: A PDF with A4 page size and minimum 20-pixel margins (approx. 3.4mm at 150 DPI).
// A3 für große Diagramme
pdfFile({{{
<html>
<body>
<h1>Architekturdiagramm</h1>
<!-- Großer Diagramminhalt -->
</body>
</html>
}}}, name: "diagramm.pdf", pageSize: "A3")
Output: A PDF with A3 page size (297 x 420 mm), suitable for large diagrams or posters.
pageSize parameter supports A0 to A6 as well as LETTER, LEGAL and TABLOID. Dimensions are calculated automatically based on the resolutionlandscape: true, width and height are swapped. This works regardless of whether pageSize or user-defined dimensions are usedpageSize: "A4", landscape: true). This avoids specifying null for unused positional parameters