For the complete documentation index, see llms.txt. This page is also available as Markdown.

PDF processing

The PDF processing class provides static utility functions that create and manipulate PDF documents. It generates PDFs from structured JSON (pdfmake format), converts HTML content into PDFs, and merges multiple documents (PDF, PNG, JPG, and HEIC) into a single PDF file. This class contains static functions only and does not require an instance. The code class name is Pdf.

mergeDocuments

Merges multiple source documents into a single PDF file. The function accepts PDFs, PNG images, or JPG images, and automatically converts the images to PDF pages before merging. HEIC images are supported when provided as file objects with a path. Entries that cannot be processed are skipped and logged.

Parameters

Input
Description
Type

files

An array where each element is either a base64-encoded file string or an object containing a path property pointing to the file.

array

Output

Returns a file object representing the merged PDF file, including its path, name, size, and type. Returns nothing if the input is not a non-empty array.

Example

# files
  - path: /shared/documents/report.pdf
  - path: /shared/documents/scan.png

createPdfFileFromJson

Creates a new PDF file from a structured JSON object that follows the pdfmake document definition format. Use this format to control the PDF layout and content precisely. See the pdfmake playground to test layouts.

Parameters

Input
Key
Description
Type

content

The content definition object or array following the pdfmake syntax.

any

options

format

The page size (such as A4, A5, or LETTER). Default A4.

string

orientation

The page orientation: portrait or landscape. Default portrait.

string

Output

Returns a file object representing the generated PDF file.

Example

createPdfBufferFromJson

Creates a PDF from a pdfmake JSON object and returns it as a base64-encoded string instead of writing it to a file.

Parameters

Input
Key
Description
Type

content

The content definition object or array following the pdfmake syntax.

any

options

format

The page size (such as A4, A5, or LETTER). Default A4.

string

orientation

The page orientation: portrait or landscape. Default portrait.

string

Output

Returns a base64-encoded string representing the generated PDF document.

Example

createPdfFileFromHtml

Converts an HTML string into a new PDF file.

Parameters

Input
Key
Description
Type

html

The HTML content string to convert.

string

options

format

The page size. Default A4.

string

orientation

The page orientation: portrait or landscape. Default portrait.

string

tableAutoSize

Automatically sizes HTML tables. Default true.

boolean

removeExtraBlanks

Removes extra blank spaces from the document. Default false.

boolean

Output

Returns a file object representing the generated PDF file.

Example

createPdfBufferFromHtml

Converts an HTML string into a PDF and returns it as a base64-encoded string.

Parameters

Input
Key
Description
Type

html

The HTML content string to convert.

string

options

format

The page size. Default A4.

string

orientation

The page orientation: portrait or landscape. Default portrait.

string

tableAutoSize

Automatically sizes HTML tables. Default true.

boolean

removeExtraBlanks

Removes extra blank spaces from the document. Default false.

boolean

Output

Returns a base64-encoded string representing the generated PDF document.

Example

Last updated

Was this helpful?