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

pdf-read-file-fallback

Was er macht

Dieser Skill ist ein Ausweichweg für PDFs, die der eingebaute Leser als Bild- oder Binärdaten zurückgibt. Er richtet sich an Menschen, die die Wörter in PDFs brauchen, die die KI normal nicht lesen kann.

Wann du ihn nutzt

  • ✓Wenn das Lesen einer PDF Bild- oder Binärdaten statt Text zurückgibt.
  • ✓Wenn die PDF ein gescanntes Dokument ist oder eine komplexe Formatierung hat.
  • ✓Wenn ich den Text einer PDF in lesbarer Form brauche.

Link zum Skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-read-file-fallback/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-read-file-fallback/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 bekommt bei meiner PDF nur Binärdaten. Bitte hol den Text mit einem Werkzeug der Kommandozeile heraus.”

5 neue Skills pro Woche. 1 Minute Lesezeit.

So funktioniert es

Die KI versucht zuerst das normale Lesen der Datei, prüft, ob das Ergebnis brauchbar ist, und führt bei Bedarf pdftotext mit der Layout-Option aus, um den Text zu bekommen.

Technischer Inhalt (originale SKILL.md)

Originaltext des Autors, auf Englisch, direkt von GitHub.

PDF Text Extraction Fallback

When to Use

Use this pattern when read_file with filetype="pdf" returns binary image data instead of extractable text content. This commonly occurs with PDFs that contain scanned images or complex formatting.

Steps

1. Attempt Primary Extraction

First, try using read_file:

result = read_file(file_path="document.pdf", filetype="pdf")

Important: Use filetype (not file_type) - incorrect parameter naming will cause execution failures.

2. Detect Binary/Image Data

Check if the result contains unusable content:

# Indicators of binary/image data:
# - Contains null bytes: '\x00'
# - Very short or empty
# - Contains image markers (PNG/JPEG headers)
# - Unreadable character sequences

if not result or len(result) < 50 or '\x00' in str(result):
    # Proceed to fallback

3. Use pdftotext via run_shell

Extract text using the pdftotext command-line tool:

shell_result = run_shell(command="pdftotext -layout document.pdf -")
text_content = shell_result.stdout

The - flag outputs to stdout for easy capture. The -layout flag preserves original formatting.

4. Handle pdftotext Unavailable

If pdftotext is not installed, try Python-based extraction:

result = execute_code_sandbox(code="""
import pdfplumber
text = ''
with pdfplumber.open('document.pdf') as pdf:
    for page in pdf.pages:
        extracted = page.extract_text()
        if extracted:
            text += extracted + '\\n'
print(text)
""")

Complete Example

file_path = "report.pdf"

# Primary attempt
result = read_file(file_path=file_path, filetype="pdf")

# Validate and fallback if needed
if not result or len(str(result)) < 100 or '\x00' in str(result):
    # Fallback to pdftotext
    shell_result = run_shell(command=f"pdftotext -layout {file_path} -")
    text_content = shell_result.stdout
    
    # If pdftotext fails, try Python extraction
    if not text_content or len(text_content) < 50:
        code_result = execute_code_sandbox(code=f"""
import pdfplumber
text = ''
with pdfplumber.open('{file_path}') as pdf:
    for page in pdf.pages:
        extracted = page.extract_text()
        if extracted:
            text += extracted + '\\n'
print(text)
""")
        text_content = code_result

Notes

  • pdftotext is part of the poppler-utils package on most Linux systems
  • For scanned/image-only PDFs, consider OCR tools (tesseract) instead
  • Always validate parameter names against tool documentation (filetype vs file_type)
Häufige Fragen

Was macht die Layout-Option?

Sie erhält den ursprünglichen Abstand und die Struktur der Seite so weit wie möglich.

Was ist, wenn pdftotext fehlt?

Die Anleitung schlägt eine Python-Bibliothek wie pdfplumber als Ersatz vor.

Woran erkennt man Binärausgabe?

Die Anleitung nennt Anzeichen wie Null-Bytes, ein sehr kurzes Ergebnis oder Bildkopfzeilen.

Details

Originalbeschreibung des Autors

Extract text from PDFs using pdftotext when read_file returns binary data

repo: HKUDS/AgentPilot

Beliebtheit

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

Ist dieser Skill nützlich?

0

Anmelden um abzustimmen.

Kommentare

  • …

Weitere Skills aus diesem Repository

Ähnliche Skills