Overview
This node populates a DOCX template with JSON data and outputs the result in DOCX format, PDF format, or both. It is useful for automating document generation where templates contain placeholders that need to be replaced with dynamic data, such as generating personalized letters, contracts, reports, or certificates.
Typical use cases include:
- Filling out contract templates with client-specific information.
- Creating customized reports by injecting data into predefined DOCX templates.
- Generating certificates or awards with recipient names and details.
- Automating invoice creation from JSON data.
The node supports loading the DOCX template either from a file path or from binary data passed into the node, making it flexible for different workflows.
Properties
| Name | Meaning |
|---|---|
| Template Source | Source of the DOCX template. Options: "File Path" (load template from a file system path), "Binary Data" (load template from incoming binary data). |
| Template File | Path to the DOCX template file on disk. Required if "Template Source" is set to "File Path". |
| Binary Property | Name of the binary property containing the DOCX template. Required if "Template Source" is set to "Binary Data". |
| JSON Data | JSON object where keys correspond to variables/placeholders in the DOCX template to be replaced with their values. |
| Output Format | The output format to return. Options: "PDF Only", "DOCX Only", "Both PDF and DOCX". |
Output
The node outputs an array of items corresponding to each input item processed. Each output item contains:
jsonfield:success: Boolean indicating whether the operation succeeded.message: A descriptive message about the operation result.error: Present only if the operation failed, containing the error message.
binaryfield:- Depending on the selected output format:
- For DOCX output: Contains a binary property named
docxFilewith the populated DOCX document. - For PDF output: Contains a binary property named
pdfFilewith the generated PDF document. - For both: Contains both
docxFileandpdfFile.
- For DOCX output: Contains a binary property named
- Depending on the selected output format:
The binary data represents the actual files ready for download, further processing, or storage.
Dependencies
- Requires the
docxtemplaterlibrary to process and render DOCX templates. - Uses
pizzipfor ZIP file handling inside DOCX files. - Uses
docx2pdf-converterfor converting DOCX files to PDF format. - Node.js built-in modules:
fs,fs/promises,path, andos. - Temporary directory access for intermediate file storage during PDF conversion.
- No external API keys or credentials are required.
Troubleshooting
- Template file does not exist: If using "File Path" as the template source, ensure the specified file path is correct and accessible.
- No binary data found in property: When using "Binary Data" as the template source, verify that the input item contains the binary property with the expected name and valid base64 data.
- Failed to read template file: Check file permissions and ensure the file is not locked or corrupted.
- Failed to decode binary data: Confirm that the binary data is properly encoded in base64.
- Failed to load template / render template: Ensure the JSON data keys match the placeholders in the DOCX template exactly; mismatches or syntax errors in the template can cause rendering failures.
- PDF conversion timed out or failed: The node writes temporary files and waits for the PDF conversion to complete. If this times out, check that the environment supports the PDF conversion tool and has necessary permissions.
- Error cleaning up temp files: Temporary files may fail to delete due to permission issues; these do not affect the main operation but should be monitored.
If the node is configured to continue on failure, errors will be reported in the output JSON without stopping the workflow.