百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

clawpdf

> 编程语言
开源

用于 Node 和浏览器的零依赖 PDFium WebAssembly 绑定。

99 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

用于 Node 和浏览器的零依赖 PDFium WebAssembly 绑定。

clawpdf — Pull the text and pixels out of PDFs

ClawPDF is an ESM-only PDFium WebAssembly library and CLI for Node.js and bundled browser apps. It extracts text, renders pages, and produces PNG bytes without runtime dependencies, native addons, postinstall scripts, or a canvas package.

Install

bash
npm install clawpdf

Node.js 22 or newer is required. The package includes the clawpdf command and its PDFium WebAssembly runtime.

Quick start

Extract text from a PDF without writing a script:

bash
$ npx clawpdf https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf
Dummy PDF file

Or open a local file from JavaScript and render its first page:

typescript
import { writeFile } from "node:fs/promises";
import { openPdf } from "clawpdf";

await using pdf = await openPdf("report.pdf");
console.log(pdf.text({ maxPages: 5 }));

const png = await pdf.page(1).png({ dpi: 144, forms: true });
await writeFile("page-1.png", png);

Page numbers in the CLI and library are one-based.

CLI

The CLI reads file paths, URLs, and standard input. Text goes to stdout; diagnostics go to stderr.

Task Command
Extract text clawpdf report.pdf
Read standard input cat report.pdf | clawpdf -
Emit structured output clawpdf report.pdf --json
Render one page clawpdf render report.pdf --page 1 -o page.png

HTTP(S) downloads have no size cap by default. Opt into a byte budget with --fetch-max-bytes 10000000 or the library's fetchMaxBytes option. 0 disables the budget; the existing 30-second deadline still applies.

See the CLI reference for extraction modes, page selection, passwords, image budgets, inline terminal images, JSON output, and exit codes.

Text-first extraction

extractPdf() can return text, PNG fallback images, or both. In auto mode it always extracts text, then renders selected pages only when the text is shorter than minTextChars.

typescript
import { extractPdf } from "clawpdf";

const result = await extractPdf("report.pdf", {
  mode: "auto",
  maxPages: 20,
  minTextChars: 200,
  image: { dpi: 96, maxPixels: 4_000_000, forms: true },
});

console.log(result.text, result.images);

Image results contain raw PNG bytes. The optional clawpdf/adapters export converts them to data URLs or model-message content blocks. See extraction fallback for the modes, limits, and result shape.

Reuse an engine

openPdf() owns a private engine and suits one-off work. Servers should create one engine, reuse it across documents, and dispose it during shutdown:

typescript
import { createEngine } from "clawpdf";

export async function inspect(pdfBytes: Uint8Array) {
  await using engine = await createEngine();
  await using pdf = await engine.open(pdfBytes);

  console.log(pdf.metadata.title);
  console.log(pdf.page(1).text());
}

The Node entry point accepts byte arrays, file paths, URLs, and blobs. Bundled browser code should import the pre-wired clawpdf/browser entry point; see browser and bundler setup.

Documentation

  • Loading PDFs covers inputs, document lifetimes, and passwords.
  • Text extraction, page rendering, and PNG output cover the core document APIs.
  • Password-protected PDFs covers the library and CLI flows.
  • API reference lists exports, types, options, and typed errors.
  • Package shape records the published files and dependency contract.
  • PDFium provenance records the vendored release, checksum, notices, and refresh workflow.
  • Performance contains the current local benchmark snapshot.

The full documentation site is available at clawpdf.dev.

Development

bash
pnpm install
pnpm build
pnpm typecheck
pnpm test
pnpm test:package
pnpm docs:site

CI runs the same checks on Node.js 22, 24, and 26.

License

MIT. PDFium carries upstream BSD-style and Apache-2.0 notices; see THIRD_PARTY_NOTICES.md.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptnodepdfwasm

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言