@fastgpt-sdk/anydoc

中文文档
0.2.5发布于 2026/08/30MITTypeScriptCommonJS零依赖近 30 天下载 7405

Convert documents (doc, docx, odt, rtf, epub, pdf, presentations, spreadsheets, csv) to GitHub-Flavored Markdown

原始使用文档
文档目录8 节
  1. Supported formats
  2. CLI
  3. Usage
  4. Scanned pages
  5. Errors
  6. Format detection
  7. Images and embedded objects
  8. License

@fastgpt-sdk/anydoc

npm License: MIT

Convert Word, PowerPoint, Excel, OpenDocument, RTF, EPUB, CSV, and PDF files into clean GitHub-Flavored Markdown. Node.js bindings for the anydoc Rust crate, built by Firecrawl. Also available as a hosted API through Firecrawl Parse, which adds our OCR models for the scanned pages anydoc can't read on its own.

Every format parses into one shared document model and renders through a single Markdown serializer, so headings, tables, lists, and footnotes come out the same no matter which format goes in. Conversion runs on the libuv thread pool and never blocks the event loop. TypeScript types ship with the package.

npm install @fastgpt-sdk/anydoc

Supported formats

FormatExtensions
Word.doc, .docx, .docm
PowerPoint.ppt, .pps, .pot, .pptx, .pptm, .ppsx, .ppsm
Excel.xls, .xlsx, .xlsm, .xlsb
OpenDocument.odt, .ods, .odp
Rich Text Format.rtf
EPUB.epub
CSV.csv
PDF.pdf

CLI

The package ships an anydoc command, so npx converts a document with no install:

npx @fastgpt-sdk/anydoc report.docx               # Markdown to stdout
npx @fastgpt-sdk/anydoc slides.pptx -o slides.md  # or to a file
npx @fastgpt-sdk/anydoc - --format csv < data.csv # read stdin
npx @fastgpt-sdk/anydoc scan.pdf --ocr hosted     # scanned pages via Firecrawl Parse

Markdown goes to stdout, errors to stderr, and anydoc --help covers the rest.

Usage

import { toDocument, toMarkdown, toMarkdownBytes } from '@fastgpt-sdk/anydoc';

// From a file path:
const markdown = await toMarkdown('report.docx');

// From bytes, with the format detected from the content:
const fromBytes = await toMarkdownBytes(bytes);

// Or name it, which signature-less formats (CSV) need:
const fromCsv = await toMarkdownBytes(bytes, 'csv');

// Preserve embedded images and their positions in the Markdown:
const { markdown, assets } = await toMarkdownBytes(bytes, 'doc', {
  embeddedImageMode: 'reference',
  maxImageBytes: 32 * 1024 * 1024,
  maxImageTotalBytes: 128 * 1024 * 1024,
});
// markdown contains ![alt](asset:0); assets contains { id: 0, mediaType, data, ... }.

// Or stop at the document model, which also carries embedded assets:
const document = await toDocument(bytes);

Scanned pages

anydoc converts locally and does not do OCR, so a PDF with scanned or image-only pages rejects with needsOcr. Opt in with ocr: 'hosted' to send that document to Firecrawl Parse. No signup needed. Set apiKey or FIRECRAWL_API_KEY for higher limits.

const markdown = await toMarkdown('scan.pdf', { ocr: 'hosted' });

On the CLI, anydoc scan.pdf --ocr hosted.

Errors

A conversion rejects only when no complete Markdown could come out of the file. The rejection is an Error whose code names what went wrong:

try {
  return await toMarkdown(path);
} catch (error) {
  // No document comes out of these, so record the file and take the next one.
  if (error.code === 'encrypted' || error.code === 'unsupported') {
    unconverted.push({ path, reason: error.code });
    return null;
  }
  throw error;
}
codeMeaning
unsupportedUnknown format, or one that cannot be converted
needsOcrScanned or image-only pages of a PDF, listed in pages
malformedStructurally unusable: no meaningful content could be extracted
encryptedEncrypted or password-protected
resourceLimitCrossed a fixed safety limit (decompression, nesting, node count)
missingPartA part required for any meaningful output is absent
ioThe file could not be read, from toMarkdown only
hostedocr: 'hosted' could not get the document through Firecrawl Parse

error.message carries the detail, naming the package part at fault where the format identifies one. TypeScript gets the union as ConvertErrorCode.

Format detection

The format is read from the file content, using the marker its specification designates: the PDF header, the RTF open group, OLE stream names, the ZIP package mimetype and content types. CSV has no such marker, so detection returns null for it and the extension, or an explicit format, names it instead.

formatFromBytes(bytes); // 'docx', or null when nothing matches
formatFromExtension('.pptm'); // 'pptx'
formatFromPath('report.odt'); // 'odt'

Images and embedded objects

By default, an embedded image renders as its alt text while the bytes stay on document.assets. Pass embeddedImageMode: 'reference' to toMarkdown or toMarkdownBytes to receive { markdown, assets }: the Markdown contains asset:<id> image URLs and assets contains the corresponding image/* bytes. maxImageBytes and maxImageTotalBytes cap one image and all images respectively; both default to 128 MiB and reject with resourceLimit when crossed. Non-image embedded objects keep the default alt-text behavior. Images that carry an external URL always render as ordinary Markdown images.

Full behavior notes and benchmarks live in the repository README.

License

MIT

版本与发布记录

@fastgpt-sdk/anydoc 共发布 1 个版本,首次发布于 2026/08/30;过去 12 个月发布了 1 个版本。

版本发布日期距今
0.2.5latest2026/08/302 个月前

关于 @fastgpt-sdk/anydoc 的常见问题

@fastgpt-sdk/anydoc 是什么?

Convert documents (doc, docx, odt, rtf, epub, pdf, presentations, spreadsheets, csv) to GitHub-Flavored Markdown

如何安装 @fastgpt-sdk/anydoc?

在项目目录运行 npm install @fastgpt-sdk/anydoc,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 anydoc,可以用 npx anydoc 直接运行。

@fastgpt-sdk/anydoc 支持 TypeScript 吗?

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

@fastgpt-sdk/anydoc 支持 ESM 还是 CommonJS?

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

@fastgpt-sdk/anydoc 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@fastgpt-sdk/anydoc 可以商用吗?

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

@fastgpt-sdk/anydoc 的下载量有多少?

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

@fastgpt-sdk/anydoc 还在维护吗?

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