pdflib

n8n community node for filling and manipulating PDF documents using pdf-lib. Perfect for generating tax receipts, invoices, and forms.

Package Information

Released: 12 mo ago
Downloads: 669 weeklyΒ /Β 4,735 monthly
Latest Version: 0.4.1
Author: hichamchar

Documentation

n8n PDF-lib Custom Node

A custom n8n node for working with PDF documents using the pdf-lib library. This node allows you to fill PDF forms, create new PDFs, and merge multiple PDFs directly in your n8n workflows.

🎯 Features

  • Fill PDF Forms - Add text overlays to existing PDF documents with full positioning control
  • Fill Form Fields - Fill actual interactive PDF form fields (text, checkboxes, radio buttons)
  • Extract Form Fields - Discover all form fields, types, values, and properties from PDFs ✨ NEW in v0.4.0
  • Add Images - Embed PNG and JPEG images into PDFs with positioning and rotation
  • Create PDFs - Generate new PDF documents from scratch
  • Merge PDFs - Combine multiple PDF files into one with support for multiple sources
  • JavaScript Code Mode - Programmatically define fields using JavaScript code
  • French Character Support - Full UTF-8 support for international characters
  • Flexible Input - Works with URLs or binary data
  • Customizable - Configure fonts, colors, positions, sizes, and rotations

πŸ“¦ Installation

Follow the detailed instructions in SETUP.md to install this custom node in your n8n instance.

Quick Start:

cd ~
wget https://github.com/n8n-io/n8n-nodes-starter/archive/refs/heads/master.zip
unzip master.zip
mv n8n-nodes-starter-master n8n-nodes-pdflib
cd n8n-nodes-pdflib

# Clean up examples
rm -rf nodes/ExampleNode nodes/HttpBin credentials/*

# Copy the PDF-lib node files into nodes/PdfLib/

# Update package.json with the provided version

# Build and link
npm install
npm run build
npm link

# Link to n8n
cd ~/.n8n/custom
npm link n8n-nodes-pdflib
docker restart n8n

πŸš€ Usage

Fill PDF Form

Perfect for filling tax receipts, invoices, or any form-based PDFs:

  1. Select Fill PDF Form operation
  2. Choose PDF source (URL or Binary Data)
  3. Add text fields with coordinates and styling
  4. Output as binary data

Example Use Case: French Tax Receipt (ReΓ§u Fiscal)

  • Load template PDF from URL
  • Add donor name, address, amount, date
  • Generate personalized receipt

Create PDF

Create new PDF documents from scratch:

  1. Select Create PDF operation
  2. Choose page size (A4, Letter, or Custom)
  3. Add text fields with positions and styling
  4. Output as binary data

Extract Form Fields ✨ NEW

Discover all form fields in a PDF before filling:

  1. Select Extract Form Fields operation
  2. Choose PDF source (URL or Binary Data)
  3. Get JSON output with all field information

Returns:

  • Field names and types (text, checkbox, radio, dropdown, list, button, signature)
  • Current values and properties
  • Max lengths, options, read-only status
  • PDF metadata (page count, title, author)

Perfect for:

  • Finding exact field names before filling forms
  • Validating PDF form structure
  • Building dynamic form-filling workflows
  • Documenting form fields

Merge PDFs

Combine multiple PDF files:

  1. Select Merge PDFs operation
  2. Add multiple PDF sources (URL or Binary Data)
  3. Get combined PDF as output

πŸ“‹ Sample Workflow

A sample workflow for French tax receipts is included in sample-workflow.json. Import it into n8n to see the node in action.

The workflow:

  1. Takes donation data (name, address, amount, date)
  2. Fills a PDF template
  3. Saves the result
  4. Optionally emails it to the donor

πŸ› οΈ Files Included

  • nodes/PdfLib/PdfLib.node.ts - Main node implementation
  • nodes/PdfLib/PdfLib.node.json - Node metadata
  • nodes/PdfLib/logo-full.svg - PDF-lib logo icon
  • package.json - Package configuration
  • SETUP.md - Detailed setup instructions
  • PUBLISHING.md - Guide to publish to npm
  • CHANGELOG.md - Version history
  • sample-workflow.json - Example workflow
  • README.md - This file

πŸ”§ Configuration

Text Field Parameters

  • Text - The text content to add
  • X Position - Horizontal position from left (in points)
  • Y Position - Vertical position from bottom (in points)
  • Font Size - Text size (default: 12)
  • Page Number - Which page to add text to (0-indexed)
  • Color - Text color in hex format (e.g., #000000)

Coordinate System

PDFs use a coordinate system where:

  • (0, 0) is at the bottom-left corner
  • X increases to the right
  • Y increases upward
  • A4 page is approximately 595 x 842 points

🎨 Customization

You can extend this node by:

  • Adding more PDF operations (rotate, extract, compress)
  • Supporting more fonts (embed custom TTF fonts)
  • Adding image support
  • Creating credential support for authenticated sources

πŸ“š Resources

πŸ› Troubleshooting

Node doesn't appear:

  • Verify npm link worked: ls -la ~/.n8n/custom/node_modules
  • Check Docker logs: docker logs n8n
  • Restart n8n: docker restart n8n

Build errors:

  • Delete node_modules and reinstall: rm -rf node_modules package-lock.json && npm install
  • Ensure TypeScript is installed: npm install -g typescript

PDF operations fail:

  • Check URL accessibility from Docker container
  • Verify coordinates are within page bounds
  • Check n8n execution logs for details

πŸ“„ License

MIT

🀝 Contributing

This is a custom node for personal/organizational use. Feel free to modify and extend it for your needs!

✨ Advantages

βœ… Permanent - Survives n8n updates
βœ… Local - No external API dependencies
βœ… Fast - Runs directly in n8n
βœ… Flexible - Full control over PDF operations
βœ… Reusable - Works across all workflows
βœ… Team-Friendly - Easy for others to use

Discussion