Skip to main content

Create PDF From JSON

Creates a new PDF document or updates an existing one using a JSON definition file that describes the PDF structure and content.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • JSON Path - Path to the JSON file containing the PDF definition.

Options

  • In PDF Path - Input PDF path for updating an existing PDF with the JSON definition. Optional.
  • Out PDF Path - Output path where the created or updated PDF file will be saved. Optional.
note

At least one of In PDF Path or Out PDF Path must be provided:

  • If only Out PDF Path is provided: Creates a new PDF from JSON
  • If only In PDF Path is provided: Updates the existing PDF in place
  • If both are provided: Reads the input PDF and saves the result to the output path

Output

This node does not produce any output variables. The result is saved to the specified PDF file.

How It Works

The Create PDF From JSON node generates or modifies PDF documents based on a JSON definition. When executed, the node:

  1. Validates the JSON path and reads the JSON definition
  2. Determines the operation mode based on provided paths
  3. If updating: Opens the existing PDF file
  4. Applies the JSON definition to create or modify the PDF structure
  5. Saves the result to the appropriate output path

Operation Modes

In PDF PathOut PDF PathAction
EmptyProvidedCreate new PDF and save to output path
ProvidedEmptyUpdate existing PDF in place
ProvidedProvidedRead input PDF, apply changes, save to output path

Use Cases

  • PDF Generation: Create PDFs dynamically from structured data
  • Template Processing: Generate documents from JSON-based templates
  • PDF Modification: Update existing PDFs with new content or structure
  • Batch Document Creation: Generate multiple PDFs from different JSON files
  • Form Creation: Define PDF form structures programmatically

JSON Definition Format

The JSON file defines the PDF structure including pages, content, and properties. Consult the pdfcpu library documentation for the complete JSON schema specification.

Example basic structure:

{
"pages": [
{
"content": "Page content here",
"properties": {
"size": "A4"
}
}
]
}

Error Handling

The node will return specific errors in the following cases:

  • Empty or invalid JSON path
  • JSON file not found or invalid JSON format
  • Neither In PDF Path nor Out PDF Path is provided
  • Invalid PDF path (when In PDF Path is provided)
  • Input PDF file not found (when In PDF Path is provided)
  • Invalid JSON definition structure
  • Insufficient permissions to read input files or write output file

Usage Notes

  • The JSON definition follows the pdfcpu library schema
  • When updating an existing PDF, the original file is modified according to the JSON definition
  • For creating new PDFs, ensure the JSON contains all required PDF elements
  • The output directory must exist before saving the PDF
  • Complex PDF structures may require detailed JSON definitions
  • Validate your JSON structure before processing to avoid errors

Tips for Effective Use

  • Start Simple: Begin with basic JSON definitions and gradually add complexity
  • Validate JSON: Use a JSON validator to check syntax before processing
  • Backup Originals: When updating existing PDFs, always specify an output path to preserve originals
  • Reference Documentation: Consult pdfcpu documentation for detailed JSON schema
  • Testing: Test JSON definitions with sample files first
  • Error Handling: Enable Continue On Error when batch processing multiple files
  • Export To JSON: Extract form data from existing PDFs
  • Fill From JSON: Fill PDF form fields with JSON data