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

pdf-extract-shell-first

하는 일

이 스킬은 가장 안정적인 셸 도구를 먼저 쓰는 PDF 텍스트 추출 순서를 제시합니다. 실패를 줄이고 PDF 텍스트를 얻어야 하는 사람에게 맞습니다.

사용하는 경우

  • ✓PDF가 내 컴퓨터에 있고 텍스트를 최대한 빨리 얻어야 할 때.
  • ✓PDF가 웹 주소에 있어 읽기 전에 내려받아야 할 때.
  • ✓가장 안정적인 추출이 필요하고 모든 대체 도구를 쓸 수 있는 경우.

스킬 링크

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-download-extract-fallback-enhanced-e27e0c/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/pdf-download-extract-fallback-enhanced-e27e0c/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의 텍스트를 가져와 주세요. 로컬 파일이든 웹 링크든 상관없습니다. 셸 도구를 먼저 쓰고 필요하면 Python 도구를 써 주세요.”

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

작동 방식

PDF가 온라인에 있으면 AI는 브라우저 스타일 요청으로 내려받습니다. 그다음 단순 읽기를 시도하고, 셸에서 pdftotext를 실행하며, 마지막 선택지로 Python을 씁니다.

기술 내용 (원본 SKILL.md)

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

PDF Extract with Shell-First Tool Cascade

This skill provides an optimized workflow for extracting text content from PDF documents (local files or downloaded URLs) using a prioritized tool cascade that favors shell-based extraction before falling back to Python libraries.

Why Shell-First?

Analysis of execution patterns shows:

  • read_file on PDFs sometimes returns binary/image data instead of text
  • run_shell with pdftotext has higher success rate and fewer sandbox errors
  • execute_code_sandbox can fail with "unknown error" in constrained environments
  • Shell tools are more reliable for PDF text extraction when available

Entry Point: Determine Your Starting Point

Before beginning, identify your scenario:

Scenario Start Here Skip
PDF already on local disk Step 1 (Try read_file) Shell download steps
PDF at a web URL Shell download, then Step 1 None
Need maximum reliability Full cascade (all 3 tools) None

Complete Workflow

Step 0: Download PDF (URL Only)

If your PDF is at a web URL, download it first using browser user-agent:

curl -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" -o target.pdf "URL_HERE"

Key flags:

  • -L: Follow redirects
  • -A: Set user-agent header to mimic a real browser
  • -o: Specify output filename

If you already have the PDF locally, skip to Step 1.

Step 1: Try read_file (Primary Attempt)

First, attempt to extract text using the read_file tool:

read_file(filetype="pdf", file_path="target.pdf")

Evaluate the response:

Response Type Interpretation Next Action
Clean readable text Success Proceed to content analysis
Binary data / PNG image / garbled read_file returned raw data Go to Step 2 immediately
Error / timeout Tool failure Go to Step 2 immediately

Critical: If read_file returns binary image data or garbled content, do not retry read_file. Immediately proceed to Step 2.

Step 2: Use run_shell with pdftotext (Preferred Fallback)

When read_file fails or returns binary data, use run_shell with pdftotext:

run_shell(command="pdftotext target.pdf output.txt")

Then read the extracted text:

read_file(filetype="txt", file_path="output.txt")

If pdftotext is not found, install it first:

run_shell(command="apt-get update && apt-get install -y poppler-utils")
# Or for macOS:
run_shell(command="brew install poppler")

Then retry:

run_shell(command="pdftotext target.pdf output.txt")

Verify extraction quality:

  • Check that output.txt exists and has content
  • Sample the text to ensure it's readable (not garbled)
  • If extraction looks corrupted, proceed to Step 3

Step 3: Use execute_code_sandbox with PyMuPDF (Last Resort)

If pdftotext is unavailable or produces poor results, use Python's PyMuPDF via execute_code_sandbox:

import fitz  # PyMuPDF

doc = fitz.open("target.pdf")
text = ""
for page in doc:
    text += page.get_text()
doc.close()

with open("output.txt", "w") as f:
    f.write(text)
print(f"Extracted {len(text)} characters from {len(doc)} pages")

Execute via:

execute_code_sandbox(code="<python code above>")

Then read the result:

read_file(filetype="txt", file_path="output.txt")

Note: execute_code_sandbox may fail with "unknown error" in some environments. If this occurs, document the failure and proceed to Step 4.

Step 4: Graceful Degradation to Domain Knowledge

If all extraction methods fail:

  1. Document the specific failure mode for each tool attempted
  2. Extract any partial content that was successfully retrieved
  3. Supplement missing content from established domain knowledge
  4. Clearly mark which portions are from source vs. generated from knowledge
  5. Provide citations for any claimed requirements or specifications

Example degradation documentation:

EXTRACTION FAILURE REPORT:
- Source: [URL or file path]
- read_file: Returned binary/image data (no text extraction)
- run_shell/pdftotext: [Tool not available / produced garbled output / succeeded]
- execute_code_sandbox/PyMuPDF: [Failed with unknown error / succeeded]

NOTE: Content below combines partial extraction with established domain 
knowledge for [topic]. Verify against official sources when available.
``
자주 묻는 질문

셸 도구가 왜 먼저 오나요?

가이드는 pdftotext가 성공률이 더 높고 샌드박스 오류가 적다고 말합니다.

웹 PDF는 어떻게 내려받나요?

curl로 브라우저 스타일 헤더를 쓰고, 리디렉션을 따라가며 내려받습니다.

모든 도구가 실패하면 어떻게 하나요?

가이드의 순서는 세 도구를 모두 거치므로, 포기하기 전에 마지막 Python 방법도 시도합니다.

상세 정보

작성자의 원본 설명

PDF text extraction with tool cascade prioritizing shell pdftotext before Python fallback

repo: HKUDS/AgentPilot

인기도

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

이 스킬이 유용한가요?

0

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

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬