DocxToPdf icon

DocxToPdf

Converts DOCX templates to populated DOCX and PDF files

Overview

This node processes DOCX template files by populating them with user-provided JSON data, then saves the populated DOCX file and generates a PDF version of it. It is useful in scenarios where users need to automate document generation, such as creating personalized reports, contracts, invoices, or letters from templates with dynamic content.

For example, a user can provide a DOCX template containing placeholders for customer names and order details, supply corresponding JSON data, and automatically produce both a filled DOCX document and a PDF copy ready for distribution or archiving.

Properties

Name Meaning
Template File Absolute path to the DOCX template file containing variables/placeholders to populate.
Output DOCX File Absolute path where the populated DOCX file will be saved after filling in the variables.
Output PDF File Absolute path where the converted PDF file will be saved after generating from the DOCX.
JSON Data JSON object with keys matching the template variables; used to fill the DOCX template.

Output

The node outputs an array of items, each containing a json field with the following structure:

  • success: Boolean indicating if the operation succeeded.
  • outputDocxFile: The absolute path where the populated DOCX file was saved.
  • outputPdfFile: The absolute path where the generated PDF file was saved.
  • message: A success message confirming completion.

If an error occurs and the node is set to continue on failure, the output item will contain:

  • success: false
  • error: Error message describing what went wrong.

No binary data is output by this node.

Dependencies

  • Requires access to the filesystem to read the DOCX template and write output files.
  • Uses the pizzip and docxtemplater libraries to process and populate DOCX templates.
  • Uses the pdf-lib library to generate PDF files (currently creates a placeholder PDF stating that external service integration is required for real conversion).
  • No external API keys or online services are used by default, but note that the PDF generation is a stub and does not convert DOCX content to PDF properly.

Troubleshooting

  • Template file does not exist: Ensure the provided path to the DOCX template is correct and accessible by the node.
  • Failed to read template file: Check file permissions and confirm the file is not locked or corrupted.
  • Failed to initialize template processor: Verify the DOCX template is valid and not corrupted.
  • Template variable not found: This error indicates a mismatch between JSON data keys and template placeholders. Confirm that all variables used in the DOCX template have corresponding keys in the JSON data.
  • Failed to save DOCX file: Check write permissions and ensure the output directory exists or can be created.
  • Failed to generate PDF file: Currently, the PDF generation only creates a placeholder PDF. For actual DOCX to PDF conversion, integration with an external service is needed.
  • If the node throws unexpected errors, verify input parameters and file paths carefully.

Links and References

Discussion