main
PDF Manager
A Node.js Express service for PDF processing operations: split PDFs into multiple documents and rename them based on metadata.
Features
- PDF Splitting: Split a multi-page PDF into separate documents based on a specified page count
- Metadata-Based Renaming: Automatically rename split PDFs using provided metadata (name and lastname)
- ZIP Archive Output: Receive all processed PDFs in a single ZIP archive
- Input Validation: Joi-based request validation for robust error handling
- File Size Limits: 10MB maximum file size for uploads
API Endpoints
POST /process-pdf
Process a PDF file by splitting it into multiple documents and renaming them based on metadata.
Request
- Content-Type:
multipart/form-data - Parameters:
file(file, required): The PDF file to process (max 10MB)pagesPerDoc(number, required): Number of pages per output documentmetadata(JSON string, required): Array of metadata objects for naming
Metadata Format
[
{
"name": "John",
"lastname": "Doe"
},
{
"name": "Jane",
"lastname": "Smith"
}
]
The number of metadata entries must match or exceed the number of output documents that will be created based on pagesPerDoc.
Response
- Content-Type:
application/zip - Content-Disposition:
attachment; filename="processed_pdfs.zip" - Body: ZIP archive containing the split and renamed PDF files
Output Filenames
Files are named in the format: {name}_{lastname}.pdf (e.g., john_doe.pdf, jane_smith.pdf)
Example Request (using curl)
curl -X POST http://localhost:3000/process-pdf \
-F "file=@document.pdf" \
-F "pagesPerDoc=2" \
-F 'metadata=[{"name":"John","lastname":"Doe"},{"name":"Jane","lastname":"Smith"}]' \
-o processed_pdfs.zip
Error Responses
- 400 Bad Request: Invalid metadata JSON, missing file, or validation errors
- 500 Internal Server Error: PDF processing failed
Running Locally
Prerequisites
- Node.js 20 or higher
- npm or Docker
Option 1: Using npm
-
Install dependencies:
npm install -
Start the server:
npm start -
The server will start on port 3000 (or the port specified in the
PORTenvironment variable)
Option 2: Using Docker Compose
-
Start the service:
docker-compose up -
The service will be available at
http://localhost:3000 -
Stop the service:
docker-compose down
Option 3: Using Docker
-
Build the image:
docker build -t pdf-manager . -
Run the container:
docker run -p 3000:3000 pdf-manager
Dependencies
- express (^4.18.2): Web framework
- multer (^1.4.5-lts.1): Multipart/form-data handling for file uploads
- pdf-lib (^1.17.1): PDF manipulation library
- archiver (^7.0.1): ZIP archive creation
- joi (^17.11.0): Request validation
Development
Start the development server with auto-reload:
npm run dev
License
ISC
Description
Languages
JavaScript
95.8%
Dockerfile
4.2%