pdf-read-file-fallback
Skill này làm gì
Skill này là phương án dự phòng cho các PDF mà trình đọc tích hợp trả về dưới dạng hình ảnh hoặc dữ liệu nhị phân. Dành cho người cần đọc chữ bên trong PDF mà AI không đọc bình thường được.
Khi nào nên dùng
- ✓Khi đọc một PDF trả về hình ảnh hoặc dữ liệu nhị phân thay vì văn bản.
- ✓Khi PDF là tài liệu quét hoặc có định dạng phức tạp.
- ✓Khi tôi cần văn bản từ một PDF ở dạng đọc được.
Liên kết skill
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-read-file-fallback/SKILL.mdSao 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
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“AI chỉ nhận được dữ liệu nhị phân từ PDF của tôi. Hãy lấy văn bản ra bằng một công cụ dòng lệnh.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
AI thử đọc tệp bình thường trước, kiểm tra xem kết quả có dùng được không, và nếu không thì chạy pdftotext với tùy chọn layout để lấy văn bản.
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.
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
pdftotextis part of thepoppler-utilspackage on most Linux systems- For scanned/image-only PDFs, consider OCR tools (tesseract) instead
- Always validate parameter names against tool documentation (
filetypevsfile_type)
Câu hỏi thường gặp
Tùy chọn layout làm gì?
Nó giữ khoảng cách và cấu trúc gốc của trang càng nhiều càng tốt.
Nếu thiếu pdftotext thì sao?
Hướng dẫn gợi ý một thư viện Python, như pdfplumber, làm phương án dự phòng.
Dữ liệu nhị phân được nhận ra thế nào?
Hướng dẫn chú ý các dấu hiệu như byte rỗng, kết quả rất ngắn hoặc tiêu đề hình ảnh.
Chi tiết
Mô tả gốc của tác giả
Extract text from PDFs using pdftotext when read_file returns binary data
repo: HKUDS/AgentPilot
Độ phổ biến
- Sao GitHub
- 7.8k
- Vị trí xếp hạng
- #12931
- Giấy phép
- MIT
- Cập nhật
- 1/11/2026
Bình luận
- …
Thêm skill từ kho mã này
agentpilot
7.8kGiúp agent của bạn cải thiện dự án từng bước bằng cách chuẩn bị tác vụ và chạy vòng lặp AgentPilot, gồm đề xuất, kiểm thử và chấm điểm thay đổi.
openspace
7.8kGiúp agent của bạn thiết lập OpenSpace, công cụ lưu và lấy lại skill của agent, rồi kết nối nó với ứng dụng AI của bạn qua MCP.
rsi-arena
7.8kGiúp agent của bạn thiết lập và chạy các bài kiểm thử benchmark AI chuẩn, như AIME và Terminal-Bench, để so sánh các phương pháp cải tiến khác nhau.
experiment-guide
7.8kGiúp agent của bạn lên kế hoạch các thí nghiệm nhỏ, đọc kết quả và ghi lại phát hiện khi tìm cách cải thiện một chương trình.
Skill tương tự
feishu-doc
394kGiúp agent của bạn đọc, tạo và sửa tài liệu đám mây Feishu, gồm văn bản, hình ảnh và bảng, bằng công cụ tài liệu.
feishu-drive
394kCho phép agent của bạn duyệt, sắp xếp và bình luận các file trong một thư mục đám mây Feishu đã được chia sẻ với bot.
feishu-perm
394kGiúp agent của bạn kiểm tra và thay đổi ai có quyền truy cập một file Feishu, chọn quyền nhỏ nhất đáp ứng yêu cầu của bạn.