@ooneex/pdf is a toolkit for working with PDF documents on the file system. A single PDF class, pointed at a file path, lets you create documents, add pages, read and update metadata, split documents, remove pages, and extract text and images page by page. It builds on pdf-lib, unpdf, pdf-to-img, and sharp.
Installation
Add the package to your project with Bun.Usage
Create aPDF instance with the path to a file. The same instance is used both to author new documents and to read or transform existing ones.
Reading text content
Extract text from a single page, or stream every page with the async generator.Metadata and page count
Splitting and removing pages
split writes each range to its own file under outputDir; removePages rewrites the source file in place.
Converting pages and extracting images
Render pages to PNG images, or pull embedded images out of the document. Both save to disk and yield results as they go.When to use it
- Generating simple PDF documents on the server (reports, receipts, exports) with text and metadata.
- Extracting plain text from uploaded PDFs for search, indexing, or parsing.
- Splitting a large PDF into smaller files or removing unwanted pages.
- Rendering pages to PNG thumbnails/previews, or pulling embedded images out of a document.
- For encrypted PDFs, pass a
passwordin the constructor options. - You do not need it for rich, pixel-perfect page layouts or HTML-to-PDF rendering — reach for a dedicated layout/print engine instead.