Actions2
Parse PDF
AI-generatedOverview
The node "PDF Parse" is designed to process PDF files by either extracting their text content or converting PDF pages into images. It supports two main operations:
- Parse PDF: Extracts text from a PDF file with various formatting options to suit different use cases, including AI-friendly raw text extraction or visually structured layouts.
- Convert to Image: Converts one or more pages of a PDF into image files (PNG or JPEG), allowing customization of resolution, size, and aspect ratio.
This node is useful in scenarios such as:
- Automating data extraction from invoices, reports, or contracts stored as PDFs.
- Preparing textual content for further processing like natural language analysis or indexing.
- Generating preview images or thumbnails of PDF documents for display purposes.
Practical examples:
- Extracting all text from a multi-page PDF invoice and storing it in a workflow variable for downstream processing.
- Converting the first three pages of a PDF report into PNG images to embed in an email.
Properties
| Name | Meaning |
|---|---|
| Operation | Choose between "Parse PDF" (extract text) or "Convert to Image" (convert pages to images). |
| PDF Source | Select the source of the PDF file: "Binary Data" (from a binary property in the input item) or "URL" (download PDF from a web address). |
| Binary Property | (Shown if source is Binary Data) Name of the binary property containing the PDF file. |
| URL | (Shown if source is URL) The URL of the PDF file to parse. |
| Output Property Name | The name of the property where the extracted content or image info will be stored in the output JSON. |
| Additional Options | Collection of optional settings depending on the operation: |
| - Max Pages | Maximum number of pages to parse or convert (0 means all pages). |
| - Page Range Start | Starting page number (1-based) for parsing or conversion. |
| - Page Range End | Ending page number (0 means last page). |
| - Text Formatting | (For parsing) Style of text formatting applied to extracted content. Options: Raw, Smart Layout, Minimal Cleanup, Visual Layout, Structured, Compact. |
| - Include Metadata | (For parsing) Whether to include PDF metadata (like author, creation date) in the output. |
| - Split by Pages | (For parsing) Whether to split the output text by pages, returning an array of page texts instead of a single string. |
| - Version | (For parsing) PDF.js library version used internally for parsing. |
| - Image Format | (For conversion) Output image format: PNG (supports transparency) or JPEG (smaller file size). |
| - DPI (Resolution) | (For conversion) Dots per inch setting controlling image quality and size (range 72–600). |
| - Width | (For conversion) Desired image width in pixels; 0 means auto-calculated based on DPI. |
| - Height | (For conversion) Desired image height in pixels; 0 means auto-calculated based on DPI. |
| - Preserve Aspect Ratio | (For conversion) Whether to maintain the original aspect ratio when resizing images. |
Output
For Parse PDF operation:
- The output JSON contains the extracted text under the specified output property name.
- If "Split by Pages" is enabled, the output is an array of strings, each representing one page's text.
- Optionally includes PDF metadata if enabled.
- Additional statistics such as total number of pages, text length, and word count are included.
- The binary data remains unchanged from the input.
For Convert to Image operation:
- The output JSON contains an array of objects under the specified output property name.
- Each object represents one converted page with details: page number, width, height, file size, image format, and the name of the binary property holding the image.
- The binary data contains base64-encoded image files keyed by generated binary property names (e.g.,
image_page_1). - Images are provided in the chosen format (PNG or JPEG).
Dependencies
- Requires the following npm packages bundled with the node:
- A PDF parsing library for text extraction.
- A PDF-to-image conversion library relying on GraphicsMagick and Ghostscript system dependencies.
- For URL source, requires network access to fetch PDF files.
- When converting PDFs to images, the environment must have GraphicsMagick and Ghostscript installed:
- On Docker/Ubuntu:
apt-get install -y graphicsmagick ghostscript - On Alpine Linux:
apk add graphicsmagick ghostscript
- On Docker/Ubuntu:
Troubleshooting
Common issues:
- Invalid or empty PDF file input.
- Incorrect binary property name or missing binary data.
- Invalid or unreachable URL when using URL source.
- Missing system dependencies (GraphicsMagick, Ghostscript) for image conversion.
- Unsupported or corrupted PDF files.
Error messages and resolutions:
"URL is required when source is set to URL": Provide a valid URL."Invalid URL format": Check URL syntax."Failed to fetch PDF from URL": Verify network connectivity and URL accessibility."File does not appear to be a valid PDF": Confirm the input file is a proper PDF.- Errors mentioning missing GraphicsMagick or Ghostscript: Install these tools in your n8n environment as described above.
- Conversion errors related to system delegates indicate missing or misconfigured system dependencies.
Links and References
- PDF.js GitHub Repository — underlying PDF parsing library.
- GraphicsMagick Official Site — required for PDF to image conversion.
- Ghostscript Official Site — required for PDF rendering during conversion.
- n8n Documentation on Binary Data Handling