pdf-extraction-fallback-80956b
Fungsinya
Skill ini mencakup pengunduhan PDF dari situs resmi atau yang dilindungi serta pembacaan teksnya, dengan pemeriksaan untuk unduhan yang gagal. Skill ini cocok untuk orang yang mengumpulkan buku panduan atau dokumen regulasi dari web.
Kapan dipakai
- ✓Saat unduhan PDF dari situs pemerintah atau perusahaan menghasilkan file yang sangat kecil atau rusak.
- ✓Saat situs mungkin memblokir unduhan otomatis atau memuat kontennya dengan skrip.
- ✓Saat saya membutuhkan teks yang andal dari PDF yang saya unduh dari web.
Link skill
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-extraction-fallback-80956b/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
“Unduh PDF buku panduan dari situs lembaga ini dan ambil teksnya. Jika unduhannya tampak rusak, coba cara lain.”
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
AI mengunduh file dengan curl, memeriksa ukurannya dan apakah isinya halaman galat, lalu mengekstrak teks dengan alat cadangan jika file tersebut valid.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.
PDF Extraction Fallback Workflow
This skill provides a robust, multi-layered approach to downloading and extracting text from PDF documents when sources may be protected, corrupted, or inaccessible via standard methods.
When to Use
- Downloading regulatory documents, handbooks, or official PDFs from government/enterprise websites
- Sources that may have JavaScript protection, CORS restrictions, or dynamic content
- When initial PDF downloads produce suspiciously small files or error content
- Any scenario requiring reliable text extraction from potentially problematic PDF sources
Core Workflow
Step 1: Download with Validation
# Download PDF with size check
curl -L -o output.pdf "https://example.com/document.pdf"
# Early failure detection: check file size
file_size=$(stat -c%s output.pdf 2>/dev/null || stat -f%z output.pdf)
if [ "$file_size" -lt 1000 ]; then
echo "WARNING: File size ($file_size bytes) suggests failed download or error page"
# Check for HTML/JavaScript error content
if head -c 500 output.pdf | grep -qi "<html\|<script\|error\|access denied"; then
echo "FAILURE: File contains error message, not PDF content"
rm output.pdf
# Proceed to alternative download method
fi
fi
Step 2: Sequential Extraction Fallbacks
Try extraction methods in order, moving to next on failure:
Fallback 1: pdftotext (command-line)
if command -v pdftotext &> /dev/null; then
pdftotext output.pdf output.txt
if [ -s output.txt ] && [ $(wc -c < output.txt) -gt 100 ]; then
echo "SUCCESS: pdftotext extraction"
exit 0
fi
fi
Fallback 2: PyMuPDF (fitz)
import fitz # PyMuPDF
def extract_with_pymupdf(pdf_path):
try:
doc = fitz.open(pdf_path)
text = ""
for page in doc:
text += page.get_text()
doc.close()
if len(text.strip()) > 100:
return text
return None
except Exception as e:
print(f"PyMuPDF failed: {e}")
return None
Fallback 3: pdfplumber
import pdfplumber
def extract_with_pdfplumber(pdf_path):
try:
text = ""
with pdfplumber.open(pdf_path) as pdf:
for page in pdf.pages:
page_text = page.extract_text()
if page_text:
text += page_text + "\n"
if len(text.strip()) > 100:
return text
return None
except Exception as e:
print(f"pdfplumber failed: {e}")
return None
Step 3: Content Sanity Validation
After any extraction method succeeds:
def validate_extracted_text(text, min_length=100):
"""Validate extracted content is meaningful"""
if not text or len(text.strip()) < min_length:
return False
# Check for common error patterns
error_patterns = [
"access denied", "permission denied", "error",
"javascript", "<html", "<script", "404", "403"
]
text_lower = text.lower()[:500] # Check first 500 chars
for pattern in error_patterns:
if pattern in text_lower:
return False
return True
Complete Workflow Script
#!/usr/bin/env python3
"""
Robust PDF extraction with multiple fallbacks
"""
import subprocess
import os
import sys
def download_pdf(url, output_path):
"""Download PDF with validation"""
subprocess.run(["curl", "-L", "-o", output_path, url], check=True)
# Validate download
if not os.path.exists(output_path):
return False
file_size = os.path.getsize(output_path)
if file_size < 1000:
with open(output_path, 'r', errors='ignore') as f:
content = f.read(500).lower()
if any(x in content for x in ['<html', '<script', 'error', 'denied']):
os.remove(output_path)
return False
return True
def extract_text(pdf_path):
"""Try multiple extraction methods"""
# Method 1: pdftotext
try:
result = subprocess.run(
["pdftotext", pdf_path, "-"],
capture_output=True, text=True, timeout=60
)
if result.stdout and len(result.stdout.strip()) > 100:
return result.stdout
except:
pass
# Method 2: PyMuPDF
try:
import fitz
doc = fitz.open(pdf_path)
text = "".join(page.get_text() for page in doc)
doc.close()
if len(text.strip()) >
Pertanyaan umum
Bagaimana unduhan yang gagal dideteksi?
Panduan ini memeriksa apakah file sangat kecil atau berisi HTML atau pesan akses ditolak.
Apa yang terjadi pada file yang rusak?
Panduan ini menghapusnya dan mencoba metode unduhan alternatif.
Alat apa yang mengekstrak teks lebih dulu?
Pilihan pertama panduan ini adalah pdftotext dari shell.
Detail
Deskripsi asli dari pembuat
Multi-fallback PDF download and text extraction with early failure detection
repo: HKUDS/AgentPilot
Popularitas
- Bintang GitHub
- 7.8k
- Peringkat
- #12922
- Lisensi
- MIT
- Diperbarui
- 1/11/2026
Komentar
- …
Skill lain dari repositori ini
agentpilot
7.8kMembantu agent Anda meningkatkan proyek langkah demi langkah dengan menyiapkan tugas dan menjalankan loop AgentPilot yang mengusulkan, menguji, dan memberi skor pada perubahan.
openspace
7.8kMembantu agent Anda menyiapkan OpenSpace, alat yang menyimpan dan mengambil skill agent, lalu menghubungkannya ke aplikasi AI Anda melalui MCP.
rsi-arena
7.8kMembantu agent Anda menyiapkan dan menjalankan tes benchmark AI standar, seperti AIME dan Terminal-Bench, untuk membandingkan berbagai metode perbaikan.
experiment-guide
7.8kMembantu agent Anda merencanakan eksperimen kecil, membaca hasilnya, dan mencatat temuan saat menyelidiki cara memperbaiki sebuah program.
Skill serupa
feishu-doc
394kMembantu agent Anda membaca, membuat, dan mengedit dokumen cloud Feishu, termasuk teks, gambar, dan tabel, dengan memakai alat dokumen.
feishu-drive
394kMemungkinkan agent Anda menelusuri, mengatur, dan memberi komentar pada file di folder cloud Feishu yang sudah dibagikan kepada bot.
feishu-perm
394kMembantu agent Anda memeriksa dan mengubah siapa yang dapat mengakses file Feishu, dengan memilih izin terkecil yang memenuhi permintaan Anda.