mioffice-pdf-utils
v1.0.0
Published
Lightweight PDF utilities for Node.js and the browser — merge, split, extract pages, get metadata. Zero native dependencies.
Maintainers
Readme
@mioffice/pdf-utils
Lightweight PDF utilities for Node.js and the browser. Merge, split, extract, rotate, reorder pages, and read/write metadata — all with zero native dependencies.
Built by MiOffice.ai — the AI office suite where files never leave your browser.
Install
npm install @mioffice/pdf-utilsUsage
import { mergePdfs, splitPdf, extractPages, getPdfMetadata, rotatePdf } from '@mioffice/pdf-utils';
import { readFileSync, writeFileSync } from 'fs';
// Merge multiple PDFs
const merged = await mergePdfs([
readFileSync('doc1.pdf'),
readFileSync('doc2.pdf'),
]);
writeFileSync('merged.pdf', merged);
// Split a PDF into individual pages
const pages = await splitPdf(readFileSync('document.pdf'));
pages.forEach((page, i) => writeFileSync(`page-${i + 1}.pdf`, page));
// Extract specific pages (0-indexed)
const extracted = await extractPages(readFileSync('document.pdf'), [0, 2, 4]);
writeFileSync('extracted.pdf', extracted);
// Rotate all pages
const rotated = await rotatePdf(readFileSync('document.pdf'), 90);
writeFileSync('rotated.pdf', rotated);
// Get metadata
const meta = await getPdfMetadata(readFileSync('document.pdf'));
console.log(meta);
// { title: '...', author: '...', pageCount: 12, pageSizes: [...] }API
| Function | Description |
|----------|-------------|
| mergePdfs(pdfs) | Combine multiple PDFs into one |
| splitPdf(pdf) | Split a PDF into single-page PDFs |
| extractPages(pdf, indices) | Extract specific pages (0-indexed) |
| removePages(pdf, indices) | Remove specific pages |
| reorderPages(pdf, newOrder) | Reorder pages by index |
| rotatePdf(pdf, degrees) | Rotate all pages (90, 180, 270) |
| getPdfMetadata(pdf) | Read title, author, page count, sizes |
| setPdfMetadata(pdf, meta) | Write title, author, subject, etc. |
All functions accept Uint8Array | ArrayBuffer and return Uint8Array.
Browser Usage
Works in any modern browser. No Node.js-specific APIs used.
<script type="module">
import { mergePdfs } from 'https://esm.sh/@mioffice/pdf-utils';
const file1 = await fetch('/doc1.pdf').then(r => r.arrayBuffer());
const file2 = await fetch('/doc2.pdf').then(r => r.arrayBuffer());
const merged = await mergePdfs([new Uint8Array(file1), new Uint8Array(file2)]);
</script>Why This Exists
MiOffice.ai provides 67+ file processing tools that run 100% in your browser — no uploads, no signup, no cloud. This package extracts our PDF utilities for developers who need the same capabilities in their own apps.
License
MIT — JSVV SOLS LLC
