pdf-text-extraction-fallback-85d5ca
Skill này làm gì
Skill này là phương án dự phòng cho các PDF có nội dung trả về dưới dạng dữ liệu nhị phân từ trình đọc. Dành cho người cần văn bản của một tệp PDF để tiếp tục công việc.
Khi nào nên dùng
- ✓Khi trình đọc tệp trả về cấu trúc PDF thô hoặc dữ liệu nhị phân.
- ✓Khi cần văn bản PDF để tóm tắt, phân tích hoặc trích xuất dữ liệu.
- ✓Khi pdftotext chưa được cài và cần một thư viện Python thay thế.
Liên kết skill
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-text-extraction-fallback-85d5ca/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
“Trình đọc tệp chỉ hiển thị mã PDF thô cho tài liệu của tôi. Hãy nhờ một trợ lý trích xuất văn bản bằng pdftotext, hoặc pdfplumber nếu không có sẵn.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
AI giao một tác vụ trích xuất rõ ràng cho một trợ lý shell, yêu cầu chạy pdftotext và lưu văn bản, với pdfplumber là phương án Python dự phòng.
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
Use this skill when read_file returns binary data or garbled content for PDF files instead of readable text. This workflow provides a reliable fallback using command-line PDF tools.
When to Use
read_filewithfiletype: pdfreturns binary data, unreadable characters, or errors- You need to extract text from a PDF to process its contents
- Standard file reading methods fail to extract usable text
Step-by-Step Instructions
Step 1: Detect Binary/Unreadable PDF Output
After attempting to read a PDF with read_file, check if the output is:
- Binary data (contains null bytes, non-printable characters)
- Garbled text with many special characters
- Empty or truncated content
# Example of problematic output from read_file
%PDF-1.4
1 0 obj
<< /Type /Catalog ...
If the output looks like raw PDF structure or binary, proceed to Step 2.
Step 2: Use shell_agent with PDF Tools
Invoke shell_agent to extract text using pdftotext (preferred) or pdfplumber (Python fallback):
Task: Extract all text content from <filename.pdf> using pdftotext or pdfplumber.
Output the extracted text in readable format. If pdftotext is not available, use Python with pdfplumber library.
Example shell_agent invocation:
shell_agent task="Extract text from Move_Out_Inspection_Tracker.pdf using pdftotext. Save output to a .txt file and return the content."
Step 3: Validate Extracted Content
After extraction, validate that the content contains expected text patterns:
# Validation checklist
def validate_pdf_extraction(text, expected_patterns=None):
checks = [
bool(text.strip()), # Not empty
len(text) > 50, # Has substantial content
not text.startswith('%PDF'), # Not raw PDF structure
]
if expected_patterns:
for pattern in expected_patterns:
checks.append(pattern.lower() in text.lower())
return all(checks)
Common expected patterns to check:
- Document-specific keywords (e.g., "inspection", "resident", "date")
- Expected data formats (dates, names, IDs)
- Minimum word count threshold
Step 4: Handle Extraction Failures
If validation fails:
Try alternative tool: If
pdftotextfailed, trypdfplumber:shell_agent task="Extract text from <file.pdf> using Python pdfplumber library. Handle any encoding issues."Try OCR fallback: For scanned PDFs:
shell_agent task="This PDF may be scanned. Use pytesseract or similar OCR tool to extract text from <file.pdf>."Report specific error: Document what patterns were expected but not found.
Step 5: Proceed with Data Processing
Once validated text is obtained:
- Parse the extracted text for required data
- Store or process the content as needed
- Continue with the original task workflow
Code Example
# Complete extraction workflow
def extract_pdf_text_fallback(pdf_path, expected_patterns=None):
"""Extract text from PDF with fallback handling."""
# Step 1: Try read_file first
content = read_file(filetype="pdf", file_path=pdf_path)
# Step 2: Check if binary/unreadable
if is_binary_or_garbled(content):
# Step 3: Use shell_agent fallback
result = shell_agent(
task=f"Extract all text from {pdf_path} using pdftotext. Return the text content."
)
content = result.stdout
# Step 4: Validate
if not validate_pdf_extraction(content, expected_patterns):
# Try pdfplumber as secondary fallback
result = shell_agent(
task=f"Extract text from {pdf_path} using Python pdfplumber library."
)
content = result.stdout
return content
def is_binary_or_garbled(text):
"""Check if text appears to be binary or unreadable."""
if not text:
return True
if text.startswith('%PDF'):
return True
# Check for high ratio of non-printable characters
non_printable = sum(1 for c in text if ord(c) > 127 or ord(c) < 32)
return non_printable / len(text) > 0.3
Tips
- pdftotext is typically faster and pre-installed on many systems
- pdfplumber handles complex layouts better but requires Python
- For scanned PDFs, you'll need OCR tools (tesseract, pytesseract)
- Always validate extracted content matches your expected data patterns
- Save intermediate extraction results fo
Câu hỏi thường gặp
AI yêu cầu trợ lý làm gì?
Nó yêu cầu trợ lý trích xuất văn bản bằng pdftotext và lưu vào một tệp văn bản.
Thư viện Python dự phòng là gì?
Hướng dẫn nêu pdfplumber là phương án Python dự phòng.
Đầu ra mong đợi là gì?
Văn bản đọc được của tài liệu, được lưu trong một tệp.
Chi tiết
Mô tả gốc của tác giả
Fallback workflow for extracting text from PDFs when read_file returns binary data
repo: HKUDS/AgentPilot
Độ phổ biến
- Sao GitHub
- 7.8k
- Vị trí xếp hạng
- #12933
- 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.