Chuyển đến nội dung
Skillpedia
PDF, Word và slide7.8k · #12968

reliable-pdf-extraction

Skill này làm gì

Skill này hướng dẫn AI agent đọc PDF bằng pdftotext, pdfinfo hoặc thư viện Python khi trình đọc tích hợp cho kết quả kém. Nó dành cho những người làm việc với tài liệu PDF qua AI.

Khi nào nên dùng

  • ✓Khi trình đọc PDF thông thường trả về dữ liệu nhị phân, lỗi hoặc văn bản trống.
  • ✓Khi bạn cần văn bản từ PDF để dùng cho việc trích xuất dữ liệu có cấu trúc.
  • ✓Khi bạn muốn kiểm tra thông tin chi tiết của PDF trước khi đọc văn bản.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/reliable-pdf-extraction/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Đọc file PDF báo cáo tôi đã đính kèm và cho tôi các ý chính. Trình đọc PDF thông thường báo lỗi.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent trước hết thử trình đọc thông thường và kiểm tra đầu ra. Nếu kết quả bị lỗi ký tự hoặc trống, nó chạy pdftotext hoặc pdfinfo qua shell, hoặc dùng một thư viện Python, rồi đọc văn bản đã trích xuất.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Reliable PDF Text Extraction

Problem

The read_file tool with filetype='pdf' often returns binary image data, errors, or unusable output when attempting to extract text from PDF documents. This makes it unreliable for structured data extraction tasks.

Solution

Use run_shell with command-line tools (pdftotext, pdfinfo) or execute_code_sandbox with Python libraries (PyMuPDF, pdfplumber) to extract PDF text content reliably.

Methods

Method 1: pdftotext (Recommended for simple extraction)

# Extract all text to stdout
pdftotext input.pdf -

# Or extract to file
pdftotext input.pdf output.txt
cat output.txt

Method 2: pdfinfo (For metadata)

pdfinfo input.pdf

Method 3: Python with PyMuPDF (fitz)

import fitz  # PyMuPDF

doc = fitz.open("input.pdf")
text = ""
for page in doc:
    text += page.get_text()
print(text)
doc.close()

Method 4: Python with pdfplumber (Better for tables/structured data)

import pdfplumber

with pdfplumber.open("input.pdf") as pdf:
    for page in pdf.pages:
        text = page.extract_text()
        print(text)
        # For tables:
        # tables = page.extract_tables()

Workflow

  1. Attempt read_file with filetype='pdf' first (in case it works)

  2. Check output - If you receive:

    • Binary/garbage data
    • Error messages
    • Empty or truncated content
    • Image data instead of text
  3. Fall back to one of the extraction methods above:

    • Use pdftotext via run_shell for quick text extraction
    • Use pdfplumber via execute_code_sandbox for structured data/tables
    • Use PyMuPDF for complex layouts or when you need more control
  4. Process the extracted text for your task

Example Usage

# Via run_shell
result = run_shell(command="pdftotext document.pdf -")
pdf_text = result.stdout

# Via execute_code_sandbox
code = """
import pdfplumber
with pdfplumber.open("/path/to/document.pdf") as pdf:
    for page in pdf.pages:
        print(page.extract_text())
"""
result = execute_code_sandbox(code=code)
pdf_text = result.stdout

Tips

  • pdftotext is fastest and most reliable for plain text extraction
  • pdfplumber excels at extracting tables and preserving layout
  • PyMuPDF offers the most control for complex PDF structures
  • Always check if the PDF is scanned/image-based (may need OCR tools like tesseract)
  • Some PDFs have copy protection that may prevent text extraction
Câu hỏi thường gặp

pdfinfo hiển thị điều gì?

Nó hiển thị các chi tiết như số trang và kích thước trang, giúp ích trước khi trích xuất.

Agent có luôn thử trình đọc thông thường trước không?

Có, skill yêu cầu thử nó trước và chỉ chuyển sang cách khác khi đầu ra có vẻ sai.

Những thư viện Python nào được nêu tên?

Skill nêu PyMuPDF cho văn bản nói chung và pdfplumber cho bảng.

Chi tiết

Mô tả gốc của tác giả

Use shell commands or Python libraries to extract PDF text when read_file PDF handler fails

repo: HKUDS/AgentPilot

Độ phổ biến

Sao GitHub
7.8k
Vị trí xếp hạng
#12968
Giấy phép
MIT
Cập nhật
1/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự