←Back to Guides
๐Ÿ“„Document Security & PDFโฑ๏ธ 14 min read•Updated November 2026•โœ๏ธBy Chris

Client-Side PDF Engineering: pdf-lib Manipulation, Worker Rasterization & Metadata Sanitization

Master zero-upload PDF engineering in the browser: learn when to modify vector COS objects losslessly with pdf-lib, how PDF.js Web Workers rasterize pages cleanly at 150-300 DPI, and how to strip hidden Author, Creator, and XMP metadata.

#PDF#Privacy#Metadata#pdf-lib#PDF.js#WebAssembly#Sanitization

1. PDF Internal Architecture: COS Objects vs Pixel Rasterization

A PDF document is not a flat imageโ€”it is a binary Carousel Object System (COS) graph made of dictionaries, streams, vector drawing operators, embedded Type 1/TrueType font subsets, and XObject images. Structural tools like merging, splitting, lossless 90-degree page rotation, and footer pagination operate strictly on the page-tree dictionary without decompressing or degrading underlying vector text.
Inspect Raw PDF /Info Dictionary via qpdf / pdfinfo
pdfinfo -meta confidential-contract.pdf
qpdf --show-all-pages --object-streams=disable confidential-contract.pdf inspect.pdf

Audits embedded document metadata, XMP XML packets, and page rotation flags from the terminal.

Lossless Page Rotation with pdf-lib in Browser
import { PDFDocument, degrees } from 'pdf-lib';
const doc = await PDFDocument.load(arrayBuffer);
doc.getPages().forEach((page) => page.setRotation(degrees(90)));
const cleanBytes = await doc.save({ useObjectStreams: true });

Rotates vector pages purely by updating each Page /Rotate dictionary key.

OperationEngine ClassVector Text PreservedTypical LatencyCopy
Merge / Split / ReorderDirect PDFDocument page copyYes (100% lossless)< 40ms
Rotate / Watermark / Page #Page dictionary & overlay streamYes (100% lossless)< 60ms
PDF -> PNG/JPG ExportPDF.js off-thread Web WorkerRasterized at chosen scale80-250ms / page
Image -> PDF Print BookJPEG/PNG XObject embeddingN/A (embedded images)< 120ms

2. Rasterization Scale Factors, DPI & Browser Canvas Limits

When exporting PDF pages into raster images for thumbnails, slide decks, or OCR pipelines, scale selection controls memory usage quadratically. PDF user space defaults to 72 points per inch (595x842 pts for A4). Rendering at 2x outputs ~144 DPI crisp UI assets, whereas 3x (~216 DPI) targets high-detail archive exports while staying safely beneath Safari and Chromium maximum canvas pixel budgets (~16.7 million pixels).
Safe Viewport Scaling with PDF.js Off-Main-Thread Worker
const viewport = page.getViewport({ scale: 2.0 });
canvas.width = Math.floor(viewport.width);
canvas.height = Math.floor(viewport.height);
await page.render({ canvasContext: ctx, viewport }).promise;

Uses an isolated Web Worker to decode CFF fonts and FlateDecode streams without freezing UI responsiveness.

Target Use CaseScale FactorA4 Output ResolutionCanvas Pixel FootprintCopy
Web Thumbnail Preview1.0x (72 DPI)595 x 842 px~2.0 MB RGBA raw buffer
Crisp Screen & Document Share2.0x (144 DPI)1190 x 1684 px~8.0 MB RGBA raw buffer
High-Detail Print / OCR3.0x (216 DPI)1785 x 2526 px~18.0 MB RGBA raw buffer

3. Metadata Leaks: /Info Dictionaries, XMP Streams & Print Stamps

Exporting a document from Microsoft Word, LibreOffice, Figma, or macOS Preview silently injects your workstation username into /Author, software build versions into /Creator and /Producer, and editing timestamps into /CreationDate and /ModDate. Worse, some tools embed duplicate XML inside the unencrypted /Metadata XMP streamโ€”stripping both in-memory before sharing prevents identity disclosure.
Scrubbing PDF Metadata Keys with pdf-lib
doc.setTitle('');
doc.setAuthor('');
doc.setSubject('');
doc.setKeywords([]);
doc.setProducer('');
doc.setCreator('');

Overwrites identifying /Info dictionary attributes locally prior to byte serialization.

Metadata FieldCommon Exposure RiskSanitization ActionCopy
/Author & /CreatorReveals employee full name, OS account ID, or corporate template nameOverwrite with empty string
/ProducerExposes exact Office, Chrome, or CAD suite version for fingerprintingClear string value
/CreationDate & /ModDateDiscloses user timezone offset and exact editing timelineReset to epoch / scrub
XMP /Metadata StreamDuplicates XML edit history and UUIDs outside /Info dictionaryStrip or re-serialize cleanly

4. Why Sensitive Contracts Belong Exclusively in Local Browser Memory

Uploading tax forms, ID scans, NDAs, or medical invoices to ad-supported server converters exposes documents to CDN edge logs, temporary bucket retention, and third-party analytics. Running pdf-lib and pdfjs-dist inside local client-side memory transforms every byte purely on the user CPU with zero network egress.
๐Ÿ‘จโ€๐Ÿ’ป
Authored & Reviewed by ChrisMayPixels • Netherlands

Independent software developer focused on client-side architectures, local-first computing, WebAssembly, and privacy-first web systems.

About MayOnlineTools→

๐ŸŽ“Explore More Guides

โœจ