Top AI Repos โ open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
๐ PDF extraction and rendering across all JavaScript runtimes
| Date | Stars |
|---|---|
| 2026-07-24 | 1191 |
| 2026-07-25 | 1193 |
| 2026-07-28 | 1193 |
| 2026-07-30 | 1193 |
| 2026-08-06 | 1193 |
Today
โ stars today
This week
โ stars this week
This month
โ stars this month
Momentum
35.0
growth rate 0.00%/day
# unpdf
Utilities for PDF extraction and rendering across all JavaScript runtimes โ Node.js, Deno, Bun, the browser, and serverless environments like Cloudflare Workers. Especially useful for AI applications that need to summarize or analyze PDF documents.
Ships with a serverless build of Mozilla's [PDF.js](https://github.com/mozilla/pdf.js), optimized for edge environments. If you're coming from [`pdf-parse`](https://www.npmjs.com/package/pdf-parse), `unpdf` is a modern, actively maintained alternative with broader runtime support.
## Features
- ๐๏ธ Works in Node.js, browser and serverless environments
- ๐ชญ Includes serverless build of PDF.js ([`unpdf/pdfjs`](./package.json))
- ๐ฌ Extract [text](#extract-text-from-pdf), [links](#extractlinks), and [images](#extractimages) from PDF files
- ๐ง Perfect for AI applications and PDF summarization
- ๐งฑ Opt-in to official or legacy PDF.js build
## Installation
```bash
# pnpm
pnpm add unpdf
# npm
npm install unpdf
```
## Usage
### Extract Text From PDF
```ts
import { extractText, getDocumentProxy } from 'unpdf'
// Fetch a PDF from the web or load it from the file system
const buffer = await fetch('https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf')
.then(res => res.arrayBuffer())
const pdf = await getDocumentProxy(new Uint8Array(buffer))
const { totalPages, text } = await extractText(pdf, { mergePages: true })
console.log(`Total pages: ${totalPages}`)
console.log(text)
```
### Official or Legacy PDF.js Build
Usually you don't need to worry about the PDF.js build. `unpdf` ships with a serverless build of the latest PDF.js version. However, if you want to use the official PDF.js version or the legacy build, you can define a custom PDF.js module.
> [!WARNING]
> PDF.js v5.x uses `Promise.withResolvers`, which may not be supported in all environments, such as Node < 22. Consider using the bundled serverless build, which includes a polyfill, or use an older version of PDF.js.
For example, if you want to use the official PDF.js build:
```ts
import { definePDFJSModule, extractText, getDocumentProxy } from 'unpdf'
// Define the PDF.js build before using any other unpdf method
await definePDFJSModule(() => import('pdfjs-dist'))
// Now, you can use all unpdf methods with the official PDF.js build
const pdf = await getDocumentProxy(/* โฆ */)
const { text } = await extractText(pdf)
```
### PDF.js API
`unpdf` provides helpful [methods](#api) to work with PDF files, such as `extractText` and `extractImages`, which should cover most use cases. However, if you need more control over the PDF.js API, you can use the `getResolvedPDFJS` method to get the resolved PDF.js module.
Access the PDF.js API directly by calling `getResolvedPDFJS`:
```ts
import { getResolvedPDFJS } from 'unpdf'
const { version } = await getResolvedPDFJS()
```
> [!NOTE]
> If no other PDF.js build was defined, the serverless build will always be used.
For example, you can use the `getDocument` method to load a PDF file and then use the `getMetadata` method to get the metadata of the PDF file:
```ts
import { readFile } from 'node:fs/promises'
import { getResolvedPDFJS } from 'unpdf'
const { getDocument } = await getResolvedPDFJS()
const data = await readFile('./dummy.pdf')
const document = await getDocument(new Uint8Array(data)).promise
console.log(await document.getMetadata())
```
## How It Works
> [!NOTE]
> The serverless PDF.js bundle is built from PDF.js v5.6.205.
Heart and soul of this package is the [`pdfjs.rolldown.config.ts`](./pdfjs.rolldown.config.ts) file. It uses [Rolldown](https://rolldown.rs/) to bundle PDF.js into a single file for serverless environments. The key techniques:
- **String replacements** strip browser-specific references from the PDF.js source.
- **Worker inlining** embeds the PDF.js worker directly into the main bundle, since serverless runtimes can't load separate worker files.
- **Global polyfills** provide missing APIs like `Promise.withResolvers` andExcerpt of 13,003 characters
Read on GitHubWould you bet a product on this? Bounded 0โ100 and slow moving.
matched fp:bfb544ea5cf371ee, topic:serverless