@siliph/pdf-engine-core
v0.3.0
Published
Browser-native PDF parser, renderer, and editor engine. Merge, split, rotate, crop, encrypt, sign, annotate, and edit PDFs entirely client-side with zero server dependencies.
Downloads
80
Maintainers
Keywords
Readme
Install
npm install @siliph/pdf-engine-coreQuick Start
import { mergePdfs, splitPdf, rotate, fillForm, search } from '@siliph/pdf-engine-core';
// Merge PDFs
const merged = await mergePdfs([doc1, doc2]);
// Split by page ranges
const parts = await splitPdf(doc, [{ start: 0, end: 4 }, { start: 5, end: 9 }]);
// Rotate page 90°
const cmd = await rotate(doc, 0, 90);
if (cmd.ok) doc.applyCommand(cmd.value);
// Fill form
const formCmd = await fillForm(doc, { name: 'John', agree: true });
// Full-text search
for await (const hit of search(doc, 'invoice')) {
console.log(`Page ${hit.pageIndex}, offset ${hit.offset}`);
}Tree Shaking
Each task is independently importable — no bundle bloat:
import { mergePdfs } from '@siliph/pdf-engine-core/tasks/mergePdfs'; // ~15KB gzipped20 Task Functions
| Function | Description |
|----------|-------------|
| mergePdfs | Merge multiple documents into one |
| splitPdf | Split by page ranges |
| splitByBookmarks | Split at bookmark boundaries |
| splitBySize | Split into max-size chunks |
| extractPages | Extract specific pages |
| rotate | Rotate pages (90°/180°/270°) |
| crop | Crop (metadata or content clip) |
| compress | Remove unused resources (GC) |
| addWatermark | Add text watermark to all pages |
| setHeaderFooter | Add headers/footers with page numbers |
| setMetadata | Set title, author, keywords |
| redact | Visual or permanent redaction |
| fillForm | Fill AcroForm fields |
| search | Full-text search (Unicode NFC, async iterator) |
| mixPages | Alternate pages from multiple docs |
| addBackPages | Insert back pages for duplex printing |
| setBookmarks | Set document outline |
| getBookmarks | Read current bookmarks |
| pdfToImages | Convert pages to PNG/JPEG |
14 Engines
| Engine | Capability | |--------|-----------| | Parser | XRef streams, object streams, lazy loading, brute-force recovery | | Rendering | Canvas2D, OffscreenCanvas Workers, blend modes, transparency groups | | Font | TrueType, Type1, CID, CMap, ToUnicode, glyph LRU cache, Standard 14 | | Text | Run reconstruction, in-place editing, kerning, RTL/BiDi, selection | | Image | JPEG, JPEG2000, JBIG2, CCITTFax, Flate, SMask compositing | | Annotation | 9 types, appearance streams, visual + permanent redaction | | Forms | AcroForms, all field types, validation, radio groups | | Security | RC4, AES-128, AES-256, digital signatures (PKCS#7) | | Page | Merge, split, extract, rotate, crop, reorder, resource dedup | | Export | Incremental save, full save, streaming, Worker offload | | Search | Unicode NFC, ligature decomposition, hyphenation, async iterator | | Selection | Hit-testing (4px tolerance), multi-select, marquee | | Graphics | Shape primitives, ink paths | | Validation | PDF/A-1b conformance checking |
Benchmarks
| Operation | Time | Memory | |-----------|------|--------| | Parse XRef (500pg, 12MB) | ~85ms | 4MB | | First page render | ~180ms | 28MB | | Merge 100pg + 50pg | ~45ms | 18MB | | Full-text search (200pg) | ~120ms | 6MB | | AES-256 decrypt (5MB) | ~95ms | 8MB | | Incremental save | ~35ms | 12MB |
Error Handling
All functions return Result<T, TaskError> — never throws:
const result = await mergePdfs([doc1, doc2]);
if (result.ok) {
console.log(result.value.getPageCount());
} else {
console.error(result.error.code); // 'INVALID_INPUT' | 'ENGINE_FAILURE'
console.error(result.error.message);
}Part of @siliph/pdf-engine
| Package | Description |
|---------|-------------|
| @siliph/pdf-engine | Umbrella (re-exports all) |
| @siliph/pdf-engine-core | Parser, engines, task API (this package) |
| @siliph/pdf-engine-ui | Viewport, toolbar, accessibility |
| @siliph/pdf-engine-plugin-sdk | Plugin extension system |
Links
- 🌐 siliph.com — Documentation
- 📦 GitHub — Source code
- 🐛 Issues — Bug reports
License
MIT
