[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KFZG8JC1N3NTX2TPT7WKTJ":3,"skill-same:01M6KFZG8JC1N3NTX2TPT7WKTJ":67},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":23,"publishedAt":34,"linkOnly":35,"markdownContent":36,"markdownBody":37,"frontMatter":38,"refName":39,"commitSha":40,"skillDirectory":41,"forksCount":14,"repositoryHtmlUrl":42,"repositoryHomepageUrl":6,"ownerHtmlUrl":43,"ownerBlogUrl":44,"ownerDescription":45,"updatedAt":46,"install":47,"resources":60},"01M6KFZG8JC1N3NTX2TPT7WKTJ","robust-pdf-extraction",null,"Multi-method PDF extraction with sequential fallback and OCR for scanned documents","xyliu-cs\u002FOpenSpace-GDPval","xyliu-cs","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F89236536?v=4","01M6KF8Z1V4TXS86CKSH48BY8T","xy","01M6KF8Z67443W0SHXM85JEF0B",0,"MIT","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Frobust-pdf-extraction\u002FSKILL.md",[18],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000002","文档处理","SCENARIO","使用场景",[24,25,26,27,28,29,30,31,32,33],"PDF","extraction","pdf extraction","robust pdf extraction","documents","ocr","fallback","multi","with","for","2026-11-10 10:12:30",false,"---\nname: robust-pdf-extraction\ndescription: Multi-method PDF extraction with sequential fallback and OCR for scanned documents\n---\n\n# Robust PDF Extraction Workflow\n\nThis skill provides a systematic approach to extracting text from PDF files, handling both text-based and scanned\u002Fimage-based documents through progressive fallback methods.\n\n## When to Use\n\n- Processing PDFs of unknown or mixed types (text vs. scanned images)\n- Critical document processing where extraction failure is not acceptable\n- Batch processing multiple PDFs with varying formats\n\n## Workflow Steps\n\n### Step 1: Verify File Accessibility\n\nBefore attempting extraction, confirm the PDF exists and is readable:\n\n```bash\n# Check file exists and get basic info\nls -la \u002Fpath\u002Fto\u002Fdocument.pdf\n\n# Or search for files if location uncertain\nfind \u002Fpath -name \"*.pdf\" -type f 2>\u002Fdev\u002Fnull\n```\n\n### Step 2: Attempt Primary Extraction (pdfplumber)\n\nStart with pdfplumber for best text structure preservation:\n\n```python\nimport pdfplumber\n\ndef extract_with_pdfplumber(pdf_path):\n    text = \"\"\n    with pdfplumber.open(pdf_path) as pdf:\n        for page in pdf.pages:\n            page_text = page.extract_text()\n            if page_text:\n                text += page_text + \"\\n\"\n    return text.strip()\n```\n\n### Step 3: Fallback to Secondary Method (pypdfium2)\n\nIf pdfplumber returns empty or incomplete text:\n\n```python\nimport pdfium2\n\ndef extract_with_pypdfium2(pdf_path):\n    pdf = pdfium2.PdfDocument(pdf_path)\n    text = \"\"\n    for page in pdf:\n        text_page = page.get_textpage()\n        page_text = text_page.get_text_bounded()\n        if page_text:\n            text += page_text + \"\\n\"\n    return text.strip()\n```\n\n### Step 4: Fallback to Tertiary Method (pdftotext)\n\nIf pypdfium2 also fails, use command-line pdftotext:\n\n```bash\npdftotext \u002Fpath\u002Fto\u002Fdocument.pdf - 2>\u002Fdev\u002Fnull\n```\n\nOr in Python:\n\n```python\nimport subprocess\n\ndef extract_with_pdftotext(pdf_path):\n    result = subprocess.run(\n        ['pdftotext', pdf_path, '-'],\n        capture_output=True,\n        text=True\n    )\n    return result.stdout.strip()\n```\n\n### Step 5: Detect Scanned\u002FImage-Based PDFs\n\nAfter each extraction attempt, verify text was actually extracted:\n\n```python\ndef is_meaningful_text(text, min_chars=50):\n    \"\"\"Check if extracted text is meaningful (not empty or just whitespace)\"\"\"\n    if not text:\n        return False\n    # Remove whitespace and check length\n    cleaned = ''.join(text.split())\n    return len(cleaned) >= min_chars\n```\n\n### Step 6: OCR Fallback for Scanned Documents\n\nIf all text extraction methods return empty\u002Finsufficient text, the PDF is likely scanned. Use OCR:\n\n```python\nimport pdf2image\nimport pytesseract\nfrom PIL import Image\n\ndef extract_with_ocr(pdf_path, dpi=300):\n    \"\"\"Extract text from scanned PDFs using OCR\"\"\"\n    text = \"\"\n    images = pdf2image.convert_from_path(pdf_path, dpi=dpi)\n    for image in images:\n        page_text = pytesseract.image_to_string(image)\n        text += page_text + \"\\n\"\n    return text.strip()\n```\n\n## Complete Workflow Function\n\n```python\ndef robust_pdf_extract(pdf_path):\n    \"\"\"\n    Extract text from PDF using progressive fallback methods.\n    Returns (text, method_used) tuple.\n    \"\"\"\n    methods = [\n        (\"pdfplumber\", extract_with_pdfplumber),\n        (\"pypdfium2\", extract_with_pypdfium2),\n        (\"pdftotext\", extract_with_pdftotext),\n    ]\n    \n    for method_name, extract_func in methods:\n        try:\n            text = extract_func(pdf_path)\n            if is_meaningful_text(text):\n                return text, method_name\n        except Exception as e:\n            print(f\"{method_name} failed: {e}\")\n            continue\n    \n    # All text methods failed - try OCR\n    try:\n        text = extract_with_ocr(pdf_path)\n        if is_meaningful_text(text):\n            return text, \"ocr\"\n    except Exception as e:\n        print(f\"OCR failed: {e}\")\n    \n    return \"\", \"failed\"\n```\n\n## Dependencies\n\nInstall required packages:\n\n```bash\npip install pdfplumber pypdfium2 pdf2image pytesseract pillow\n# Also need system packages:\n# apt-get install poppler-utils tesseract-ocr  # Debian\u002FUbuntu\n# brew install poppler tesseract  # macOS\n```\n\n## Best Practices\n\n1. **Log which method succeeded** - helps identify document types for future optimization\n2. **Set reasonable character thresholds** - adjust `min_chars` based on expected document content\n3. **Handle exceptions gracefully** - each method may fail for different reasons\n4. **Consider DPI for OCR** - higher DPI (300+) improves accuracy but increases processing time\n5. **Cache results** - if processing same PDFs repeatedly, store successful extraction method per file\n\n## Troubleshooting\n\n| Symptom | Likely Cause | Solution |\n|---------|--------------|----------|\n| All methods return empty | Scanned PDF | OCR fallback should handle this |\n| pdfplumber fails with permission error | File locked or permissions issue | Check file permissions with `ls -la` |\n| OCR returns gibberish | Low quality scan or wrong language | Increase DPI, specify language in pytesseract |\n| pdftotext not found | Missing poppler-utils | Install system package |","# Robust PDF Extraction Workflow\n\nThis skill provides a systematic approach to extracting text from PDF files, handling both text-based and scanned\u002Fimage-based documents through progressive fallback methods.\n\n## When to Use\n\n- Processing PDFs of unknown or mixed types (text vs. scanned images)\n- Critical document processing where extraction failure is not acceptable\n- Batch processing multiple PDFs with varying formats\n\n## Workflow Steps\n\n### Step 1: Verify File Accessibility\n\nBefore attempting extraction, confirm the PDF exists and is readable:\n\n```bash\n# Check file exists and get basic info\nls -la \u002Fpath\u002Fto\u002Fdocument.pdf\n\n# Or search for files if location uncertain\nfind \u002Fpath -name \"*.pdf\" -type f 2>\u002Fdev\u002Fnull\n```\n\n### Step 2: Attempt Primary Extraction (pdfplumber)\n\nStart with pdfplumber for best text structure preservation:\n\n```python\nimport pdfplumber\n\ndef extract_with_pdfplumber(pdf_path):\n    text = \"\"\n    with pdfplumber.open(pdf_path) as pdf:\n        for page in pdf.pages:\n            page_text = page.extract_text()\n            if page_text:\n                text += page_text + \"\\n\"\n    return text.strip()\n```\n\n### Step 3: Fallback to Secondary Method (pypdfium2)\n\nIf pdfplumber returns empty or incomplete text:\n\n```python\nimport pdfium2\n\ndef extract_with_pypdfium2(pdf_path):\n    pdf = pdfium2.PdfDocument(pdf_path)\n    text = \"\"\n    for page in pdf:\n        text_page = page.get_textpage()\n        page_text = text_page.get_text_bounded()\n        if page_text:\n            text += page_text + \"\\n\"\n    return text.strip()\n```\n\n### Step 4: Fallback to Tertiary Method (pdftotext)\n\nIf pypdfium2 also fails, use command-line pdftotext:\n\n```bash\npdftotext \u002Fpath\u002Fto\u002Fdocument.pdf - 2>\u002Fdev\u002Fnull\n```\n\nOr in Python:\n\n```python\nimport subprocess\n\ndef extract_with_pdftotext(pdf_path):\n    result = subprocess.run(\n        ['pdftotext', pdf_path, '-'],\n        capture_output=True,\n        text=True\n    )\n    return result.stdout.strip()\n```\n\n### Step 5: Detect Scanned\u002FImage-Based PDFs\n\nAfter each extraction attempt, verify text was actually extracted:\n\n```python\ndef is_meaningful_text(text, min_chars=50):\n    \"\"\"Check if extracted text is meaningful (not empty or just whitespace)\"\"\"\n    if not text:\n        return False\n    # Remove whitespace and check length\n    cleaned = ''.join(text.split())\n    return len(cleaned) >= min_chars\n```\n\n### Step 6: OCR Fallback for Scanned Documents\n\nIf all text extraction methods return empty\u002Finsufficient text, the PDF is likely scanned. Use OCR:\n\n```python\nimport pdf2image\nimport pytesseract\nfrom PIL import Image\n\ndef extract_with_ocr(pdf_path, dpi=300):\n    \"\"\"Extract text from scanned PDFs using OCR\"\"\"\n    text = \"\"\n    images = pdf2image.convert_from_path(pdf_path, dpi=dpi)\n    for image in images:\n        page_text = pytesseract.image_to_string(image)\n        text += page_text + \"\\n\"\n    return text.strip()\n```\n\n## Complete Workflow Function\n\n```python\ndef robust_pdf_extract(pdf_path):\n    \"\"\"\n    Extract text from PDF using progressive fallback methods.\n    Returns (text, method_used) tuple.\n    \"\"\"\n    methods = [\n        (\"pdfplumber\", extract_with_pdfplumber),\n        (\"pypdfium2\", extract_with_pypdfium2),\n        (\"pdftotext\", extract_with_pdftotext),\n    ]\n    \n    for method_name, extract_func in methods:\n        try:\n            text = extract_func(pdf_path)\n            if is_meaningful_text(text):\n                return text, method_name\n        except Exception as e:\n            print(f\"{method_name} failed: {e}\")\n            continue\n    \n    # All text methods failed - try OCR\n    try:\n        text = extract_with_ocr(pdf_path)\n        if is_meaningful_text(text):\n            return text, \"ocr\"\n    except Exception as e:\n        print(f\"OCR failed: {e}\")\n    \n    return \"\", \"failed\"\n```\n\n## Dependencies\n\nInstall required packages:\n\n```bash\npip install pdfplumber pypdfium2 pdf2image pytesseract pillow\n# Also need system packages:\n# apt-get install poppler-utils tesseract-ocr  # Debian\u002FUbuntu\n# brew install poppler tesseract  # macOS\n```\n\n## Best Practices\n\n1. **Log which method succeeded** - helps identify document types for future optimization\n2. **Set reasonable character thresholds** - adjust `min_chars` based on expected document content\n3. **Handle exceptions gracefully** - each method may fail for different reasons\n4. **Consider DPI for OCR** - higher DPI (300+) improves accuracy but increases processing time\n5. **Cache results** - if processing same PDFs repeatedly, store successful extraction method per file\n\n## Troubleshooting\n\n| Symptom | Likely Cause | Solution |\n|---------|--------------|----------|\n| All methods return empty | Scanned PDF | OCR fallback should handle this |\n| pdfplumber fails with permission error | File locked or permissions issue | Check file permissions with `ls -la` |\n| OCR returns gibberish | Low quality scan or wrong language | Increase DPI, specify language in pytesseract |\n| pdftotext not found | Missing poppler-utils | Install system package |",{"name":5,"description":7},"main","af1b40a42167d09c30b3a63000aa14ace4c1e229","gdpval_bench\u002Fskills\u002Frobust-pdf-extraction","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval","https:\u002F\u002Fgithub.com\u002Fxyliu-cs","https:\u002F\u002Fxyliu-cs.github.io","PhD Student in CS, CUHK-Shenzhen.","2026-04-06 20:32:15",{"source":8,"skillName":5,"commands":48,"prompt":58,"zipAvailable":59},[49,52,55],{"tool":50,"command":51},"npx","npx skills add xyliu-cs\u002FOpenSpace-GDPval --skill robust-pdf-extraction",{"tool":53,"command":54},"bunx","bunx skills add xyliu-cs\u002FOpenSpace-GDPval --skill robust-pdf-extraction",{"tool":56,"command":57},"pnpm","pnpm dlx skills add xyliu-cs\u002FOpenSpace-GDPval --skill robust-pdf-extraction","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Frobust-pdf-extraction\u002FSKILL.md",true,[61],{"path":62,"resourceType":63,"resourceTypeDesc":64,"sizeBytes":65,"sourceHtmlUrl":66},".skill_id","OTHER","其他",35,"https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Frobust-pdf-extraction\u002F.skill_id",[68,81,89,104,128,147],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":34},"01M6KG8MF1S664SWBDENYRSCK8","zip-export-deliverable","Ensures codebase deliverables are properly exported as ZIP archives through a dedicated finalization step","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fzip-export-deliverable\u002FSKILL.md",[],[75,76,77,78,79,80],"zip export deliverable","zip","export","deliverables","codebase","as",{"skillNo":82,"name":83,"nameZh":6,"description":84,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":34},"01M6KG8GAZWHHEK7VNJDW0ME21","zip-deliverable-finalization","Ensure codebase deliverables are properly packaged as ZIP exports in a dedicated final step","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fzip-deliverable-finalization\u002FSKILL.md",[],[88,76,78,79,80],"zip deliverable finalization",{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":93,"categories":94,"keywords":95,"publishedAt":34},"01M6KG8CMQQ1PYMNTSRZ9VS1MD","zero-iteration-failure-analysis","Identify and handle agent failures with 0 iterations as pre-execution system issues","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fzero-iteration-failure-analysis\u002FSKILL.md",[],[96,97,98,99,100,32,101,102,80,103],"failure analysis","ZeRO","analysis","iteration","zero iteration failure analysis","issues","execution","system",{"skillNo":105,"name":106,"nameZh":6,"description":107,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":108,"categories":109,"keywords":115,"publishedAt":34},"01M6KG86W3PA07FT9W58YHHERM","write-file-fallback-report","Generate professional documents using write_file when primary data sources fail, leveraging embedded domain knowledge instead of external retrieval","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fwrite-file-fallback-report\u002FSKILL.md",[110],{"categoryNo":111,"categoryName":112,"taxonomyType":113,"taxonomyTypeDesc":114},"01JBSEEDCAT000000000000034","行政与办公人员","PROFESSION","适用职业",[30,116,117,118,119,120,121,122,123,124,125,28,126,127],"write","file","report","write file fallback report","domain","professional","sources","retrieval","generate","embedded","data","knowledge",{"skillNo":129,"name":130,"nameZh":6,"description":131,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":132,"categories":133,"keywords":137,"publishedAt":34},"01M6KG82GAEY3GG77CMGCK1C2T","fallback-doc-with-delegation","Generate professional documents after tool failures using shell_agent for complex formats or write_file for simple text\u002Fmarkdown","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fwrite-file-fallback-report-enhanced\u002FSKILL.md",[134],{"categoryNo":135,"categoryName":136,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发",[138,32,30,139,140,141,28,124,117,142,143,144,116,145,121,146,33],"fallback doc with delegation","doc","delegation","shell","markdown","tool","text","simple","formats",{"skillNo":148,"name":149,"nameZh":6,"description":150,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":151,"categories":152,"keywords":154,"publishedAt":34},"01M6KG7WT7GX5NYCGEFHW22NV7","context-anchored-fallback-report","Generate documents with write_file when retrieval tools fail, with explicit guardrails against task context drift","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fwrite-file-fallback-report-enhanced-4bc5c2\u002FSKILL.md",[153],{"categoryNo":111,"categoryName":112,"taxonomyType":113,"taxonomyTypeDesc":114},[30,118,155,156,124,117,157,158,116,159,160,123,32,161,28],"context","context anchored fallback report","Guardrails","Tools","task","drift","context drift"]