Custom PDF to Images

Converts PDF pages to images

Overview

This node converts each page of a PDF file into separate PNG image files. It is useful in workflows where you need to process, analyze, or share individual pages of a PDF as images. Common scenarios include document digitization, extracting graphics from reports, or preparing PDFs for OCR (Optical Character Recognition) processing.

Practical examples:

  • Splitting a multi-page scanned contract into individual images for further analysis.
  • Converting a PDF presentation into images for embedding in web content.
  • Preparing PDF pages for machine learning models that require image input.

Properties

Name Type Meaning
PDF File Path String The path to the PDF file to be converted.
Output Folder Path String The path to the folder where the resulting images will be saved.

Output

The node returns the original input data unchanged. The actual output (the generated images) is written to the specified output folder on disk. No binary data is returned via n8n; instead, the images are saved as PNG files named page_1.png, page_2.png, etc., in the output directory.

Dependencies

  • External Tools: Requires the pdftocairo command-line tool installed at /usr/bin/pdftocairo.
  • Node.js Modules: Uses fs, path, pdf-lib, and child_process modules.
  • Permissions: The node must have read access to the PDF file and write permissions to the output folder.
  • n8n Configuration: No special environment variables required, but the host running n8n must have pdftocairo installed and accessible.

Troubleshooting

  • Common Issues:

    • Missing pdftocairo: If pdftocairo is not installed or not found at /usr/bin/pdftocairo, the node will fail with an error indicating the executable cannot be found.
    • File Permissions: Errors may occur if the node lacks permission to read the PDF file or write to the output folder.
    • Invalid Paths: Supplying incorrect paths for the PDF file or output folder will result in errors such as "file not found" or "no such directory".
  • Error Messages and Resolutions:

    • "ENOENT: no such file or directory": Check that the PDF file path and output folder path are correct and accessible.
    • "EACCES: permission denied": Ensure the n8n process has appropriate read/write permissions.
    • "Error: Command failed: /usr/bin/pdftocairo ...": Verify that pdftocairo is installed and available at the specified location.

Links and References

Discussion