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

robust-pdf-read

Skill này làm gì

Skill này chỉ cho AI agent cách lấy văn bản đọc được từ PDF bằng công cụ pdftotext. Nó dành cho những người có việc đọc PDF chỉ trả về các ký tự không đọc được.

Khi nào nên dùng

  • ✓Khi trình đọc file trả về dữ liệu nhị phân thô, dữ liệu ảnh base64 hoặc ký tự lỗi với một PDF.
  • ✓Khi bạn cần các chữ trong PDF dưới dạng văn bản thuần để làm việc.
  • ✓Khi bạn muốn bố cục văn bản của PDF được giữ gần nhất với bản gốc.

Liên kết skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/robust-pdf-read/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/robust-pdf-read/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 hợp đồng thuê nhà của tôi và cho tôi văn bản. Trình đọc file chỉ hiển thị ký tự lỗi.”

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

Cách hoạt động

Agent kiểm tra kết quả của trình đọc thông thường xem có nội dung nhị phân hoặc bị lỗi không. Nếu có, nó chạy pdftotext với các tùy chọn bố cục và không có ký tự ngắt trang, rồi đưa văn bản ra đầu ra chuẩn để đọc.

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.

Robust PDF Text Extraction

Problem

Standard file reading tools (e.g., read_file) often fail to extract text from PDF documents. Instead of returning parsed text, they may return:

  • Raw binary data
  • Base64 encoded images
  • Garbled characters or null bytes

This occurs because PDFs are complex binary formats, not plain text files. Attempts to parse them using general-purpose Python libraries (like PyMuPDF) in sandboxed environments may also fail due to missing dependencies or environment restrictions.

Solution

Use the pdftotext command-line utility (part of poppler-utils) via run_shell. This tool is commonly pre-installed in Linux environments and reliably extracts text content from PDFs.

Procedure

1. Detect Extraction Failure

When attempting to read a PDF:

  • Check the content returned by read_file.
  • If the content contains null bytes (\x00), appears as base64, or is clearly binary/garbled, assume standard reading has failed.

2. Execute pdftotext

Run the following shell command using run_shell:

pdftotext -layout -nopgbrk <file_path> -
  • -layout: Maintains the physical layout of the text (optional but recommended).
  • -nopgbrk: Prevents inserting form feed characters between pages.
  • -: Outputs content to stdout instead of creating a new file.

3. Parse Output

Capture the stdout from the shell command. This string is the extracted text.

Example Usage

Scenario: You need to read document.pdf.

Step 1: Attempt standard read

content = read_file("document.pdf")
if "\x00" in content or not content.strip():
    # Fallback needed
    pass

Step 2: Fallback to shell

result = run_shell("pdftotext -layout -nopgbrk document.pdf -")
text = result.stdout

Prerequisites

  • The environment must have pdftotext installed (usually via poppler-utils).
  • If pdftotext is not found, attempt to install it (apt-get install poppler-utils) if permissions allow, or notify the user.

Benefits

  • Reliability: Bypasses Python library dependency issues in sandboxes.
  • Speed: Command-line tools are often faster than loading heavy Python libraries.
  • Compatibility: Works consistently across most Linux-based agent environments.
Câu hỏi thường gặp

Agent phát hiện một lần đọc thất bại bằng cách nào?

Nó tìm các byte null, dữ liệu trông như base64 hoặc văn bản rõ ràng bị lỗi.

Các tùy chọn của pdftotext làm gì?

Tùy chọn layout giữ bố cục trang, còn nopgbrk loại bỏ các ký tự ngắt trang.

Có cần cài đặt đặc biệt không?

Skill nói pdftotext là một phần của poppler-utils, thường đã được cài sẵn trên hệ thống Linux.

Chi tiết

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

Reliably extract text from PDFs using pdftotext when standard file reading fails.

repo: HKUDS/AgentPilot

Độ phổ biến

Sao GitHub
7.8k
Vị trí xếp hạng
#12977
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ự