matrixdf icon

matrixdf

Fill PDF forms with text, images and annotations (no external API required)

Overview

This node allows you to fill PDF forms natively without relying on any external API. It supports filling existing form fields (text and checkboxes), adding custom text annotations at specific positions, and embedding images such as signatures into the PDF. The filled PDF can be output either as binary data or as a Base64 string.

Common scenarios where this node is beneficial include:

  • Automatically populating PDF forms with user data collected from other sources.
  • Adding dynamic text annotations or stamps to PDFs.
  • Embedding signatures or logos into PDF documents.
  • Generating customized PDF reports or contracts on the fly.

For example, you could use this node to fill out an employment application form by setting text fields like name and address, checking relevant checkboxes, adding a signature image, and then outputting the completed PDF for further processing or delivery.

Properties

Name Meaning
Source PDF Select the source of the PDF file: either "From URL" to fetch the PDF from a web address, or "From Binary Data" to use a PDF file already available in the workflow's binary data.
PDF URL The URL of the PDF file to fill (required if source is "From URL").
Binary Property The name of the binary property containing the PDF file (required if source is "From Binary Data").
Output Format How to return the filled PDF: either as "Binary" data or as a "Base64" encoded string.
Binary Property Name When output format is "Binary", the name of the binary property to store the filled PDF.
Output File Name When output format is "Binary", the filename to assign to the output PDF file.
Form Fields A collection of form fields to fill in the PDF. Each field includes:
- Field Name: the exact name of the form field.
- Field Type: "Text" or "Checkbox".
- Value: text to insert (for text fields).
- Checked: whether to check the box (for checkboxes).
Text Annotations A collection of custom text annotations to add anywhere in the PDF. Each annotation includes:
- Text content
- Page number (0-indexed)
- X and Y coordinates (points)
- Font size and font type
- Color in hex format (without #)
Images A collection of images to embed in the PDF. Each image includes:
- Image Source: "From URL" or "From Binary Property"
- Image URL or binary property name
- Page number (0-indexed)
- X and Y coordinates (points)
- Width and height (points)
Options Additional options:
- Flatten PDF: boolean to make form fields non-editable after filling.

Output

The node outputs the filled PDF in one of two formats:

  • Binary output: The PDF is returned as binary data under a specified binary property name. The JSON part contains metadata including the output file name and file size in bytes.
  • Base64 output: The PDF is returned as a Base64-encoded string in the JSON output along with the file size.

If the output is binary, the PDF can be directly used in subsequent nodes that accept binary files, such as sending via email or saving to disk.

Dependencies

  • Uses the pdf-lib library to manipulate PDF documents entirely within the node, requiring no external API.
  • Uses @pdf-lib/fontkit to support embedding fonts for text annotations.
  • Requires internet access if fetching PDFs or images from URLs.
  • No special credentials are required unless accessing protected URLs.

Troubleshooting

  • Field not found or wrong type warning: If a specified form field name does not exist in the PDF or the field type does not match (e.g., trying to set text on a checkbox), a warning is logged but processing continues. Verify field names and types exactly match those in the PDF.
  • Image embedding errors: If an image cannot be embedded as PNG, the node attempts JPG. Ensure images are valid PNG or JPG formats.
  • HTTP request failures: When fetching PDFs or images from URLs, network issues or invalid URLs will cause errors. Check URL correctness and network connectivity.
  • Flatten option: Enabling flatten makes form fields non-editable; disable if you want users to edit fields later.
  • Output format mismatch: Make sure to configure downstream nodes to handle the chosen output format (binary or Base64).

Links and References

Discussion