pdf-extraction-fallback-7db3aa
하는 일
이 스킬은 첫 시도가 실패할 때 PDF에서 텍스트를 얻는 여러 방법을 시도합니다. 양식, 법률 서류, 스캔 문서를 다루는 사람에게 맞습니다.
사용하는 경우
- ✓PDF를 처음 읽을 때 오류가 나거나 아무것도 나오지 않을 때.
- ✓PDF가 텍스트가 아니라 스캔이나 이미지로 보일 때.
- ✓이전 추출에서 양식이나 표의 텍스트가 불완전하거나 깨진 경우.
스킬 링크
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-extraction-fallback-7db3aa/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“AI가 제 세금 양식 PDF에서 텍스트를 읽지 못합니다. 텍스트를 얻을 때까지 여러 방법을 시도해 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
AI는 먼저 pdftotext 같은 명령줄 도구를 시도하고, 결과에 실제 내용이 있는지 확인한 뒤, 내용이 없으면 PyPDF2나 pdfplumber 같은 Python 라이브러리로 넘어갑니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
PDF Extraction Fallback Strategy
Purpose
When processing complex documents (tax forms, legal documents, scanned materials), PDF extraction often fails on the first attempt. This skill provides a systematic fallback approach that tries multiple extraction methods in sequence until one succeeds.
When to Use
- Initial PDF reading tools return errors or empty content
- Document appears to be scanned/image-based rather than text-based
- Previous extraction attempts produced incomplete or garbled output
- Working with forms, tables, or structured documents that need reliable extraction
Fallback Sequence
Tier 1: Shell-Based Extraction (pdftotext)
Start with command-line tools that often handle edge cases better:
# Extract text maintaining layout
pdftotext -layout input.pdf output.txt
# Extract raw text (faster, less formatting)
pdftotext input.pdf output.txt
# Extract specific page range
pdftotext -f 1 -l 3 input.pdf output.txt
Check if output contains meaningful content before proceeding.
Tier 2: Python-Based Parsing
If shell tools fail, use Python libraries with different extraction approaches:
# Using PyPDF2 for basic text extraction
import PyPDF2
with open('document.pdf', 'rb') as f:
reader = PyPDF2.PdfReader(f)
text = ''.join(page.extract_text() for page in reader.pages)
# Using pdfplumber for tables and structured content
import pdfplumber
with pdfplumber.open('document.pdf') as pdf:
for page in pdf.pages:
text = page.extract_text()
tables = page.extract_tables()
# Using pypdf for newer PDF features
from pypdf import PdfReader
reader = PdfReader('document.pdf')
text = ''.join(page.extract_text() for page in reader.pages)
Tier 3: OCR Tools (for Scanned Documents)
If the PDF contains images or scanned content, use OCR:
# Using tesseract via command line
tesseract input.pdf output --psm 6
# Using Python with pytesseract
import pytesseract
from pdf2image import convert_from_path
images = convert_from_path('document.pdf')
text = ''.join(pytesseract.image_to_string(img) for img in images)
Implementation Pattern
def extract_pdf_resilient(pdf_path):
"""Try multiple extraction methods until one succeeds."""
# Tier 1: Shell extraction
result = run_shell(f'pdftotext -layout "{pdf_path}" -')
if result.stdout and len(result.stdout.strip()) > 100:
return result.stdout, 'pdftotext'
# Tier 2: Python libraries
try:
import pdfplumber
with pdfplumber.open(pdf_path) as pdf:
text = ''.join(page.extract_text() or '' for page in pdf.pages)
if text.strip():
return text, 'pdfplumber'
except Exception:
pass
# Tier 3: OCR fallback
try:
from pdf2image import convert_from_path
import pytesseract
images = convert_from_path(pdf_path)
text = ''.join(pytesseract.image_to_string(img) for img in images)
if text.strip():
return text, 'tesseract-ocr'
except Exception:
pass
raise ExtractionError("All extraction methods failed")
Decision Criteria
| Indicator | Action |
|---|---|
| Empty output | Proceed to next tier |
| Garbled/special characters | Try next tier |
| Partial content | Accept if meets minimum threshold |
| Tool not available | Skip to next tier |
| Format-specific errors | Try alternative library |
Best Practices
- Validate each attempt - Check output length and quality before accepting
- Log which method succeeded - Track which tier worked for future reference
- Set minimum content thresholds - Don't accept trivial results (e.g., <50 chars)
- Combine methods if needed - Some documents need multiple approaches for different sections
- Preserve original file - Never modify the source PDF during extraction attempts
Error Handling
- Catch exceptions at each tier, don't fail immediately
- Log detailed error messages for debugging
- Continue to next tier even if current tier partially succeeds but produces poor quality
- After all tiers fail, provide clear summary of what was tried
Output Quality Check
Before declaring extraction complete:
def validate_extraction(text):
if not text or len(text.strip()) < 50:
return False
if text.count('') > len(text) * 0.1: # Too many replacement chars
return False
if len(set(text)) < 10: # Too little cha
자주 묻는 질문
어떤 도구를 먼저 쓰나요?
가이드는 까다로운 파일을 더 잘 다루는 pdftotext부터 시작합니다.
나쁜 결과는 어떻게 알아보나요?
다음 단계로 넘어가기 전에 출력에 의미 있는 내용이 있는지 확인하라고 가이드가 안내합니다.
Python 라이브러리도 쓰나요?
네, 셸 도구가 실패하면 PyPDF2나 pdfplumber 같은 라이브러리를 씁니다.
상세 정보
작성자의 원본 설명
Resilient multi-tier PDF extraction with sequential fallback strategies when initial reading fails
repo: HKUDS/AgentPilot
인기도
- GitHub 스타
- 7.8k
- 순위
- #12921
- 라이선스
- 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 파일에 누가 접근할 수 있는지 확인하고 바꾸도록 돕습니다.