A deep technical breakdown of in-browser binary parsing, PDF stream re-serialization, canvas rasterization pipelines, and client-side memory safety.
Document manipulation tools (such as PDF merging, image extraction, and optimization) traditionally rely on heavy backend worker pools powered by Ghostscript, Poppler, or Python microservices. While effective, this architecture requires transmitting complete document contents across public networks, introducing privacy hazards, high network latency, and continuous server compute costs.
DocuMorph completely inverts this model by executing 100% of PDF binary parsing, indirect object manipulation, stream optimization, and rasterization directly inside the client's browser runtime. By keeping document bytes restricted to local sandboxed memory, user data remains strictly on the client device.
How document bytes flow from the file picker through browser runtime engines to instant local download.
HTML5 Drag & Drop / File API reads file into binary memory as an ArrayBuffer. Validates headers and size bounds (≤50MB).
PDF-Lib and PDF.js inspect cross-reference (xref) tables, trailer dictionaries, page catalog trees, and encryption states.
Merge & Split: Page remapping & range slicing.
Compress: Flate stream packing & resampling.
Stamp & Raster: Dynamic watermarking & canvas loop.
Generated Uint8Array serialized into binary Blob. Managed ObjectURL triggers instant device download with garbage collection.
Built on pdf-lib, the merge subsystem parses each source document's internal structure. It copies page trees via mergedPdf.copyPages(sourceDoc, pageIndices), deduplicates shared resources (such as embedded fonts and colorspaces), re-indexes indirect object IDs sequentially, and writes a unified cross-reference dictionary.
Powered by Mozilla's PDF.js engine, this subsystem decodes postscript vector operations, fonts, and inline image streams, executing 2D rendering passes onto virtual HTML5 <canvas> viewports at user-configurable scales (1.0x to 2.0x). Exported PNG/JPEG frames are bundled asynchronously using JSZip.
DocuMorph implements a dual-strategy compression architecture: Lossless Object Streams compacts cross-reference tables and strips unreferenced metadata. Scanned Resampling re-encodes image-heavy pages at 75% JPEG quality. Files that already contain optimal Flate streams are transparently reported as already optimal.
Browser JavaScript execution environments operate within constrained memory limits (typically 1.5–2 GB per tab). DocuMorph enforces defensive engineering patterns to prevent memory crashes:
| Guardrail / Mechanism | Threshold / Implementation | Architectural Purpose |
|---|---|---|
| Max Upload Ceiling | 50 MB per file / 100 MB aggregate queue | Prevents heap overflow during ArrayBuffer expansion in memory. |
| Canvas Memory Reclamation | canvas.width = 0; canvas.height = 0; |
Immediately releases GPU/canvas backing textures after frame generation. |
| Object URL Lifecycle | Explicit URL.revokeObjectURL(url) tracking |
Prevents silent memory leaks by releasing browser blob registry allocations. |
| Encryption Detection | PDFDocument.load(buf, { ignoreEncryption: false }) |
Gracefully traps password-protected PDFs without unhandled exceptions. |
| Rasterization Safety Cap | 40 pages maximum per batch | Protects browser rendering loop against unresponsive thread lockups. |
Pure JavaScript PDF manipulation. Loads, merges, creates pages, and serializes binary PDF streams without external C++ or native binaries.
Parses vector paths, fonts, and inline graphics, rendering full fidelity page frames onto standard HTML5 2D canvas contexts.
Compresses multiple exported PNG/JPEG page blobs into a single downloadable .zip archive in-browser asynchronously.
Test client-side merging, stream compression, and canvas page rasterization directly in your browser.