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

pdftotext-fallback

Qué hace

Esta skill es un método de recuperación para la extracción de texto de PDF con pdftotext desde la shell. Está pensada para quienes sus herramientas de lectura de PDF dan resultados que no se pueden usar.

Cuándo usarla

  • ✓Cuando leer un PDF devuelve datos binarios o de imagen.
  • ✓Cuando la extracción de PDF con Python en el entorno aislado falla o devuelve texto corrupto.
  • ✓Cuando necesito texto fiable de un PDF y basta con un comando sencillo.

Link de la skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdftotext-fallback/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/pdftotext-fallback/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

“El entorno aislado me devuelve texto corrupto de mi PDF. Usa pdftotext desde la shell para obtener el texto real.”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

La IA ejecuta pdftotext desde la shell e imprime la salida en pantalla, usando la opción de maquetación para páginas complejas o escribiendo en un archivo para documentos grandes.

Contenido técnico (SKILL.md original)

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

pdftotext Fallback for PDF Text Extraction

When to Use

Apply this pattern when:

  • read_file on a PDF returns binary/image data instead of readable text
  • Python-based PDF extraction (PyMuPDF, pdfplumber, etc.) in execute_code_sandbox fails or returns garbled content
  • You need reliable text extraction from PDF files as a recovery strategy

Why This Works

The pdftotext utility (from poppler-utils) is a mature, command-line tool that handles many PDF edge cases that confuse Python libraries or the read_file tool. It's pre-installed on most Linux systems and provides consistent, reliable text extraction.

Steps

Step 1: Detect the Failure

Recognize extraction failure when:

  • read_file returns binary content, image data, or garbled text
  • Error messages indicate encoding issues or unsupported formats
  • Python PDF libraries in sandbox fail with import errors or extraction failures

Step 2: Use pdftotext via run_shell

Extract to stdout (recommended for quick extraction):

pdftotext /path/to/file.pdf -

The - argument outputs directly to stdout for easy capture in your tool response.

Example:

run_shell("pdftotext document.pdf -")

Step 3: Handle Complex PDFs

Preserve layout (maintains original formatting):

pdftotext -layout /path/to/file.pdf -

Extract to a file (for large PDFs):

pdftotext /path/to/file.pdf /path/to/output.txt

Then read the output file with read_file.

Handle encoded text:

pdftotext -enc UTF-8 /path/to/file.pdf -

Step 4: Verify and Continue

  • Check the extracted text for completeness
  • If text is still garbled, the PDF may be image-based (scanned) - consider OCR tools
  • Proceed with your task using the extracted text

Code Examples

Basic extraction:

# Simple text extraction
text = run_shell("pdftotext document.pdf -")

With error handling:

# Try extraction, check for success
result = run_shell("pdftotext document.pdf - && echo 'SUCCESS' || echo 'FAILED'")

Multi-page PDF with layout:

# Preserve tables and formatting
text = run_shell("pdftotext -layout document.pdf -")

Troubleshooting

Issue Solution
pdftotext: command not found Install poppler-utils: apt-get install poppler-utils
Garbled/special characters Try -enc UTF-8 or -enc ASCII7
Missing formatting Use -layout flag
Scanned PDF (no text) Requires OCR (e.g., tesseract), not text extraction
Large PDF timeout Extract to file instead of stdout

Limitations

  • Does not work on image-only (scanned) PDFs without embedded text
  • May lose complex formatting, tables, or embedded objects
  • Requires poppler-utils to be installed (common on Linux, may need installation on other systems)

Related Tools

  • pdfinfo: Get PDF metadata (pages, size, etc.)
  • pdftoppm: Convert PDF pages to images
  • tesseract: OCR for scanned PDFs
Preguntas frecuentes

¿Por qué se considera fiable pdftotext?

La guía lo describe como una herramienta de línea de comandos madura que maneja muchos casos límite de PDF.

¿Qué hace el guion?

Envía el texto extraído a la pantalla para que la IA pueda capturarlo.

¿Qué opción conviene para PDF grandes?

La guía sugiere extraer el texto a un archivo en lugar de a la pantalla.

Detalles

Descripción original del autor

Recover PDF text extraction when read_file returns binary data by using pdftotext via shell

repo: HKUDS/AgentPilot

Popularidad

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

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas