Saltar al contenido
Skillpedia
PDF, Word y diapositivas7,8 mil · #12932

pdf-text-extraction-9424c5

Qué hace

Esta skill explica cómo extraer texto legible de archivos PDF con pdftotext cuando falla el lector habitual. Está pensada para quienes trabajan con documentos PDF que la IA no puede leer directamente.

Cuándo usarla

  • ✓Cuando leer un PDF devuelve contenido corrupto o binario.
  • ✓Cuando el PDF contiene imágenes escaneadas o estructuras binarias complejas.
  • ✓Cuando necesito guardar el texto del PDF en un archivo o usarlo en pasos posteriores.

Link de la skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-text-extraction-9424c5/SKILL.md

Cópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.

Cómo usar

La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.

Mensaje listo para pegar

Usa esta skill para ayudarme: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-text-extraction-9424c5/SKILL.md Lee el archivo SKILL.md de ese link y sigue sus instrucciones en mi tarea.
¿Quieres que tu IA encuentre skills como esta por sí sola?Instala el MCP gratis de Skillpedia: una línea, y busca entre 15.000+ skills antes de cada tarea.Instalar en 1 minuto →

Ejemplo de qué pedirle a la IA

“Lee el texto de mi documento.pdf. El lector normal da una salida corrupta, así que extráelo con pdftotext.”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

La IA confirma que el archivo existe, ejecuta pdftotext para obtener el texto y usa la salida directamente o la escribe en un archivo de texto temporal si hace falta.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de GitHub.

PDF Text Extraction via pdftotext

Problem

When using read_file on PDF documents, the function may return binary image data or garbled content instead of readable text. This occurs because PDFs can contain scanned images or complex binary structures that read_file cannot properly parse as text.

Solution

Use the pdftotext command-line utility via run_shell to extract clean text content from PDF files.

Steps

1. Verify PDF file exists

import os

pdf_path = "path/to/document.pdf"
if not os.path.exists(pdf_path):
    raise FileNotFoundError(f"PDF not found: {pdf_path}")

2. Extract text using pdftotext

from tools import run_shell

# Extract text to stdout
result = run_shell(command=f"pdftotext '{pdf_path}' -", timeout=60)
pdf_text = result.stdout

# Alternative: extract to a temporary file
temp_txt = "/tmp/extracted.txt"
run_shell(command=f"pdftotext '{pdf_path}' '{temp_txt}'", timeout=60)
with open(temp_txt, 'r') as f:
    pdf_text = f.read()

3. Handle parameter naming carefully

When calling read_file, be aware of the parameter name:

  • Use filetype="pdf" (not file_type)
  • Some tool implementations may use different parameter names
# Correct parameter usage
content = read_file(file_path="doc.pdf", filetype="pdf")

# If this returns binary/garbled data, fall back to pdftotext

Common pdftotext Options

Option Description
- Output to stdout
-layout Maintain original layout
-f <n> Start from page n
-l <n> End at page n
-q Quiet mode

Example with options:

result = run_shell(command=f"pdftotext -layout -q '{pdf_path}' -", timeout=60)

Error Handling

from tools import run_shell

def extract_pdf_text(pdf_path):
    """Extract text from PDF using pdftotext with error handling."""
    import os
    
    if not os.path.exists(pdf_path):
        raise FileNotFoundError(f"PDF not found: {pdf_path}")
    
    result = run_shell(command=f"pdftotext '{pdf_path}' -", timeout=60)
    
    if result.returncode != 0:
        raise RuntimeError(f"pdftotext failed: {result.stderr}")
    
    return result.stdout.strip()

When to Use This Pattern

  • read_file returns binary data, garbled text, or image content for a PDF
  • You need searchable/processable text from PDF documents
  • The PDF contains text (not just scanned images - for those, consider OCR tools)

Prerequisites

  • pdftotext must be installed (part of poppler-utils on Debian/Ubuntu, poppler on macOS via Homebrew)
  • Verify availability: run_shell(command="which pdftotext")
Preguntas frecuentes

¿Por qué comprobar primero que el archivo existe?

La guía se detiene con un error claro si la ruta del PDF es incorrecta.

¿Qué consejo hay sobre el parámetro de read_file?

La guía indica usar filetype en lugar de file_type al llamar a la herramienta de lectura.

¿Dónde puede ir la salida?

Puede mostrarse en pantalla o escribirse en un archivo de texto.

Detalles

Descripción original del autor

Extract text from PDF files using pdftotext when read_file returns binary data

repo: HKUDS/AgentPilot

Popularidad

Estrellas en GitHub
7,8 mil
Posición en el ranking
#12932
Licencia
MIT
Actualizada
1/11/2026

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas