Home
cd ../playbooks
File OrganizationBeginner

Document Layout Analyzer

Detect text blocks, tables, figures, and reading order in complex documents using surya.

10 minutes
By communitySource
#layout#analysis#structure#surya

Your PDF has two-column text, tables that wrap across pages, sidebars mixed with body text, and figures with captions. Standard OCR reads it top-to-bottom and scrambles everything. You need layout understanding, not just text extraction.

Who it's for: data engineers processing complex document layouts, researchers extracting structured data from academic papers, legal teams parsing multi-column contracts, developers building document processing pipelines, anyone whose PDFs have layouts that break standard text extraction

Example

"Analyze the layout of these 50 research papers to extract figures and tables" → Layout detection identifying text blocks, tables, figures, and captions with correct reading order — even in two-column papers with floating elements — ready for structured downstream processing

CLAUDE.md Template

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

Or install from your terminal:
npx ccplaybooks add layout-analyzer
# Layout Analyzer

## Overview

This workflow enables document layout analysis using **surya** - an advanced document understanding system. Detect text blocks, tables, figures, headings, and determine reading order in complex documents.

## How to Use

1. Provide the document image or PDF
2. Specify what layout elements to detect
3. I'll analyze the structure and return detected regions

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 document layout analysis using surya - an advanced document understanding system. Detect text blocks, tables, figures, headings, and determine reading order in complex documents.


Quick Start

Step 1: Create a Project Folder

mkdir -p ~/Documents/LayoutAnalyzer

Step 2: Download the Template

Click Download above, then:

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

Step 3: Start Working

cd ~/Documents/LayoutAnalyzer
claude

How to Use

  1. Provide the document image or PDF
  2. Specify what layout elements to detect
  3. I'll analyze the structure and return detected regions

Example prompts:

  • "Analyze the layout of this document page"
  • "Detect all tables and text blocks in this image"
  • "Determine the reading order for this PDF page"
  • "Find headings and paragraphs in this document"

Best Practices

  1. Use High-Quality Images: 150+ DPI for best results
  2. Preprocess if Needed: Deskew rotated documents
  3. Validate Results: Check confidence scores
  4. Handle Multi-page: Process pages individually
  5. Combine with OCR: Get text within detected regions

Examples

Example 1: Academic Paper Analysis

from surya.layout import LayoutPredictor
from surya.reading_order import ReadingOrderPredictor
from pdf2image import convert_from_path

def analyze_academic_paper(pdf_path):
    """Analyze structure of academic paper."""
    
    images = convert_from_path(pdf_path)
    
    layout_predictor = LayoutPredictor()
    order_predictor = ReadingOrderPredictor()
    
    paper_structure = {
        'pages': [],
        'element_counts': {
            'Title': 0,
            'Section-header': 0,
            'Text': 0,
            'Table': 0,
            'Figure': 0,
            'Formula': 0,
            'Footnote': 0
        }
    }
    
    layout_results = layout_predictor(images)
    order_results = order_predictor(images, layout_results)
    
    for page_num, (layout, order) in enumerate(zip(layout_results, order_results)):
        page_structure = {
            'page': page_num + 1,
            'elements': []
        }
        
        for element in order.ordered_bboxes:
            page_structure['elements'].append({
                'type': element.label,
                'bbox': element.bbox,
                'order': element.position
            })
            
            # Count element types
            if element.label in paper_structure['element_counts']:
                paper_structure['element_counts'][element.label] += 1
        
        paper_structure['pages'].append(page_structure)
    
    return paper_structure

paper = analyze_academic_paper('research_paper.pdf')
print(f"Total tables: {paper['element_counts']['Table']}")
print(f"Total figures: {paper['element_counts']['Figure']}")

Example 2: Form Field Detection

from surya.layout import LayoutPredictor
from PIL import Image

def detect_form_fields(image_path):
    """Detect form fields and labels."""
    
    image = Image.open(image_path)
    
    layout_predictor = LayoutPredictor()
    results = layout_predictor([image])
    
    form_fields = []
    
    for element in results[0].bboxes:
        # Look for text elements that might be labels
        if element.label == 'Text':
            # Check if there's a box/line nearby (potential input field)
            form_fields.append({
                'type': 'potential_label',
                'bbox': element.bbox,
                'confidence': element.confidence
            })
    
    return form_fields

fields = detect_form_fields('form.png')
print(f"Found {len(fields)} potential form elements")

Example 3: Multi-column Article

Limitations

  • Handwritten layouts may be inaccurate
  • Very small text regions may be missed
  • Complex nested layouts challenging
  • GPU recommended for batch processing
  • Multi-language support varies

Installation

pip install surya-ocr

# For PDF processing
pip install pdf2image

$Related Playbooks

File Organization

Markdown to Office Converter

Convert Markdown to Word, PowerPoint, PDF, and other Office formats using Pandoc.

10 minutes
Advanced
File Organization

Mac Performance Diagnostics

Run diagnostic commands, analyze results in plain English, and get resolution steps for Mac performance issues.

5 minutes
Beginner
File Organization

Smart OCR Document Scanner

Extract text from images, scanned documents, and handwritten notes in 100+ languages using PaddleOCR.

10 minutes
Intermediate
File Organization

PDF to Word Converter

Convert PDF files to editable Word documents using pdf2docx

10 minutes
Intermediate
File Organization

PDF Watermark Tool

Add watermarks, page numbers, headers, and footers to PDFs

10 minutes
Intermediate
File Organization

Project Inventory & Documentation

Analyze project folders to understand what each does, identify tech stacks, and create documented inventories.

10 minutes
Intermediate
File Organization

Photo Organizer by Event

Organize photos by reading EXIF metadata and analyzing content to create Year > Month > Event folder structures automatically.

5 minutes
Beginner
File Organization

Office to Markdown Converter

Convert Office documents to Markdown for version control and AI processing using Microsoft's markitdown.

10 minutes
Advanced
File Organization

PDF Compression Tool

Reduce PDF file size while maintaining acceptable quality

10 minutes
Intermediate
File Organization

Universal PDF Converter

Convert PDF files to and from Word, Excel, Image, and other formats

10 minutes
Intermediate
File Organization

PDF Text & Table Extractor

Extract text, tables, and metadata from PDFs using pdfplumber

10 minutes
Beginner
File Organization

PDF Form Auto-Filler

Fill out PDF forms programmatically and extract form data

10 minutes
Advanced

Browse all File Organization playbooks →