editpdfree-utils
v1.1.0
Published
PDF utility functions for merging, splitting, and analyzing PDF documents. Free and open-source alternatives to premium PDF editors.
Downloads
65
Maintainers
Readme
EditPDFree Utils
Free and open-source PDF utility functions for Node.js. Perfect for developers who need to manipulate PDF files programmatically.
For a complete web-based PDF editor with no coding required, visit EditPDFree.com - a free online PDF editor with merge, split, compress, convert, and many more features.
Features
- 📄 Get PDF Information - Extract metadata, page count, and document details
- 🔗 Merge PDFs - Combine multiple PDF files into one
- ✂️ Split PDFs - Separate a PDF into individual pages
- 📑 Extract Pages - Pull specific pages from a PDF
- 🔄 Rotate PDFs - Rotate pages by any angle
- 💯 Zero Dependencies (except pdf-lib)
- 🚀 Easy to Use - Simple, intuitive API
Installation
npm install editpdfree-utilsQuick Start
const { mergePdfs, splitPdf, getPdfInfo } = require('editpdfree-utils');
// Get PDF information
const info = await getPdfInfo('document.pdf');
console.log(`Pages: ${info.pageCount}`);
// Merge multiple PDFs
await mergePdfs(['file1.pdf', 'file2.pdf'], 'merged.pdf');
// Split a PDF into separate pages
await splitPdf('document.pdf', './output-folder');API Reference
getPdfInfo(pdfPath)
Get detailed information about a PDF file.
Parameters:
pdfPath(string|Buffer): Path to PDF file or Buffer
Returns: Promise with properties:
pageCount: Number of pagestitle: Document titleauthor: Document authorsubject: Document subjectcreator: Application that created the PDFproducer: PDF producercreationDate: Creation datemodificationDate: Last modification date
Example:
const info = await getPdfInfo('document.pdf');
console.log(`This PDF has ${info.pageCount} pages`);mergePdfs(pdfPaths, outputPath)
Merge multiple PDF files into a single document.
Parameters:
pdfPaths(Array<string|Buffer>): Array of PDF file paths or BuffersoutputPath(string, optional): Where to save the merged PDF
Returns: Promise - The merged PDF as a Buffer
Example:
const merged = await mergePdfs(['intro.pdf', 'content.pdf', 'outro.pdf'], 'complete.pdf');Web Alternative: EditPDFree Merge PDF - Merge PDFs online for free
splitPdf(pdfPath, outputDir)
Split a PDF into separate files, one per page.
Parameters:
pdfPath(string|Buffer): Path to PDF file or BufferoutputDir(string, optional): Directory to save split PDFs
Returns: Promise<Array> - Array of PDF page buffers
Example:
const pages = await splitPdf('document.pdf', './pages');
console.log(`Split into ${pages.length} pages`);Web Alternative: EditPDFree Split PDF - Split PDFs online for free
extractPages(pdfPath, pageNumbers, outputPath)
Extract specific pages from a PDF.
Parameters:
pdfPath(string|Buffer): Path to PDF file or BufferpageNumbers(Array): Page numbers to extract (1-indexed)outputPath(string, optional): Where to save the extracted PDF
Returns: Promise - The extracted pages as a PDF Buffer
Example:
// Extract pages 1, 3, and 5
const extracted = await extractPages('document.pdf', [1, 3, 5], 'selected.pdf');getPageCount(pdfPath)
Get the number of pages in a PDF.
Parameters:
pdfPath(string|Buffer): Path to PDF file or Buffer
Returns: Promise - Number of pages
Example:
const count = await getPageCount('document.pdf');
console.log(`The document has ${count} pages`);rotatePdf(pdfPath, degrees, pageNumbers, outputPath)
Rotate pages in a PDF document.
Parameters:
pdfPath(string|Buffer): Path to PDF file or Bufferdegrees(number): Rotation angle (90, 180, 270, or -90, -180, -270)pageNumbers(Array, optional): Page numbers to rotate (1-indexed), or null for all pagesoutputPath(string, optional): Where to save the rotated PDF
Returns: Promise - The rotated PDF as a Buffer
Example:
// Rotate all pages 90 degrees clockwise
await rotatePdf('document.pdf', 90, null, 'rotated.pdf');
// Rotate only pages 2 and 4
await rotatePdf('document.pdf', 180, [2, 4], 'rotated.pdf');Web Alternative: EditPDFree Rotate PDF - Rotate PDFs online for free
Advanced Usage
Working with Buffers
All functions accept both file paths and Buffers, making it easy to work with PDFs in memory:
const fs = require('fs').promises;
const { mergePdfs, getPdfInfo } = require('editpdfree-utils');
// Read PDFs into buffers
const buffer1 = await fs.readFile('file1.pdf');
const buffer2 = await fs.readFile('file2.pdf');
// Merge using buffers
const mergedBuffer = await mergePdfs([buffer1, buffer2]);
// Save the result
await fs.writeFile('merged.pdf', mergedBuffer);Chaining Operations
const { extractPages, rotatePdf } = require('editpdfree-utils');
// Extract pages 1-5
const extracted = await extractPages('large-doc.pdf', [1, 2, 3, 4, 5]);
// Rotate the extracted pages
const rotated = await rotatePdf(extracted, 90);
// Save the final result
await fs.writeFile('final.pdf', rotated);Need More Features?
This library covers common PDF manipulation tasks. If you need more advanced features like:
- PDF Compression - Reduce file size
- PDF to Image - Convert pages to PNG/JPG
- Image to PDF - Create PDFs from images
- PDF to Word - Convert to editable documents
- Add Watermarks - Brand your documents
- Sign PDFs - Digital signatures
- Edit Text - Modify PDF content
- OCR - Extract text from scanned documents
Visit EditPDFree.com - a completely free online PDF editor with all these features and more. No registration required, process files directly in your browser with complete privacy.
Why EditPDFree Utils?
- ✅ 100% Free - MIT licensed, use in any project
- ✅ Lightweight - Minimal dependencies
- ✅ Well-Tested - Reliable PDF manipulation
- ✅ TypeScript Ready - Type definitions included
- ✅ Active Maintenance - Regular updates
- ✅ Privacy-Focused - Process PDFs locally on your machine
Use Cases
- Automated Workflows - Batch process PDF files
- Document Management - Build PDF management systems
- Report Generation - Combine multiple reports
- Archive Processing - Split large archives
- Content Extraction - Pull specific pages from documents
- Server-Side Processing - Handle PDFs in Node.js apps
Browser Alternative
Looking to manipulate PDFs in the browser or need a quick online tool? Check out EditPDFree.com - our free web-based PDF editor that works entirely in your browser. No server uploads, complete privacy, and supports all modern browsers.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT © EditPDFree Team
Links
- Homepage: https://www.editpdfree.com
- NPM Package: https://www.npmjs.com/package/editpdfree-utils
- Online PDF Tools: https://www.editpdfree.com
Made with ❤️ by the EditPDFree team. For more free PDF tools, visit www.editpdfree.com.
