본문으로 건너뛰기
Skillpedia
PDF, Word, 슬라이드7.8k · #12942

pdftotext-fallback

하는 일

이 스킬은 셸의 pdftotext로 PDF 텍스트를 추출하는 복구 방법입니다. PDF 읽기 도구가 쓸 수 없는 결과를 주는 사람에게 맞습니다.

사용하는 경우

  • ✓PDF를 읽을 때 바이너리나 이미지 데이터가 나올 때.
  • ✓샌드박스의 Python PDF 추출이 실패하거나 깨진 텍스트를 줄 때.
  • ✓PDF에서 믿을 만한 텍스트가 필요하고 간단한 명령이면 충분한 경우.

스킬 링크

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdftotext-fallback/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdftotext-fallback/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“샌드박스가 제 PDF에서 깨진 텍스트를 줍니다. 셸에서 pdftotext를 써서 실제 텍스트를 가져와 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

AI는 셸에서 pdftotext를 실행하고 출력을 화면에 보여 줍니다. 복잡한 페이지에는 레이아웃 옵션을, 큰 문서에는 파일로 저장하는 방식을 씁니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

pdftotext Fallback for PDF Text Extraction

When to Use

Apply this pattern when:

  • read_file on a PDF returns binary/image data instead of readable text
  • Python-based PDF extraction (PyMuPDF, pdfplumber, etc.) in execute_code_sandbox fails or returns garbled content
  • You need reliable text extraction from PDF files as a recovery strategy

Why This Works

The pdftotext utility (from poppler-utils) is a mature, command-line tool that handles many PDF edge cases that confuse Python libraries or the read_file tool. It's pre-installed on most Linux systems and provides consistent, reliable text extraction.

Steps

Step 1: Detect the Failure

Recognize extraction failure when:

  • read_file returns binary content, image data, or garbled text
  • Error messages indicate encoding issues or unsupported formats
  • Python PDF libraries in sandbox fail with import errors or extraction failures

Step 2: Use pdftotext via run_shell

Extract to stdout (recommended for quick extraction):

pdftotext /path/to/file.pdf -

The - argument outputs directly to stdout for easy capture in your tool response.

Example:

run_shell("pdftotext document.pdf -")

Step 3: Handle Complex PDFs

Preserve layout (maintains original formatting):

pdftotext -layout /path/to/file.pdf -

Extract to a file (for large PDFs):

pdftotext /path/to/file.pdf /path/to/output.txt

Then read the output file with read_file.

Handle encoded text:

pdftotext -enc UTF-8 /path/to/file.pdf -

Step 4: Verify and Continue

  • Check the extracted text for completeness
  • If text is still garbled, the PDF may be image-based (scanned) - consider OCR tools
  • Proceed with your task using the extracted text

Code Examples

Basic extraction:

# Simple text extraction
text = run_shell("pdftotext document.pdf -")

With error handling:

# Try extraction, check for success
result = run_shell("pdftotext document.pdf - && echo 'SUCCESS' || echo 'FAILED'")

Multi-page PDF with layout:

# Preserve tables and formatting
text = run_shell("pdftotext -layout document.pdf -")

Troubleshooting

Issue Solution
pdftotext: command not found Install poppler-utils: apt-get install poppler-utils
Garbled/special characters Try -enc UTF-8 or -enc ASCII7
Missing formatting Use -layout flag
Scanned PDF (no text) Requires OCR (e.g., tesseract), not text extraction
Large PDF timeout Extract to file instead of stdout

Limitations

  • Does not work on image-only (scanned) PDFs without embedded text
  • May lose complex formatting, tables, or embedded objects
  • Requires poppler-utils to be installed (common on Linux, may need installation on other systems)

Related Tools

  • pdfinfo: Get PDF metadata (pages, size, etc.)
  • pdftoppm: Convert PDF pages to images
  • tesseract: OCR for scanned PDFs
자주 묻는 질문

pdftotext가 왜 믿을 만하다고 하나요?

가이드는 많은 PDF의 예외 경우를 잘 다루는 성숙한 명령줄 도구라고 설명합니다.

하이픈은 무엇을 하나요?

추출된 텍스트를 화면으로 보내 AI가 받을 수 있게 합니다.

큰 PDF를 위한 옵션은 무엇인가요?

화면 출력 대신 파일로 추출하라고 가이드가 제안합니다.

상세 정보

작성자의 원본 설명

Recover PDF text extraction when read_file returns binary data by using pdftotext via shell

repo: HKUDS/AgentPilot

인기도

GitHub 스타
7.8k
순위
#12942
라이선스
MIT
업데이트
2026. 11. 1.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬