Apache PDFBox FromHtml

Apache PDFBox FromHtml

Certified

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.

yaml
type: io.kestra.plugin.pdfbox.document.FromHtml

Generate a PDF report from HTML

yaml
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

yaml
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

yaml
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
Defaultfalse

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

Definitions
assetFailureBehaviorstring
Possible Values
IGNOREFAILWARN

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

enableAutobooleanstring

Whether to auto-register assets referenced dynamically at runtime that are not statically declared in inputs or outputs.

inputsarray

The assets consumed as inputs.

id*string
Min length1
typestring
outputs

The assets produced as outputs.

id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*string
Min length1

Custom asset type

descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150

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.

An XHTML file to render, as an internal storage URI

Set either html or from.

XHTML to render

Set either html or from.

Default20971520

Largest 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).

DefaultPORTRAIT
Possible Values
PORTRAITLANDSCAPE

Default page orientation

Default PORTRAIT.

DefaultA4
Possible Values
A3A4A5LETTERLEGALIMAGE

Default page size, used when the CSS does not set one

Default A4.

Number of pages

Formaturi

Internal storage URI of the PDF