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

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가 스킬을 읽고 지침을 따릅니다.

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

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

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

  1. Validate each attempt - Check output length and quality before accepting
  2. Log which method succeeded - Track which tier worked for future reference
  3. Set minimum content thresholds - Don't accept trivial results (e.g., <50 chars)
  4. Combine methods if needed - Some documents need multiple approaches for different sections
  5. 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.

이 스킬이 유용한가요?

0

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

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬