
Apache PDFBox FromHtml
CertifiedRender HTML to a PDF
Apache PDFBox FromHtml
Render HTML to a PDF
Converts an XHTML document (inline html or a file in internal storage via from) to a PDF with OpenHTMLtoPDF. The input must be well-formed XHTML: close every tag and escape & as &. Page margins and breaks come from CSS, for example @page { margin: 20mm }.
Images, stylesheets and fonts are loaded only from inline data: URIs and Kestra internal storage (kestra:// URIs, or paths relative to baseUri when it points to internal storage). Remote http(s) resources are blocked by default because the HTML may come from user input; set allowRemoteResources to fetch them through Kestra's HTTP client. file: URIs are always blocked. A resource that cannot be loaded is skipped with a warning naming its URL, and the from file and every resource are limited to maxResourceBytes.
type: io.kestra.plugin.pdfbox.document.FromHtmlExamples
Generate a PDF report from HTML
id: pdf_from_html
namespace: company.team
tasks:
- id: render
type: io.kestra.plugin.pdfbox.document.FromHtml
html: |
<html>
<head><style>@page { margin: 20mm }</style></head>
<body>
<h1>Daily report</h1>
<p>Execution: {{ execution.id }}</p>
</body>
</html>
pageSize: A4
- id: log_uri
type: io.kestra.plugin.core.log.Log
message: "{{ outputs.render.uri }}"
Render an uploaded HTML file
id: pdf_from_html_file
namespace: company.team
inputs:
- id: page
type: FILE
tasks:
- id: render
type: io.kestra.plugin.pdfbox.document.FromHtml
from: "{{ inputs.page }}"
pageSize: LETTER
Embed an uploaded logo in generated HTML
id: pdf_from_html_logo
namespace: company.team
inputs:
- id: logo
type: FILE
tasks:
- id: render
type: io.kestra.plugin.pdfbox.document.FromHtml
html: |
<html><body>
<img src="{{ inputs.logo }}" width="120"/>
<p>Invoice</p>
</body></html>
Properties
allowRemoteResources booleanstring
falseAllow loading remote http and https resources
Off by default to avoid server-side request forgery when the HTML is not fully trusted. When on, remote resources are fetched with Kestra's HTTP client. Default false.
assets
Assets this task consumes as inputs or produces as outputs, for lineage tracking and the asset graph (Enterprise Edition). A flow declaring this property on a task is rejected in the open-source edition.
io.kestra.core.models.assets.AssetsDeclaration
IGNOREFAILWARNAsset failure behavior
Behavior applied to the task state when a declared asset fails to render, emit, or be persisted (e.g. a lock conflict): FAIL escalates it to FAILED, WARN (default) warns it if it would otherwise succeed, IGNORE leaves the state untouched.
Whether to auto-register assets referenced dynamically at runtime that are not statically declared in inputs or outputs.
The assets consumed as inputs.
io.kestra.core.models.assets.AssetIdentifier
1The assets produced as outputs.
io.kestra.plugin.ee.assets.Dataset
1150{}1150io.kestra.plugin.ee.assets.File
1150{}1150io.kestra.plugin.ee.assets.Table
1150{}1150io.kestra.plugin.ee.assets.VM
1150{}1150io.kestra.core.models.assets.External
1150{}1150io.kestra.core.models.assets.Custom
11501Custom asset type
{}1150baseUri string
Base URI for relative links in the HTML
Usually an internal storage URI; relative src and href values are resolved against it. Defaults to from when that is set.
from string
An XHTML file to render, as an internal storage URI
Set either html or from.
Pebble expression referencing an Internal Storage URI e.g. {{ outputs.mytask.uri }}.
html string
XHTML to render
Set either html or from.
maxResourceBytes integerstring
20971520Largest HTML file or resource to load, in bytes
Applies to the from file and to every image, stylesheet or font, from internal storage or the network. Default 20 MiB (20,971,520), between 1 and 1 GiB (1,073,741,824).
orientation string
PORTRAITPORTRAITLANDSCAPEDefault page orientation
Default PORTRAIT.
pageSize string
A4A3A4A5LETTERLEGALIMAGEDefault page size, used when the CSS does not set one
Default A4.
Outputs
pageCount integer
Number of pages
uri string
uriInternal storage URI of the PDF