{"data":{"slug":"github-claude-office-skills-skills-table-extractor-1413f3114e70","title":"Extract Tables from PDF Documents","summary":"Extract tables from PDFs using camelot, supporting lattice and stream methods for bordered and borderless tables. Deliverables include structured data such as CSV, Excel, JSON, or HTML formats.","url":"https:\/\/skillshunter.net\/skills\/github-claude-office-skills-skills-table-extractor-1413f3114e70","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-claude-office-skills-skills-table-extractor-1413f3114e70","markdown_url":"https:\/\/skillshunter.net\/skills\/github-claude-office-skills-skills-table-extractor-1413f3114e70.md","download_url":"https:\/\/skillshunter.net\/skills\/github-claude-office-skills-skills-table-extractor-1413f3114e70\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"Ensure the PDF is not encrypted and is text-based, not image-based. For image-based PDFs, OCR preprocessing is required. For complex tables with merged cells or rotated layouts, preprocessing may be necessary.","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: table-extractor\ndescription: \">\"\nversion: \"1.0\"\nauthor: claude-office-skills\nlicense: MIT\n\n# Categorization\ncategory: parsing\ntags:\n  - table\n  - extraction\n  - pdf\n  - camelot\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_tables_from_pdf\n\n# Skill Capabilities\ncapabilities:\n  - table_extraction\n  - data_structuring\n\n# Language Support\nlanguages:\n  - en\n  - zh\n---\n\n# Table Extractor Skill\n\n## Overview\n\nThis skill enables precise extraction of tables from PDF documents using **camelot** - the gold standard for PDF table extraction. Handle complex tables with merged cells, borderless tables, and multi-page layouts with high accuracy.\n\n## How to Use\n\n1. Provide the PDF containing tables\n2. Optionally specify pages or table detection method\n3. I'll extract tables as pandas DataFrames\n\n**Example prompts:**\n- \"Extract all tables from this PDF\"\n- \"Get the table on page 5 of this report\"\n- \"Extract borderless tables from this document\"\n- \"Convert PDF tables to Excel format\"\n\n## Domain Knowledge\n\n### camelot Fundamentals\n\n```python\nimport camelot\n\n# Extract tables from PDF\ntables = camelot.read_pdf('document.pdf')\n\n# Access results\nprint(f\"Found {len(tables)} tables\")\n\n# Get first table as DataFrame\ndf = tables[0].df\nprint(df)\n```\n\n### Extraction Methods\n\n| Method | Use Case | Description |\n|--------|----------|-------------|\n| `lattice` | Bordered tables | Detects table by lines\/borders |\n| `stream` | Borderless tables | Uses text positioning |\n\n```python\n# Lattice method (default) - for tables with visible borders\ntables = camelot.read_pdf('document.pdf', flavor='lattice')\n\n# Stream method - for borderless tables\ntables = camelot.read_pdf('document.pdf', flavor='stream')\n```\n\n### Page Selection\n\n```python\n# Single page\ntables = camelot.read_pdf('document.pdf', pages='1')\n\n# Multiple pages\ntables = camelot.read_pdf('document.pdf', pages='1,3,5')\n\n# Page range\ntables = camelot.read_pdf('document.pdf', pages='1-5')\n\n# All pages\ntables = camelot.read_pdf('document.pdf', pages='all')\n```\n\n### Advanced Options\n\n#### Lattice Options\n```python\ntables = camelot.read_pdf(\n    'document.pdf',\n    flavor='lattice',\n    line_scale=40,              # Line detection sensitivity\n    copy_text=['h', 'v'],       # Copy text across merged cells\n    shift_text=['l', 't'],      # Shift text alignment\n    split_text=True,            # Split text at newlines\n    flag_size=True,             # Flag super\/subscripts\n    strip_text='\\n',            # Characters to strip\n    process_background=False,   # Process background lines\n)\n```\n\n#### Stream Options\n```python\ntables = camelot.read_pdf(\n    'document.pdf',\n    flavor='stream',\n    edge_tol=500,               # Edge tolerance\n    row_tol=10,                 # Row tolerance\n    column_tol=0,               # Column tolerance\n    strip_text='\\n',            # Characters to strip\n)\n```\n\n### Table Area Specification\n\n```python\n# Extract from specific area (x1, y1, x2, y2)\n# Coordinates from bottom-left, in PDF points (72 points = 1 inch)\ntables = camelot.read_pdf(\n    'document.pdf',\n    table_areas=['72,720,540,400'],  # One area\n)\n\n# Multiple areas\ntables = camelot.read_pdf(\n    'document.pdf',\n    table_areas=['72,720,540,400', '72,380,540,200'],\n)\n```\n\n### Column Specification\n\n```python\n# Manually specify column positions (for stream method)\ntables = camelot.read_pdf(\n    'document.pdf',\n    flavor='stream',\n    columns=['100,200,300,400'],  # X positions of column separators\n)\n```\n\n### Working with Results\n\n```python\nimport camelot\n\ntables = camelot.read_pdf('document.pdf')\n\nfor i, table in enumerate(tables):\n    # Access DataFrame\n    df = table.df\n    \n    # Table metadata\n    print(f\"Table {i+1}:\")\n    print(f\"  Page: {table.page}\")\n    print(f\"  Accuracy: {table.accuracy}\")\n    print(f\"  Whitespace: {table.whitespace}\")\n    print(f\"  Order: {table.order}\")\n    print(f\"  Shape: {df.shape}\")\n    \n    # Parsing report\n    report = table.parsing_report\n    print(f\"  Report: {report}\")\n```\n\n### Export Options\n\n```python\nimport camelot\n\ntables = camelot.read_pdf('document.pdf')\n\n# Export to CSV\ntables[0].to_csv('table.csv')\n\n# Export to Excel\ntables[0].to_excel('table.xlsx')\n\n# Export to JSON\ntables[0].to_json('table.json')\n\n# Export to HTML\ntables[0].to_html('table.html')\n\n# Export all tables\nfor i, table in enumerate(tables):\n    table.to_excel(f'table_{i+1}.xlsx')\n```\n\n### Visual Debugging\n\n```python\nimport camelot\n\n# Enable visual debugging\ntables = camelot.read_pdf('document.pdf')\n\n# Plot detected table areas\ncamelot.plot(tables[0], kind='contour').show()\n\n# Plot text on table\ncamelot.plot(tables[0], kind='text').show()\n\n# Plot detected lines (lattice only)\ncamelot.plot(tables[0], kind='joint').show()\ncamelot.plot(tables[0], kind='line').show()\n\n# Save plot\nfig = camelot.plot(tables[0])\nfig.savefig('debug.png')\n```\n\n### Handling Multi-page Tables\n\n```python\nimport camelot\nimport pandas as pd\n\ndef extract_multipage_table(pdf_path, pages='all'):\n    \"\"\"Extract and combine tables that span multiple pages.\"\"\"\n    \n    tables = camelot.read_pdf(pdf_path, pages=pages)\n    \n    # Group tables by similar structure (columns)\n    table_groups = {}\n    \n    for table in tables:\n        cols = tuple(table.df.columns)\n        if cols not in table_groups:\n            table_groups[cols] = []\n        table_groups[cols].append(table.df)\n    \n    # Combine similar tables\n    combined = []\n    for cols, dfs in table_groups.items():\n        if len(dfs) > 1:\n            # Combine and deduplicate header rows\n            combined_df = pd.concat(dfs, ignore_index=True)\n            combined.append(combined_df)\n        else:\n            combined.append(dfs[0])\n    \n    return combined\n```\n\n## Best Practices\n\n1. **Try Both Methods**: Lattice for bordered, stream for borderless\n2. **Check Accuracy Score**: Above 90% is usually good\n3. **Use Visual Debugging**: Understand extraction results\n4. **Specify Areas**: For PDFs with multiple table types\n5. **Handle Headers**: First row often needs special treatment\n\n## Common Patterns\n\n### Batch Table Extraction\n```python\nimport camelot\nfrom pathlib import Path\nimport pandas as pd\n\ndef batch_extract_tables(input_dir, output_dir):\n    \"\"\"Extract tables from all PDFs in directory.\"\"\"\n    \n    input_path = Path(input_dir)\n    output_path = Path(output_dir)\n    output_path.mkdir(exist_ok=True)\n    \n    results = []\n    \n    for pdf_file in input_path.glob('*.pdf'):\n        try:\n            tables = camelot.read_pdf(str(pdf_file), pages='all')\n            \n            for i, table in enumerate(tables):\n                # Skip low accuracy tables\n                if table.accuracy < 80:\n                    continue\n                \n                output_file = output_path \/ f\"{pdf_file.stem}_table_{i+1}.xlsx\"\n                table.to_excel(str(output_file))\n                \n                results.append({\n                    'source': str(pdf_file),\n                    'table': i + 1,\n                    'page': table.page,\n                    'accuracy': table.accuracy,\n                    'output': str(output_file)\n                })\n        \n        except Exception as e:\n            results.append({\n                'source': str(pdf_file),\n                'error': str(e)\n            })\n    \n    return results\n```\n\n### Auto-detect Table Method\n```python\nimport camelot\n\ndef smart_extract_tables(pdf_path, pages='1'):\n    \"\"\"Try both methods and return best results.\"\"\"\n    \n    # Try lattice first\n    lattice_tables = camelot.read_pdf(pdf_path, pages=pages, flavor='lattice')\n    \n    # Try stream\n    stream_tables = camelot.read_pdf(pdf_path, pages=pages, flavor='stream')\n    \n    # Compare and return best\n    results = []\n    \n    if lattice_tables and lattice_tables[0].accuracy > 70:\n        results.extend(lattice_tables)\n    elif stream_tables:\n        results.extend(stream_tables)\n    \n    return results\n```\n\n## Examples\n\n### Example 1: Financial Statement Extraction\n```python\nimport camelot\nimport pandas as pd\n\ndef extract_financial_tables(pdf_path):\n    \"\"\"Extract financial tables from annual report.\"\"\"\n    \n    # Extract all tables\n    tables = camelot.read_pdf(pdf_path, pages='all', flavor='lattice')\n    \n    financial_data = {\n        'income_statement': None,\n        'balance_sheet': None,\n        'cash_flow': None,\n        'other_tables': []\n    }\n    \n    for table in tables:\n        df = table.df\n        text = df.to_string().lower()\n        \n        # Identify table type\n        if 'revenue' in text or 'sales' in text:\n            if 'operating income' in text or 'net income' in text:\n                financial_data['income_statement'] = df\n        elif 'asset' in text and 'liabilities' in text:\n            financial_data['balance_sheet'] = df\n        elif 'cash flow' in text or 'operating activities' in text:\n            financial_data['cash_flow'] = df\n        else:\n            financial_data['other_tables'].append({\n                'page': table.page,\n                'data': df,\n                'accuracy': table.accuracy\n            })\n    \n    return financial_data\n\nfinancials = extract_financial_tables('annual_report.pdf')\nif financials['income_statement'] is not None:\n    print(\"Income Statement found:\")\n    print(financials['income_statement'])\n```\n\n### Example 2: Scientific Data Extraction\n```python\nimport camelot\nimport pandas as pd\n\ndef extract_research_data(pdf_path, pages='all'):\n    \"\"\"Extract data tables from research paper.\"\"\"\n    \n    # Try lattice for bordered tables\n    tables = camelot.read_pdf(pdf_path, pages=pages, flavor='lattice')\n    \n    if not tables or all(t.accuracy < 70 for t in tables):\n        # Fall back to stream for borderless\n        tables = camelot.read_pdf(pdf_path, pages=pages, flavor='stream')\n    \n    extracted_data = []\n    \n    for table in tables:\n        df = table.df\n        \n        # Clean up the DataFrame\n        # Set first row as header if it looks like one\n        if not df.iloc[0].str.contains(r'\\d').any():\n            df.columns = df.iloc[0]\n            df = df[1:]\n            df = df.reset_index(drop=True)\n        \n        extracted_data.append({\n            'page': table.page,\n            'accuracy': table.accuracy,\n            'data': df\n        })\n    \n    return extracted_data\n\ndata = extract_research_data('research_paper.pdf')\nfor i, item in enumerate(data):\n    print(f\"Table {i+1} (Page {item['page']}, Accuracy: {item['accuracy']}%):\")\n    print(item['data'].head())\n```\n\n### Example 3: Invoice Line Items\n```python\nimport camelot\n\ndef extract_invoice_items(pdf_path):\n    \"\"\"Extract line items from invoice.\"\"\"\n    \n    # Usually invoices have bordered tables\n    tables = camelot.read_pdf(pdf_path, flavor='lattice')\n    \n    line_items = []\n    \n    for table in tables:\n        df = table.df\n        \n        # Look for table with typical invoice columns\n        header_text = ' '.join(df.iloc[0].astype(str)).lower()\n        \n        if any(term in header_text for term in ['quantity', 'qty', 'amount', 'price', 'description']):\n            # This looks like a line items table\n            df.columns = df.iloc[0]\n            df = df[1:]\n            \n            for _, row in df.iterrows():\n                item = {}\n                for col in df.columns:\n                    col_lower = str(col).lower()\n                    value = row[col]\n                    \n                    if 'desc' in col_lower or 'item' in col_lower:\n                        item['description'] = value\n                    elif 'qty' in col_lower or 'quantity' in col_lower:\n                        item['quantity'] = value\n                    elif 'price' in col_lower or 'rate' in col_lower:\n                        item['unit_price'] = value\n                    elif 'amount' in col_lower or 'total' in col_lower:\n                        item['amount'] = value\n                \n                if item:\n                    line_items.append(item)\n    \n    return line_items\n\nitems = extract_invoice_items('invoice.pdf')\nfor item in items:\n    print(item)\n```\n\n### Example 4: Table Comparison\n```python\nimport camelot\nimport pandas as pd\n\ndef compare_pdf_tables(pdf1_path, pdf2_path):\n    \"\"\"Compare tables between two PDF versions.\"\"\"\n    \n    tables1 = camelot.read_pdf(pdf1_path)\n    tables2 = camelot.read_pdf(pdf2_path)\n    \n    comparisons = []\n    \n    # Match tables by shape and position\n    for t1 in tables1:\n        best_match = None\n        best_score = 0\n        \n        for t2 in tables2:\n            if t1.df.shape == t2.df.shape:\n                # Calculate similarity\n                try:\n                    similarity = (t1.df == t2.df).mean().mean()\n                    if similarity > best_score:\n                        best_score = similarity\n                        best_match = t2\n                except:\n                    pass\n        \n        if best_match:\n            comparisons.append({\n                'page1': t1.page,\n                'page2': best_match.page,\n                'similarity': best_score,\n                'identical': best_score == 1.0,\n                'diff': pd.DataFrame(t1.df != best_match.df)\n            })\n    \n    return comparisons\n\ncomparison = compare_pdf_tables('report_v1.pdf', 'report_v2.pdf')\n```\n\n## Limitations\n\n- Encrypted PDFs not supported\n- Image-based PDFs need OCR preprocessing\n- Very complex merged cells may need tuning\n- Rotated tables require preprocessing\n- Large PDFs may need page-by-page processing\n\n## Installation\n\n```bash\npip install camelot-py[cv]\n\n# Additional dependencies\n# macOS\nbrew install ghostscript tcl-tk\n\n# Ubuntu\napt-get install ghostscript python3-tk\n```\n\n## Resources\n\n- [camelot Documentation](https:\/\/camelot-py.readthedocs.io\/)\n- [GitHub Repository](https:\/\/github.com\/camelot-dev\/camelot)\n- [Comparison with Other Tools](https:\/\/camelot-py.readthedocs.io\/en\/master\/user\/intro.html#why-camelot)\n","use_cases":["Extract all tables from a PDF report","Get specific tables from designated pages","Convert borderless tables to structured data","Export extracted tables to CSV, Excel, JSON, or HTML formats"],"limitations":[],"compatibility":[],"setup_tip":"```bash\npip install camelot-py[cv]\n\n# Additional dependencies\n# macOS\nbrew install ghostscript tcl-tk\n\n# Ubuntu\napt-get install ghostscript python3-tk\n```","sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/claude-office-skills\/skills\/blob\/9c4c7d5cd2813a8936bf2c9fdb174ea883b85a11\/table-extractor\/SKILL.md","source_commit":"9c4c7d5cd2813a8936bf2c9fdb174ea883b85a11","license":"MIT","version":null,"listing_approved_at":"2026-11-22","created_at":"2026-11-21T15:20:23.000000Z","updated_at":"2026-11-22T11:18:24.000000Z","seo_title":"Extract Tables from PDFs with Camelot","seo_description":"Accurately extract tables from PDF documents using camelot. Supports lattice and stream methods for bordered and borderless tables.","seo_keywords":["extract tables from PDF","camelot table extraction","borderless table extraction","PDF to CSV converter","PDF to Excel converter"]}}