Home
cd ../playbooks
File OrganizationBeginner

PDF Text & Table Extractor

Extract text, tables, and metadata from PDFs using pdfplumber

10 minutes
By communitySource
#pdf#extraction#text#tables

The data you need is trapped in a 200-page PDF. Copy-paste gives you garbled text, the tables lose their structure, and the numbers end up in the wrong columns. You need the data in a spreadsheet but the PDF was designed for printing, not for data extraction.

Who it's for: data analysts extracting structured data from PDF reports, finance teams pulling numbers from PDF financial statements, researchers extracting tables from published papers, operations teams processing PDF invoices and purchase orders, anyone who regularly needs to get usable data out of PDF documents

Example

"Extract all tables from this 80-page annual report" → Clean CSV files for each table, full text extraction with page numbers preserved, document metadata, and a summary showing 23 tables extracted across 4 sections with column headers intact

CLAUDE.md Template

New here? 3-minute setup guide → | Already set up? Copy the template below.

Or install from your terminal:
npx ccplaybooks add pdf-extraction
# PDF Extraction

## Overview

This workflow 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.

## How to Use

1. Provide the PDF file you want to extract from
2. Specify what you need: text, tables, images, or metadata
3. I'll generate pdfplumber code and execute it

Get new playbooks like this one

One email a week with new Claude Code workflows. Free, like everything here.

No spam. Unsubscribe anytime.

README.md

What This Does

This workflow 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.


Quick Start

Step 1: Create a Project Folder

mkdir -p ~/Documents/PdfExtraction

Step 2: Download the Template

Click Download above, then:

mv ~/Downloads/CLAUDE.md ~/Documents/PdfExtraction/

Step 3: Start Working

cd ~/Documents/PdfExtraction
claude

How to Use

  1. Provide the PDF file you want to extract from
  2. Specify what you need: text, tables, images, or metadata
  3. I'll generate pdfplumber code and execute it

Example prompts:

  • "Extract all tables from this financial report"
  • "Get text from pages 5-10 of this document"
  • "Find and extract the invoice total from this PDF"
  • "Convert this PDF table to CSV/Excel"

Best Practices

  1. Debug Visually: Use to_image() to understand PDF structure
  2. Tune Table Settings: Adjust tolerances for your specific PDF
  3. Handle Scanned PDFs: Use OCR first (this workflow is for native text)
  4. Process Page by Page: For large PDFs, avoid loading all at once
  5. Check for Text: Some PDFs are images - verify text exists

Examples

Example 1: Financial Report Table Extraction

import pdfplumber
import pandas as pd

def extract_financial_tables(pdf_path):
    """Extract tables from financial report and save to Excel."""
    
    with pdfplumber.open(pdf_path) as pdf:
        all_tables = []
        
        for page_num, page in enumerate(pdf.pages):
            # Debug: save table visualization
            im = page.to_image()
            im.debug_tablefinder()
            im.save(f'debug_page_{page_num+1}.png')
            
            # Extract tables
            tables = page.extract_tables({
                "vertical_strategy": "lines",
                "horizontal_strategy": "lines",
                "snap_tolerance": 5,
            })
            
            for table in tables:
                if table and len(table) > 1:
                    # Clean data
                    clean_table = []
                    for row in table:
                        clean_row = [cell.strip() if cell else '' for cell in row]
                        clean_table.append(clean_row)
                    
                    df = pd.DataFrame(clean_table[1:], columns=clean_table[0])
                    df['Source Page'] = page_num + 1
                    all_tables.append(df)
        
        # Save to Excel with multiple sheets
        with pd.ExcelWriter('extracted_tables.xlsx') as writer:
            for i, df in enumerate(all_tables):
                df.to_excel(writer, sheet_name=f'Table_{i+1}', index=False)
        
        return all_tables

tables = extract_financial_tables('annual_report.pdf')
print(f"Extracted {len(tables)} tables")

Example 2: Invoice Data Extraction

import pdfplumber
import re
from datetime import datetime

def extract_invoice_data(pdf_path):
    """Extract structured data from invoice PDF."""
    
    data = {
        'invoice_number': None,
        'date': None,
        'total': None,
        'line_items': []
    }
    
    with pdfplumber.open(pdf_path) as pdf:
        page = pdf.pages[0]
        text = page.extract_text()
        
        # Extract invoice number
        inv_match = re.search(r'Invoice\s*#?\s*:?\s*(\w+)', text, re.IGNORECASE)
        if inv_match:
            data['invoice_number'] = inv_match.group(1)
        
        # Extract date
        date_match = re.search(r'Date\s*:?\s*(\d{1,2}[/-]\d{1,2}[/-]\d{2,4})', text)
        if date_match:
            data['date'] = date_match.group(1)
        
        # Extract total
        total_match = re.search(r'Total\s*:?\s*\$?([\d,]+\.?\d*)', text, re.IGNORECASE)
        if total_match:
            data['total'] = float(total_match.group(1).replace(',', ''))
        
        # Extract line items from table
        tables = page.extract_tables()
        for table in tables:
            if table and any('description' in str(row).lower() for row in table[:2]):
                # Found line items table
                for row in table[1:]:  # Skip header
                    if row and len(row) >= 3:
                        data['line_items'].append({
                            'description': row[0],
                            'quantity': row[1] if len(row) > 1 else None,
                            'amount': row[-1]
                        })
    
    return data

invoice = extract_invoice_data('invoice.pdf')
print(f"Invoice #{invoice['invoice_number']}")
print(f"Total: ${invoice['total']}")

Example 3: Resume/CV Parser

Limitations

  • Cannot extract from scanned/image PDFs (use OCR first)
  • Complex layouts may need manual tuning
  • Some PDF encryption types not supported
  • Embedded fonts may affect text extraction
  • No direct PDF editing capability

Installation

pip install pdfplumber

# For image debugging (optional)
pip install Pillow

$Related Playbooks

File Organization

PDF Form Auto-Filler

Fill out PDF forms programmatically and extract form data

10 minutes
Advanced
File Organization

PDF Merge & Split Tool

Combine multiple PDFs or split into separate files

10 minutes
Intermediate
File Organization

PDF OCR Scanner

Extract text from scanned PDFs using optical character recognition

10 minutes
Beginner
File Organization

Recover Lost Code from Claude Code Sessions

Lost code when a Claude Code session ended? A recovery workflow that scans the session files in ~/.claude/, finds the code Claude wrote by date or keyword, and re-applies it to your project.

5 minutes
Beginner
File Organization

Old File Cleanup Assistant

Identify safely deletable old files with intelligent recommendations based on age, type, and usage patterns.

5 minutes
Beginner
File Organization

Screenshot Organizer

Organize thousands of screenshots by analyzing their visual content. Claude reads text in images to create meaningful names and categories.

5 minutes
Beginner
File Organization

Smart Downloads Organizer

Intelligently organize your Downloads folder by analyzing file content, not just extensions. Claude reads files to categorize them meaningfully.

5 minutes
Beginner
File Organization

Business Analytics Reporter

Analyze sales and revenue data from CSV files to identify weak areas, generate statistical insights, and provide strategic improvement recommendations.

10 minutes
Intermediate
File Organization

Batch File Converter

Batch convert documents between multiple formats using a unified pipeline

10 minutes
Advanced
File Organization

Batch Document Processor

Process multiple documents in bulk with parallel execution

10 minutes
Beginner
File Organization

Auto-Organize Downloads Folder

Automatically sort and organize files in your Downloads folder by type, date, or custom rules.

5 minutes
Beginner
File Organization

Bulk Image Extractor

Extract all images from Google Docs, PDFs, websites, and other documents in high resolution.

5 minutes
Beginner

Browse all File Organization playbooks →