Poppler (pdftotext)
$ pdftotext 基金会 低风险Poppler 的 pdftotext 可将 PDF 中的纯文本、保留排版文本(-layout)、TSV(-tsv)或带边界框的 HTML(-bbox)直接提取至标准输出(-)。配合查看元数据的 pdfinfo 与栅格化页面的 pdftoppm,为 Agent 提供确定性的本地 PDF 解析能力。
brew install poppler 使用 pdftotext -layout 与 pdfinfo 进行本地 PDF 提取仅需毫秒级耗时,且无需将文档上传至 MCP 服务器。
Agent 友好度体检单
本地探针实测证据抓取的 --help 摘要
pdftotext version 26.08.0 Copyright 2005-2026 The Poppler Developers - http://poppler.freedesktop.org Copyright 1996-2011, 2022 Glyph & Cog, LLC Usage: pdftotext [options] <PDF-file> [<text-file>] -f <int> : first page to convert -l <int> : last page to convert -r <fp> : resolution, in DPI (default is 72) -x <int> : x-coordinate of the crop area top left corner -y <int> : y-coordinate of the crop area top left corner -W <int> : width of crop area in pixels (default is 0) -H <int> : height of crop area in pixels (default is 0) -layout : maintain original physical layout -fixed <fp> : assume fixed-pitch (or tabular) text -raw : keep strings in content stream order -remove-hyphens <string>: end-of-line hyphen handling: none, soft, or all (default: all) -nodiag : discard diagonal text -htmlmeta : generate a simple HTML file, including the meta information -tsv : generate a simple TSV file, including the meta information for bounding boxes -enc <string> : output text encoding name -listenc : list available encodings -eol <string> : output end-of-line convention (unix, dos, or mac) -nopgbrk : don't insert page breaks between pages -bbox : output bounding box for each word and page size to html. Sets -htmlmeta -bbox-layout : like -bbox but with extra layout bounding box data. Sets -htmlmeta -cropbox : use the crop box rather than media box -colspacing <fp> : how much spacing we allow after a word before considering adjacent text to be a new column, as a fraction of the font size (default is 0.7, old releases had a 0.3 default) -opw <string> : owner password (for encrypted files) -upw <string> : user password (for encrypted files) -q : don't print any messages or errors -v : print copyright and version info -h : print usage information -help : print usage information --help : print usage information -? : print usage information
FCRS-1.0 六维评分拆解
支持 - 标准输出流、-tsv 表格输出与 -q 静默模式,具备确定性的非交互执行能力,但缺少原生 --json 输出。
- Supports
-layout,-tsv,-bbox,-q, and-stdout streaming - No native
--jsonoutput flag
输出至 - 时完全只读,绝不修改源 PDF,并支持通过 -f/-l 限定页码范围。
- Writing to
-performs zero filesystem mutations
广泛内置于 Homebrew(poppler)、各大 Linux 发行版(poppler-utils)与 Windows,C++ 原生启动极快。
- Available via
brew install popplerand standard OS repositories
单个软件包即提供 pdftotext、pdfinfo、pdftoppm 与 pdfimages,覆盖绝大多数本地 PDF 检查场景。
- Includes text extraction, metadata, image extraction, and page rendering
隶属 freedesktop.org 的老牌项目,在各大 Linux 与 macOS 生态中持续积极维护。
- Maintained under
freedesktop.orgPoppler project
-h 摘要与手册页清晰,但采用传统单短横线参数风格(如 -layout、-nopgbrk),而非 GNU --long 双短横线规范。
- Built-in
pdftotext -hlists all options concisely
安全边界、鉴权与放权指南
无需凭据;可选通过 -opw 和 -upw 参数为加密的本地 PDF 传入密码。
免费,基于 GPL-2.0-or-later 协议的开源二进制工具套件。
# Poppler (pdftotext) Agent Rules - Pass `-` as the output argument (`pdftotext -layout in.pdf -`) to read text directly via stdout without creating temporary files. - Use `-f` and `-l` page bounds on large PDFs so output does not overflow agent context.
Agent 高频安全命令配方
只读查询(安全推荐)
pdftotext -layout -q -f 1 -l 5 input.pdf -
提取第 1–5 页并保持物理列对齐后直接输出到标准输出(-),同时用 -q 静默警告。
pdftotext -tsv -q input.pdf -
将带坐标与文本标记的制表符分隔数据输出至标准输出,便于结构化解析文档。
受控写入与预演
pdftotext -enc UTF-8 -layout input.pdf extracted.txt
在不改动源 PDF 的前提下将提取文本保存至 extracted.txt。
核心优势
- + 可通过
-直接向标准输出流式输出整洁的 UTF-8 文本,支持-layout或-tsv结构。 - + 随包附带
pdfinfo与pdftoppm,可一并完成元数据检查与页面栅格化。
注意事项与踩坑点
- ! 不直接输出
--json,且对纯扫描图片型 PDF 需配合pdftoppm与tesseract进行 OCR。 - ! 使用单短横线参数(
-layout、-nopgbrk),与常见 GNU--long习惯不同。