🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@dicepdf/core

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dicepdf/core

Portable, privacy-first PDF engine. The same operations that power dicepdf.com — runnable in Node, the browser, and AI agents. Your files never leave the machine.

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

@dicepdf/core

The portable PDF engine behind dicepdf.com. The same operations that power the website, packaged as pure functions you can call from Node, the browser, a CLI, or an AI agent.

One promise: your files never leave the machine. Every function reads bytes you already hold in memory and returns new bytes. There is no network path, no upload, no telemetry.

Install

npm install @dicepdf/core

Usage

import { readFile, writeFile } from 'node:fs/promises';
import { merge, splitByRanges } from '@dicepdf/core';
import { extractText } from '@dicepdf/core/extract';
import { renderToImages } from '@dicepdf/core/render';

// Merge
const a = await readFile('a.pdf');
const b = await readFile('b.pdf');
await writeFile('merged.pdf', await merge([a, b]));

// Extract text (great for feeding an LLM/agent)
const text = await extractText(await readFile('report.pdf'));

// Render pages to PNGs
const images = await renderToImages(await readFile('report.pdf'), { dpi: 150 });
for (const img of images) await writeFile(img.name, img.bytes);

// Split
const parts = await splitByRanges(await readFile('book.pdf'), [
  [1, 10],
  [11, 20],
]);
for (const part of parts) await writeFile(part.name, part.bytes);

Every operation accepts a Uint8Array or ArrayBuffer and (for PDF outputs) returns a Uint8Array.

Three entry points

ImportRuns inPulls in
@dicepdf/corebrowser + Nodepdf-lib, fflate only — light & bundler-safe
@dicepdf/core/extractNodepdfjs-dist (layout-aware text extraction)
@dicepdf/core/renderNode@napi-rs/canvas (optional) for rasterization

The main entry has no node: imports, so it bundles cleanly into a browser or web-worker build. render needs the optional @napi-rs/canvas dependency (prebuilt — no native toolchain required).

API

FunctionDescription
merge(files)Concatenate PDFs in order
splitByRanges(file, ranges) / splitPages(file, pages) / splitEveryPage(file)Split into multiple PDFs
rotate(file, angle, pageIndices?)Rotate 90/180/270°
deletePages(file, pages)Remove 1-based pages
reorder(file, order)Reorder via a page permutation
crop(file, marginsMm)Trim margins (millimeters)
watermark(file, options)Stamp a text watermark
addPageNumbers(file, options)Stamp page numbers
stripMetadata(file, options?)Remove Info/XMP/ID metadata
compress(file)Structural compression + metadata strip
repair(file)Best-effort reparse + rewrite
imageToPdf(images, options?)PNG/JPEG → PDF (one image per page)
zip(entries)Bundle named byte arrays into a ZIP
getMetadata(file)Page count, AcroForm, signature flag
extractDocument / extractText / extractMarkdownLayout-aware text extraction (/extract)
renderToImages(file, options?)Rasterize pages to PNG/JPEG (/render)
compressAggressive(file, options?)Rasterizing compression for scan-heavy PDFs (/render)

Errors are typed: catch EncryptedPdfError and InvalidPdfError to branch on bad input.

License

MIT

Keywords

pdf

FAQs

Package last updated on 28 May 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts