Overview
This node, named "Doc Create Field," is designed to add custom fields into an existing PDF document. It takes a PDF file as input and modifies it by creating text fields on specified pages with given values and styling options. This functionality is useful in scenarios where you need to programmatically annotate or fill PDFs with dynamic content, such as generating filled forms, stamping documents with metadata, or adding watermarks.
Practical examples include:
- Automatically filling out form fields in a contract PDF before sending it to clients.
- Adding page-specific notes or labels to a report PDF.
- Overlaying dynamic data like dates, names, or codes onto invoices or certificates.
Properties
Name | Meaning |
---|---|
Property Name | The name of the binary property in the input item that contains the PDF document to be modified. |
Property Name Out | The name of the binary property where the output PDF (with added fields) will be stored. |
Configuration JSON | A JSON string defining the fields to create inside the PDF. Each field object must specify: • page : the zero-based page number where the field will be added.• value : the text content of the field.• options : an object with positioning and styling properties:- x and y : coordinates on the page.- size : font size (optional).- opacity : transparency level (optional).- colorRed , colorGreen , colorBlue : RGB color components (optional). |
Max PDF Size | Maximum allowed size of the input PDF file in megabytes. If the input exceeds this size, the node will throw an error. |
Output
The node outputs items containing the original JSON data plus a binary property holding the modified PDF document. The output binary property name is configurable via "Property Name Out." The PDF binary data represents the original document with the newly created fields embedded according to the configuration.
If the input PDF is valid and within size limits, the output will contain:
json
: Original JSON data from the input item.binary
: Contains the updated PDF under the configured output binary property name.pairedItem
: Maintains pairing with the input item for traceability.
Dependencies
- Uses the
pdf-lib
library to load, modify, and save PDF documents. - Relies on helper functions (
isPDFDocument
andcreateField
) from a local utility module to validate input and create fields. - Requires the input PDF to be provided as binary data in the specified input property.
- No external API keys or services are needed; all processing is done locally within the node.
Troubleshooting
- Input is not a PDF: If the binary data in the specified input property is not a PDF, the node throws an error indicating the expected PDF MIME type was not found. Ensure the input binary property contains a valid PDF file.
- Input PDF too large: If the input PDF exceeds the configured maximum size, the node will error out. Increase the "Max PDF Size" property if necessary or reduce the input file size.
- Invalid Configuration JSON: Malformed or incorrect JSON in the "Configuration JSON" property will cause parsing errors. Validate the JSON format and ensure all required fields (
page
,value
,options
) are correctly specified. - Page index out of range: Specifying a page number that does not exist in the PDF may cause runtime errors. Verify that page indices in the configuration correspond to actual pages in the input PDF.
- Continue On Fail behavior: If enabled, the node will continue processing other items even if one fails, returning error details in the output for failed items.
Links and References
- pdf-lib GitHub repository – Library used for PDF manipulation.
- n8n Documentation - Creating Custom Nodes – Guide on building nodes similar to this one.