pdf-text-extraction-fallback-85d5ca
하는 일
이 스킬은 리더가 바이너리 데이터로 내용을 반환하는 PDF의 예비 방법입니다. 작업을 계속하려고 PDF 파일의 텍스트가 필요한 사람에게 맞습니다.
사용하는 경우
- ✓파일 리더가 PDF의 원시 구조나 바이너리 데이터를 반환할 때.
- ✓요약, 분석 또는 데이터 추출에 PDF 텍스트가 필요할 때.
- ✓pdftotext가 없어 Python 라이브러리가 필요한 경우.
스킬 링크
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-text-extraction-fallback-85d5ca/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“파일 리더가 제 문서의 원시 PDF 코드만 보여 줍니다. 도우미에게 pdftotext로 텍스트를 추출하게 하고, 없으면 pdfplumber를 쓰게 해 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
AI는 셸 도우미에게 명확한 추출 작업을 넘기고, pdftotext로 실행해 텍스트를 저장하도록 요청하며, Python 대체 방법으로 pdfplumber를 지정합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
PDF Text Extraction Fallback
Use this skill when read_file returns binary data or garbled content for PDF files instead of readable text. This workflow provides a reliable fallback using command-line PDF tools.
When to Use
read_filewithfiletype: pdfreturns binary data, unreadable characters, or errors- You need to extract text from a PDF to process its contents
- Standard file reading methods fail to extract usable text
Step-by-Step Instructions
Step 1: Detect Binary/Unreadable PDF Output
After attempting to read a PDF with read_file, check if the output is:
- Binary data (contains null bytes, non-printable characters)
- Garbled text with many special characters
- Empty or truncated content
# Example of problematic output from read_file
%PDF-1.4
1 0 obj
<< /Type /Catalog ...
If the output looks like raw PDF structure or binary, proceed to Step 2.
Step 2: Use shell_agent with PDF Tools
Invoke shell_agent to extract text using pdftotext (preferred) or pdfplumber (Python fallback):
Task: Extract all text content from <filename.pdf> using pdftotext or pdfplumber.
Output the extracted text in readable format. If pdftotext is not available, use Python with pdfplumber library.
Example shell_agent invocation:
shell_agent task="Extract text from Move_Out_Inspection_Tracker.pdf using pdftotext. Save output to a .txt file and return the content."
Step 3: Validate Extracted Content
After extraction, validate that the content contains expected text patterns:
# Validation checklist
def validate_pdf_extraction(text, expected_patterns=None):
checks = [
bool(text.strip()), # Not empty
len(text) > 50, # Has substantial content
not text.startswith('%PDF'), # Not raw PDF structure
]
if expected_patterns:
for pattern in expected_patterns:
checks.append(pattern.lower() in text.lower())
return all(checks)
Common expected patterns to check:
- Document-specific keywords (e.g., "inspection", "resident", "date")
- Expected data formats (dates, names, IDs)
- Minimum word count threshold
Step 4: Handle Extraction Failures
If validation fails:
Try alternative tool: If
pdftotextfailed, trypdfplumber:shell_agent task="Extract text from <file.pdf> using Python pdfplumber library. Handle any encoding issues."Try OCR fallback: For scanned PDFs:
shell_agent task="This PDF may be scanned. Use pytesseract or similar OCR tool to extract text from <file.pdf>."Report specific error: Document what patterns were expected but not found.
Step 5: Proceed with Data Processing
Once validated text is obtained:
- Parse the extracted text for required data
- Store or process the content as needed
- Continue with the original task workflow
Code Example
# Complete extraction workflow
def extract_pdf_text_fallback(pdf_path, expected_patterns=None):
"""Extract text from PDF with fallback handling."""
# Step 1: Try read_file first
content = read_file(filetype="pdf", file_path=pdf_path)
# Step 2: Check if binary/unreadable
if is_binary_or_garbled(content):
# Step 3: Use shell_agent fallback
result = shell_agent(
task=f"Extract all text from {pdf_path} using pdftotext. Return the text content."
)
content = result.stdout
# Step 4: Validate
if not validate_pdf_extraction(content, expected_patterns):
# Try pdfplumber as secondary fallback
result = shell_agent(
task=f"Extract text from {pdf_path} using Python pdfplumber library."
)
content = result.stdout
return content
def is_binary_or_garbled(text):
"""Check if text appears to be binary or unreadable."""
if not text:
return True
if text.startswith('%PDF'):
return True
# Check for high ratio of non-printable characters
non_printable = sum(1 for c in text if ord(c) > 127 or ord(c) < 32)
return non_printable / len(text) > 0.3
Tips
- pdftotext is typically faster and pre-installed on many systems
- pdfplumber handles complex layouts better but requires Python
- For scanned PDFs, you'll need OCR tools (tesseract, pytesseract)
- Always validate extracted content matches your expected data patterns
- Save intermediate extraction results fo
자주 묻는 질문
AI는 도우미에게 무엇을 요청하나요?
pdftotext로 텍스트를 추출해 텍스트 파일로 저장하라고 요청합니다.
어떤 Python 라이브러리가 대체 수단인가요?
가이드는 pdfplumber를 Python 대체 방법으로 지정합니다.
어떤 출력을 기대하나요?
문서에서 읽을 수 있는 텍스트가 파일에 저장된 형태입니다.
상세 정보
작성자의 원본 설명
Fallback workflow for extracting text from PDFs when read_file returns binary data
repo: HKUDS/AgentPilot
인기도
- GitHub 스타
- 7.8k
- 순위
- #12933
- 라이선스
- MIT
- 업데이트
- 2026. 11. 1.
댓글
- …
이 저장소의 다른 스킬
agentpilot
7.8k작업을 준비하고 AgentPilot 루프를 실행해 변경을 제안, 테스트, 점수화하면서 프로젝트를 단계적으로 개선하도록 돕습니다.
openspace
7.8k에이전트 스킬을 저장하고 가져오는 도구인 OpenSpace를 설정하고, MCP를 통해 AI 앱에 연결하도록 돕습니다.
rsi-arena
7.8kAIME나 Terminal-Bench 같은 표준 AI 벤치마크 테스트를 설정하고 실행해 서로 다른 개선 방법을 비교하도록 돕습니다.
experiment-guide
7.8k프로그램을 개선하는 방법을 조사하면서 작은 실험을 계획하고, 결과를 읽고, 발견 사항을 기록하도록 돕습니다.
비슷한 스킬
feishu-doc
394k에이전트가 문서 도구를 사용해 텍스트, 이미지, 표를 포함한 Feishu 클라우드 문서를 읽고, 만들고, 편집하도록 돕습니다.
feishu-drive
394k에이전트가 봇과 공유된 Feishu 클라우드 폴더의 파일을 찾아보고, 정리하고, 댓글을 달도록 돕습니다.
feishu-perm
394k에이전트가 요청을 충족하는 가장 작은 권한을 골라, Feishu 파일에 누가 접근할 수 있는지 확인하고 바꾸도록 돕습니다.