本文へスキップ
Skillpedia
PDF・Word・スライド7.8k · #12977

robust-pdf-read

できること

このスキルは、pdftotextツールを使ってPDFから読めるテキストを取り出す方法をAIエージェントに示します。PDFの読み取りが、読めない文字として返ってくる人向けです。

使う場面

  • ✓ファイルリーダーが、PDFに対して生のバイナリや、base64の画像データ、文字化けを返すとき。
  • ✓読めるテキストとして、PDFの文章が必要なとき。
  • ✓PDFのテキストのレイアウトを、できるだけ元のまま保ちたいとき。

スキルのリンク

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/robust-pdf-read/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/robust-pdf-read/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“私の賃貸契約のPDFを読んで、テキストを教えてください。ファイルリーダーは文字化けしか表示しません。”

毎週5つの新しいスキル。1分で読めます。

仕組み

エージェントは、通常のリーダーの出力にバイナリや文字化けがないかを確認します。見つかったら、レイアウトのオプションと改ページ文字を除くオプションを付けてpdftotextを実行し、テキストを標準出力に送って読みます。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

Robust PDF Text Extraction

Problem

Standard file reading tools (e.g., read_file) often fail to extract text from PDF documents. Instead of returning parsed text, they may return:

  • Raw binary data
  • Base64 encoded images
  • Garbled characters or null bytes

This occurs because PDFs are complex binary formats, not plain text files. Attempts to parse them using general-purpose Python libraries (like PyMuPDF) in sandboxed environments may also fail due to missing dependencies or environment restrictions.

Solution

Use the pdftotext command-line utility (part of poppler-utils) via run_shell. This tool is commonly pre-installed in Linux environments and reliably extracts text content from PDFs.

Procedure

1. Detect Extraction Failure

When attempting to read a PDF:

  • Check the content returned by read_file.
  • If the content contains null bytes (\x00), appears as base64, or is clearly binary/garbled, assume standard reading has failed.

2. Execute pdftotext

Run the following shell command using run_shell:

pdftotext -layout -nopgbrk <file_path> -
  • -layout: Maintains the physical layout of the text (optional but recommended).
  • -nopgbrk: Prevents inserting form feed characters between pages.
  • -: Outputs content to stdout instead of creating a new file.

3. Parse Output

Capture the stdout from the shell command. This string is the extracted text.

Example Usage

Scenario: You need to read document.pdf.

Step 1: Attempt standard read

content = read_file("document.pdf")
if "\x00" in content or not content.strip():
    # Fallback needed
    pass

Step 2: Fallback to shell

result = run_shell("pdftotext -layout -nopgbrk document.pdf -")
text = result.stdout

Prerequisites

  • The environment must have pdftotext installed (usually via poppler-utils).
  • If pdftotext is not found, attempt to install it (apt-get install poppler-utils) if permissions allow, or notify the user.

Benefits

  • Reliability: Bypasses Python library dependency issues in sandboxes.
  • Speed: Command-line tools are often faster than loading heavy Python libraries.
  • Compatibility: Works consistently across most Linux-based agent environments.
よくある質問

読み取りが失敗したことはどう分かりますか?

ヌルバイト、base64のように見えるデータ、明らかに文字化けしたテキストを探します。

pdftotextのオプションは何をしますか?

layoutオプションはページのレイアウトを保ち、nopgbrkオプションは改ページ文字を取り除きます。

特別なインストールが必要ですか?

pdftotextはpoppler-utilsの一部で、Linuxのシステムには既に入っていることが多いとスキルは述べています。

詳細

作者による元の説明

Reliably extract text from PDFs using pdftotext when standard file reading fails.

repo: HKUDS/AgentPilot

人気

GitHubのスター
7.8k
ランキング
#12977
ライセンス
MIT
更新日
2026/11/1

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル