Zum Inhalt springen
Skillpedia
PDF, Word & Folien7.8k · #12921

pdf-extraction-fallback-7db3aa

Was er macht

Dieser Skill probiert mehrere Wege, Text aus einer PDF zu holen, wenn der erste Versuch scheitert. Er richtet sich an Menschen, die mit Formularen, Rechtsdokumenten oder gescannten Unterlagen arbeiten.

Wann du ihn nutzt

  • ✓Wenn der erste PDF-Lesevorgang einen Fehler oder gar nichts zurĂŒckgibt.
  • ✓Wenn eine PDF wie ein Scan oder ein Bild statt wie Text wirkt.
  • ✓Wenn frĂŒhere Extraktionen von einem Formular oder einer Tabelle unvollstĂ€ndigen oder verzerrten Text lieferten.

Link zum Skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-extraction-fallback-7db3aa/SKILL.md

Kopiere ihn und fĂŒge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.

So nutzt du ihn

Am einfachsten: Kopiere die Nachricht und fĂŒge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.

Fertige Nachricht zum EinfĂŒgen

Nutze diesen Skill, um mir zu helfen: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-extraction-fallback-7db3aa/SKILL.md Lies die SKILL.md unter diesem Link und folge ihren Anweisungen fĂŒr meine Aufgabe.
Soll deine KI Skills wie diesen selbst finden?Installiere den kostenlosen Skillpedia-MCP: eine Zeile, und sie durchsucht vor jeder Aufgabe 15.000+ Skills.In 1 Minute installieren →

Beispielanfrage an deine KI

“Die KI kann den Text meines Steuerformular-PDFs nicht lesen. Bitte probiere verschiedene Wege, bis du den Text bekommst.”

5 neue Skills pro Woche. 1 Minute Lesezeit.

So funktioniert es

Die KI probiert zuerst ein Kommandozeilenwerkzeug wie pdftotext, prĂŒft, ob die Ausgabe echten Inhalt hat, und wechselt zu Python-Bibliotheken, wenn das nicht der Fall ist.

Technischer Inhalt (originale SKILL.md)

Originaltext des Autors, auf Englisch, direkt von 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
HĂ€ufige Fragen

Welches Werkzeug wird zuerst probiert?

Die Anleitung beginnt mit pdftotext, das schwierige Dateien oft besser verarbeitet.

Woran erkennt man ein schlechtes Ergebnis?

Die Anleitung sagt, zu prĂŒfen, ob die Ausgabe sinnvollen Inhalt enthĂ€lt, bevor es weitergeht.

Werden Python-Bibliotheken spÀter genutzt?

Ja, Bibliotheken wie PyPDF2 oder pdfplumber kommen zum Einsatz, wenn die Shell-Werkzeuge scheitern.

Details

Originalbeschreibung des Autors

Resilient multi-tier PDF extraction with sequential fallback strategies when initial reading fails

repo: HKUDS/AgentPilot

Beliebtheit

GitHub-Sterne
7.8k
Platz im Ranking
#12921
Lizenz
MIT
Aktualisiert
1.11.2026

Ist dieser Skill nĂŒtzlich?

0

Anmelden um abzustimmen.

Kommentare

  • 


Weitere Skills aus diesem Repository

Ähnliche Skills