{"data":{"slug":"github-claude-office-skills-skills-pdf-extraction-41582c619cfd","title":"Extract Text and Tables from PDFs","summary":"Extract text, tables, and metadata from PDFs using pdfplumber for precise data retrieval. The deliverable includes extracted text, tables in structured formats, and metadata such as title, author, and creation date.","url":"https:\/\/skillshunter.net\/skills\/github-claude-office-skills-skills-pdf-extraction-41582c619cfd","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-claude-office-skills-skills-pdf-extraction-41582c619cfd","markdown_url":"https:\/\/skillshunter.net\/skills\/github-claude-office-skills-skills-pdf-extraction-41582c619cfd.md","download_url":"https:\/\/skillshunter.net\/skills\/github-claude-office-skills-skills-pdf-extraction-41582c619cfd\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"Ensure the PDF is not scanned\/image-based; use OCR first if needed. Install pdfplumber via pip before running the extraction commands.","instructions":"---\n# \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n# CLAUDE OFFICE SKILL - Enhanced Metadata v2.0\n# \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n\n# Basic Information\nname: pdf-extraction\ndescription: \"Extract text, tables, and metadata from PDFs using pdfplumber\"\nversion: \"1.0\"\nauthor: claude-office-skills\nlicense: MIT\n\n# Categorization\ncategory: pdf\ntags:\n  - pdf\n  - extraction\n  - text\n  - tables\ndepartment: All\n\n# AI Model Compatibility\nmodels:\n  recommended:\n    - claude-sonnet-4\n    - claude-opus-4\n  compatible:\n    - claude-3-5-sonnet\n    - gpt-4\n    - gpt-4o\n\n# MCP Tools Integration\nmcp:\n  server: office-mcp\n  tools:\n    - extract_text_from_pdf\n    - extract_tables_from_pdf\n\n# Skill Capabilities\ncapabilities:\n  - text_extraction\n  - table_extraction\n  - data_mining\n\n# Language Support\nlanguages:\n  - en\n  - zh\n---\n\n# PDF Extraction Skill\n\n## Overview\n\nThis skill enables precise extraction of text, tables, and metadata from PDF documents using **pdfplumber** - the go-to library for PDF data extraction. Unlike basic PDF readers, pdfplumber provides detailed character-level positioning, accurate table detection, and visual debugging.\n\n## How to Use\n\n1. Provide the PDF file you want to extract from\n2. Specify what you need: text, tables, images, or metadata\n3. I'll generate pdfplumber code and execute it\n\n**Example prompts:**\n- \"Extract all tables from this financial report\"\n- \"Get text from pages 5-10 of this document\"\n- \"Find and extract the invoice total from this PDF\"\n- \"Convert this PDF table to CSV\/Excel\"\n\n## Domain Knowledge\n\n### pdfplumber Fundamentals\n\n```python\nimport pdfplumber\n\n# Open PDF\nwith pdfplumber.open('document.pdf') as pdf:\n    # Access pages\n    first_page = pdf.pages[0]\n    \n    # Document metadata\n    print(pdf.metadata)\n    \n    # Number of pages\n    print(len(pdf.pages))\n```\n\n### PDF Structure\n```\nPDF Document\n\u251c\u2500\u2500 metadata (title, author, creation date)\n\u251c\u2500\u2500 pages[]\n\u2502   \u251c\u2500\u2500 chars (individual characters with position)\n\u2502   \u251c\u2500\u2500 words (grouped characters)\n\u2502   \u251c\u2500\u2500 lines (horizontal\/vertical lines)\n\u2502   \u251c\u2500\u2500 rects (rectangles)\n\u2502   \u251c\u2500\u2500 curves (bezier curves)\n\u2502   \u2514\u2500\u2500 images (embedded images)\n\u2514\u2500\u2500 outline (bookmarks\/TOC)\n```\n\n### Text Extraction\n\n#### Basic Text\n```python\nwith pdfplumber.open('document.pdf') as pdf:\n    # Single page\n    text = pdf.pages[0].extract_text()\n    \n    # All pages\n    full_text = ''\n    for page in pdf.pages:\n        full_text += page.extract_text() or ''\n```\n\n#### Advanced Text Options\n```python\n# With layout preservation\ntext = page.extract_text(\n    x_tolerance=3,      # Horizontal tolerance for grouping\n    y_tolerance=3,      # Vertical tolerance\n    layout=True,        # Preserve layout\n    x_density=7.25,     # Chars per unit width\n    y_density=13        # Chars per unit height\n)\n\n# Extract words with positions\nwords = page.extract_words(\n    x_tolerance=3,\n    y_tolerance=3,\n    keep_blank_chars=False,\n    use_text_flow=False\n)\n\n# Each word includes: text, x0, top, x1, bottom, etc.\nfor word in words:\n    print(f\"{word['text']} at ({word['x0']}, {word['top']})\")\n```\n\n#### Character-Level Access\n```python\n# Get all characters\nchars = page.chars\n\nfor char in chars:\n    print(f\"'{char['text']}' at ({char['x0']}, {char['top']})\")\n    print(f\"  Font: {char['fontname']}, Size: {char['size']}\")\n```\n\n### Table Extraction\n\n#### Basic Table Extraction\n```python\nwith pdfplumber.open('report.pdf') as pdf:\n    page = pdf.pages[0]\n    \n    # Extract all tables\n    tables = page.extract_tables()\n    \n    for i, table in enumerate(tables):\n        print(f\"Table {i+1}:\")\n        for row in table:\n            print(row)\n```\n\n#### Advanced Table Settings\n```python\n# Custom table detection\ntable_settings = {\n    \"vertical_strategy\": \"lines\",      # or \"text\", \"explicit\"\n    \"horizontal_strategy\": \"lines\",\n    \"explicit_vertical_lines\": [],     # Custom line positions\n    \"explicit_horizontal_lines\": [],\n    \"snap_tolerance\": 3,\n    \"snap_x_tolerance\": 3,\n    \"snap_y_tolerance\": 3,\n    \"join_tolerance\": 3,\n    \"edge_min_length\": 3,\n    \"min_words_vertical\": 3,\n    \"min_words_horizontal\": 1,\n    \"intersection_tolerance\": 3,\n    \"text_tolerance\": 3,\n    \"text_x_tolerance\": 3,\n    \"text_y_tolerance\": 3,\n}\n\ntables = page.extract_tables(table_settings)\n```\n\n#### Table Finding\n```python\n# Find tables (without extracting)\ntable_finder = page.find_tables()\n\nfor table in table_finder:\n    print(f\"Table at: {table.bbox}\")  # (x0, top, x1, bottom)\n    \n    # Extract specific table\n    data = table.extract()\n```\n\n### Visual Debugging\n\n```python\n# Create visual debug image\nim = page.to_image(resolution=150)\n\n# Draw detected objects\nim.draw_rects(page.chars)        # Character bounding boxes\nim.draw_rects(page.words)        # Word bounding boxes\nim.draw_lines(page.lines)        # Lines\nim.draw_rects(page.rects)        # Rectangles\n\n# Save debug image\nim.save('debug.png')\n\n# Debug tables\nim.reset()\nim.debug_tablefinder()\nim.save('table_debug.png')\n```\n\n### Cropping and Filtering\n\n#### Crop to Region\n```python\n# Define bounding box (x0, top, x1, bottom)\nbbox = (0, 0, 300, 200)\n\n# Crop page\ncropped = page.crop(bbox)\n\n# Extract from cropped area\ntext = cropped.extract_text()\ntables = cropped.extract_tables()\n```\n\n#### Filter by Position\n```python\n# Filter characters by region\ndef within_bbox(obj, bbox):\n    x0, top, x1, bottom = bbox\n    return (obj['x0'] >= x0 and obj['x1'] <= x1 and\n            obj['top'] >= top and obj['bottom'] <= bottom)\n\nbbox = (100, 100, 400, 300)\nfiltered_chars = [c for c in page.chars if within_bbox(c, bbox)]\n```\n\n#### Filter by Font\n```python\n# Get text by font\ndef extract_by_font(page, font_name):\n    chars = [c for c in page.chars if font_name in c['fontname']]\n    return ''.join(c['text'] for c in chars)\n\n# Extract bold text (often \"Bold\" in font name)\nbold_text = extract_by_font(page, 'Bold')\n\n# Extract by size\nlarge_chars = [c for c in page.chars if c['size'] > 14]\n```\n\n### Metadata and Structure\n\n```python\nwith pdfplumber.open('document.pdf') as pdf:\n    # Document metadata\n    meta = pdf.metadata\n    print(f\"Title: {meta.get('Title')}\")\n    print(f\"Author: {meta.get('Author')}\")\n    print(f\"Created: {meta.get('CreationDate')}\")\n    \n    # Page info\n    for i, page in enumerate(pdf.pages):\n        print(f\"Page {i+1}: {page.width} x {page.height}\")\n        print(f\"  Rotation: {page.rotation}\")\n```\n\n## Best Practices\n\n1. **Debug Visually**: Use `to_image()` to understand PDF structure\n2. **Tune Table Settings**: Adjust tolerances for your specific PDF\n3. **Handle Scanned PDFs**: Use OCR first (this skill is for native text)\n4. **Process Page by Page**: For large PDFs, avoid loading all at once\n5. **Check for Text**: Some PDFs are images - verify text exists\n\n## Common Patterns\n\n### Extract All Tables to DataFrames\n```python\nimport pandas as pd\n\ndef pdf_tables_to_dataframes(pdf_path):\n    \"\"\"Extract all tables from PDF as pandas DataFrames.\"\"\"\n    dfs = []\n    \n    with pdfplumber.open(pdf_path) as pdf:\n        for i, page in enumerate(pdf.pages):\n            tables = page.extract_tables()\n            \n            for j, table in enumerate(tables):\n                if table and len(table) > 1:\n                    # First row as header\n                    df = pd.DataFrame(table[1:], columns=table[0])\n                    df['_page'] = i + 1\n                    df['_table'] = j + 1\n                    dfs.append(df)\n    \n    return dfs\n```\n\n### Extract Specific Region\n```python\ndef extract_invoice_amount(pdf_path):\n    \"\"\"Extract amount from typical invoice layout.\"\"\"\n    with pdfplumber.open(pdf_path) as pdf:\n        page = pdf.pages[0]\n        \n        # Search for \"Total\" and get nearby numbers\n        words = page.extract_words()\n        \n        for i, word in enumerate(words):\n            if 'total' in word['text'].lower():\n                # Look at next few words\n                for next_word in words[i+1:i+5]:\n                    text = next_word['text'].replace(',', '').replace('$', '')\n                    try:\n                        return float(text)\n                    except ValueError:\n                        continue\n    \n    return None\n```\n\n### Multi-column Layout\n```python\ndef extract_columns(page, num_columns=2):\n    \"\"\"Extract text from multi-column layout.\"\"\"\n    width = page.width\n    col_width = width \/ num_columns\n    \n    columns = []\n    for i in range(num_columns):\n        x0 = i * col_width\n        x1 = (i + 1) * col_width\n        \n        cropped = page.crop((x0, 0, x1, page.height))\n        columns.append(cropped.extract_text())\n    \n    return columns\n```\n\n## Examples\n\n### Example 1: Financial Report Table Extraction\n```python\nimport pdfplumber\nimport pandas as pd\n\ndef extract_financial_tables(pdf_path):\n    \"\"\"Extract tables from financial report and save to Excel.\"\"\"\n    \n    with pdfplumber.open(pdf_path) as pdf:\n        all_tables = []\n        \n        for page_num, page in enumerate(pdf.pages):\n            # Debug: save table visualization\n            im = page.to_image()\n            im.debug_tablefinder()\n            im.save(f'debug_page_{page_num+1}.png')\n            \n            # Extract tables\n            tables = page.extract_tables({\n                \"vertical_strategy\": \"lines\",\n                \"horizontal_strategy\": \"lines\",\n                \"snap_tolerance\": 5,\n            })\n            \n            for table in tables:\n                if table and len(table) > 1:\n                    # Clean data\n                    clean_table = []\n                    for row in table:\n                        clean_row = [cell.strip() if cell else '' for cell in row]\n                        clean_table.append(clean_row)\n                    \n                    df = pd.DataFrame(clean_table[1:], columns=clean_table[0])\n                    df['Source Page'] = page_num + 1\n                    all_tables.append(df)\n        \n        # Save to Excel with multiple sheets\n        with pd.ExcelWriter('extracted_tables.xlsx') as writer:\n            for i, df in enumerate(all_tables):\n                df.to_excel(writer, sheet_name=f'Table_{i+1}', index=False)\n        \n        return all_tables\n\ntables = extract_financial_tables('annual_report.pdf')\nprint(f\"Extracted {len(tables)} tables\")\n```\n\n### Example 2: Invoice Data Extraction\n```python\nimport pdfplumber\nimport re\nfrom datetime import datetime\n\ndef extract_invoice_data(pdf_path):\n    \"\"\"Extract structured data from invoice PDF.\"\"\"\n    \n    data = {\n        'invoice_number': None,\n        'date': None,\n        'total': None,\n        'line_items': []\n    }\n    \n    with pdfplumber.open(pdf_path) as pdf:\n        page = pdf.pages[0]\n        text = page.extract_text()\n        \n        # Extract invoice number\n        inv_match = re.search(r'Invoice\\s*#?\\s*:?\\s*(\\w+)', text, re.IGNORECASE)\n        if inv_match:\n            data['invoice_number'] = inv_match.group(1)\n        \n        # Extract date\n        date_match = re.search(r'Date\\s*:?\\s*(\\d{1,2}[\/-]\\d{1,2}[\/-]\\d{2,4})', text)\n        if date_match:\n            data['date'] = date_match.group(1)\n        \n        # Extract total\n        total_match = re.search(r'Total\\s*:?\\s*\\$?([\\d,]+\\.?\\d*)', text, re.IGNORECASE)\n        if total_match:\n            data['total'] = float(total_match.group(1).replace(',', ''))\n        \n        # Extract line items from table\n        tables = page.extract_tables()\n        for table in tables:\n            if table and any('description' in str(row).lower() for row in table[:2]):\n                # Found line items table\n                for row in table[1:]:  # Skip header\n                    if row and len(row) >= 3:\n                        data['line_items'].append({\n                            'description': row[0],\n                            'quantity': row[1] if len(row) > 1 else None,\n                            'amount': row[-1]\n                        })\n    \n    return data\n\ninvoice = extract_invoice_data('invoice.pdf')\nprint(f\"Invoice #{invoice['invoice_number']}\")\nprint(f\"Total: ${invoice['total']}\")\n```\n\n### Example 3: Resume\/CV Parser\n```python\nimport pdfplumber\n\ndef parse_resume(pdf_path):\n    \"\"\"Extract structured sections from resume.\"\"\"\n    \n    with pdfplumber.open(pdf_path) as pdf:\n        full_text = ''\n        for page in pdf.pages:\n            full_text += (page.extract_text() or '') + '\\n'\n        \n        # Common resume sections\n        sections = {\n            'contact': '',\n            'summary': '',\n            'experience': '',\n            'education': '',\n            'skills': ''\n        }\n        \n        # Split by common headers\n        import re\n        section_patterns = {\n            'summary': r'(summary|objective|profile)',\n            'experience': r'(experience|employment|work history)',\n            'education': r'(education|academic)',\n            'skills': r'(skills|competencies|technical)'\n        }\n        \n        lines = full_text.split('\\n')\n        current_section = 'contact'\n        \n        for line in lines:\n            line_lower = line.lower().strip()\n            \n            # Check if line is a section header\n            for section, pattern in section_patterns.items():\n                if re.match(pattern, line_lower):\n                    current_section = section\n                    break\n            \n            sections[current_section] += line + '\\n'\n        \n        return sections\n\nresume = parse_resume('resume.pdf')\nprint(\"Skills:\", resume['skills'])\n```\n\n## Limitations\n\n- Cannot extract from scanned\/image PDFs (use OCR first)\n- Complex layouts may need manual tuning\n- Some PDF encryption types not supported\n- Embedded fonts may affect text extraction\n- No direct PDF editing capability\n\n## Installation\n\n```bash\npip install pdfplumber\n\n# For image debugging (optional)\npip install Pillow\n```\n\n## Resources\n\n- [pdfplumber Documentation](https:\/\/github.com\/jsvine\/pdfplumber)\n- [Table Extraction Guide](https:\/\/github.com\/jsvine\/pdfplumber#extracting-tables)\n- [Visual Debugging](https:\/\/github.com\/jsvine\/pdfplumber#visual-debugging)\n","use_cases":["Extract all tables from a financial report","Get text from specific pages of a document","Find and extract invoice totals from a PDF","Convert a PDF table to CSV or Excel format"],"limitations":[],"compatibility":[],"setup_tip":"```bash\npip install pdfplumber\n\n# For image debugging (optional)\npip install Pillow\n```","sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/claude-office-skills\/skills\/blob\/9c4c7d5cd2813a8936bf2c9fdb174ea883b85a11\/pdf-extraction\/SKILL.md","source_commit":"9c4c7d5cd2813a8936bf2c9fdb174ea883b85a11","license":"MIT","version":null,"listing_approved_at":"2026-11-22","created_at":"2026-11-21T14:43:34.000000Z","updated_at":"2026-11-22T11:18:09.000000Z","seo_title":"Extract Text and Tables from PDFs","seo_description":"Extract text, tables, and metadata from PDFs using pdfplumber for precise data retrieval. Supports text and table extraction, metadata retrieval, and conversion to CSV or","seo_keywords":["extract text from PDF","extract tables from PDF","PDF metadata extraction","convert PDF table to CSV","PDF data extraction"]}}