@docmost/pdf-inspector

中文文档
1.9.6发布于 2026/05/15MITTypeScriptCommonJS零依赖构建来源已验证近 30 天下载 1.6万

Fast PDF classification, text extraction, and image extraction. Native Rust performance via napi-rs.

原始使用文档
文档目录13 节
  1. Install
  2. API
  3. processPdf(buffer: Buffer, pages?: number[]): PdfResult
  4. classifyPdf(buffer: Buffer): PdfClassification
  5. processPdfWithImages(buffer: Buffer, pages?: number[]): Pdf…
  6. extractImages(buffer: Buffer): ExtractedImage[]
  7. extractTextInRegions(buffer: Buffer, pageRegions: PageRegio…
  8. extractText(buffer: Buffer): string
  9. Types
  10. Supported image formats
  11. Performance
  12. Platforms
  13. License

PDF Inspector

Fast PDF classification, text extraction, and image extraction for Node.js/Bun. Native Rust performance via napi-rs.

Built by Firecrawl for hybrid OCR pipelines — extract text from PDF structure where possible, fall back to OCR only when needed.

Install

npm install firecrawl-pdf-inspector
# or
bun add firecrawl-pdf-inspector

Prebuilt binaries included for linux-x64, linux-arm64, macOS ARM64, and windows-x64. No Rust toolchain needed.

API

processPdf(buffer: Buffer, pages?: number[]): PdfResult

Full PDF processing — classify, extract text, and convert to Markdown in one call.

import { processPdf } from 'firecrawl-pdf-inspector'
import { readFileSync } from 'fs'

const pdf = readFileSync('document.pdf')
const result = processPdf(pdf)

console.log(result.pdfType)    // "TextBased" | "Scanned" | "Mixed" | "ImageBased"
console.log(result.markdown)   // Markdown string or null
console.log(result.pageCount)  // 42

classifyPdf(buffer: Buffer): PdfClassification

Classify a PDF as TextBased, Scanned, Mixed, or ImageBased (~10-50ms). Returns which pages need OCR.

import { classifyPdf } from 'firecrawl-pdf-inspector'

const result = classifyPdf(readFileSync('document.pdf'))

console.log(result.pdfType)         // "TextBased" | "Scanned" | "Mixed" | "ImageBased"
console.log(result.pageCount)       // 42
console.log(result.pagesNeedingOcr) // [5, 12, 15] (0-indexed)
console.log(result.confidence)      // 0.875

processPdfWithImages(buffer: Buffer, pages?: number[]): PdfResultWithImages

Process a PDF and extract both markdown and images in one call. The markdown contains ![image](pdf-image://N) placeholders where N is the index into the returned images array.

import { processPdfWithImages } from 'firecrawl-pdf-inspector'
import { readFileSync } from 'fs'

const result = processPdfWithImages(readFileSync('document.pdf'))

console.log(result.images.length)  // 110
console.log(result.markdown)       // "# Title\n\n![image](pdf-image://0)\n\nSome text..."

// Replace placeholders with real URLs after uploading
let content = result.markdown
for (let i = 0; i < result.images.length; i++) {
  const img = result.images[i]
  const ext = img.format === 'Jpeg' ? 'jpg' : 'png'
  const url = await uploadImage(img.data, `image-${i}.${ext}`)
  content = content.replace(`pdf-image://${i}`, url)
}

extractImages(buffer: Buffer): ExtractedImage[]

Extract embedded images from a PDF as raw bytes. Supports JPEG (DCTDecode) and PNG (FlateDecode) images. Returns image data with page position and dimensions.

Image extraction is a separate function from text extraction — calling processPdf or extractText does not pay the cost of image decompression/encoding.

import { extractImages } from 'firecrawl-pdf-inspector'
import { writeFileSync } from 'fs'

const images = extractImages(readFileSync('document.pdf'))

for (const img of images) {
  const ext = img.format === 'Jpeg' ? 'jpg' : 'png'
  writeFileSync(`page${img.page}_${img.width}x${img.height}.${ext}`, img.data)
  console.log(`Page ${img.page}: ${img.width}x${img.height} ${img.format}`)
}

extractTextInRegions(buffer: Buffer, pageRegions: PageRegions[]): PageRegionTexts[]

Extract text within bounding-box regions from a PDF. Designed for hybrid OCR pipelines where a layout model detects regions in rendered page images, and this function extracts text from the PDF structure for text-based pages — skipping GPU OCR.

Each region result includes a needsOcr flag that signals unreliable extraction (empty text, GID-encoded fonts, garbage text, encoding issues).

import { extractTextInRegions } from 'firecrawl-pdf-inspector'

const result = extractTextInRegions(pdf, [
  {
    page: 0, // 0-indexed
    regions: [
      [0, 0, 300, 400],    // [x1, y1, x2, y2] in PDF points, top-left origin
      [300, 0, 612, 400],
    ]
  }
])

for (const region of result[0].regions) {
  if (region.needsOcr) {
    // Unreliable text — send this region to OCR instead
  } else {
    console.log(region.text) // Extracted text in reading order
  }
}

extractText(buffer: Buffer): string

Extract plain text from a PDF.

import { extractText } from 'firecrawl-pdf-inspector'

const text = extractText(readFileSync('document.pdf'))

Types

interface PdfResult {
  pdfType: string          // "TextBased" | "Scanned" | "Mixed" | "ImageBased"
  markdown: string | null  // Markdown output
  pageCount: number
  processingTimeMs: number
  pagesNeedingOcr: number[] // 1-indexed page numbers
  title: string | null
  confidence: number        // 0.0 - 1.0
  isComplexLayout: boolean
  pagesWithTables: number[]
  pagesWithColumns: number[]
  hasEncodingIssues: boolean
}

// Extends PdfResult with extracted images
interface PdfResultWithImages extends PdfResult {
  images: ExtractedImage[]  // Indices match pdf-image://N placeholders in markdown
}

interface PdfClassification {
  pdfType: string          // "TextBased" | "Scanned" | "Mixed" | "ImageBased"
  pageCount: number
  pagesNeedingOcr: number[] // 0-indexed page numbers
  confidence: number        // 0.0 - 1.0
}

interface ExtractedImage {
  page: number              // 1-indexed page number
  x: number                 // X position on page
  y: number                 // Y position on page
  width: number             // Pixel width
  height: number            // Pixel height
  format: string            // "Jpeg" | "Png"
  data: Buffer              // Raw image bytes (valid JPEG or PNG file)
}

interface PageRegions {
  page: number              // 0-indexed
  regions: number[][]       // [[x1, y1, x2, y2], ...] in PDF points, top-left origin
}

interface PageRegionTexts {
  page: number
  regions: RegionText[]
}

interface RegionText {
  text: string
  needsOcr: boolean         // true when text is unreliable
}

Supported image formats

PDF FilterOutput FormatStatus
DCTDecodeJPEGSupported
FlateDecodePNGSupported
JPXDecodeJPEG2000Planned
CCITTFaxDecodeTIFFPlanned

Color spaces: DeviceRGB, DeviceGray, DeviceCMYK (converted to RGB), Indexed, ICCBased, CalRGB, CalGray.

Note: Vector graphics (drawn with PDF path operators) are not raster images and cannot be extracted — they would need to be rendered.

Performance

Text extraction and image extraction are independent paths. processPdf and extractText skip image processing entirely, so there is zero overhead when you only need text.

Platforms

PlatformArchitectureSupported
Linuxx64Yes
LinuxARM64Yes
macOSARM64Yes
Windowsx64Yes

License

MIT

版本与发布记录

@docmost/pdf-inspector 共发布 4 个版本,首次发布于 2026/05/01;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.9.6latest2026/05/155 个月前
1.9.52026/05/106 个月前
1.9.42026/05/016 个月前
1.9.32026/05/016 个月前

关于 @docmost/pdf-inspector 的常见问题

@docmost/pdf-inspector 是什么?

Fast PDF classification, text extraction, and image extraction. Native Rust performance via napi-rs.

如何安装 @docmost/pdf-inspector?

在项目目录运行 npm install @docmost/pdf-inspector,或使用 pnpm add / yarn add / bun add。

@docmost/pdf-inspector 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@docmost/pdf-inspector 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@docmost/pdf-inspector 可以商用吗?

@docmost/pdf-inspector 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@docmost/pdf-inspector 的下载量有多少?

根据 npm 官方下载统计,@docmost/pdf-inspector 在 2026/10/13 – 2026/11/11 这 30 天内被下载 16,070 次,日均约 536 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@docmost/pdf-inspector 还在维护吗?

最新版本 1.9.6 发布于 2026/05/15(5 个月前);至今共发布 4 个版本,其中过去 12 个月发布了 4 个;首次发布于 2026/05/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。