Tool

Process PDFs with Advanced Layout Preservation

A LlamaIndex PDF reader powered by LayoutIR - a compiler-like document engine preserving tables, multi-column layout, and offering GPU-accelerated chunking.

Works with pytorchllama index

Maintainer of this project? Claim this page to edit the listing.


84
Spark score
out of 100
Updated 2 days ago
Version 0.14.23
Models

Add to Favorites

Why it matters

Leverage advanced document processing to extract and structure information from PDFs, preserving complex layouts and tables for reliable downstream analysis and indexing.

Outcomes

What it gets done

01

Ingest PDFs using a canonical Intermediate Representation (IR) layer.

02

Maintain precise document structure, including multi-column layouts and tables.

03

Enable flexible chunking strategies for semantic or fixed-size segmentation.

04

Integrate with LlamaIndex for building searchable knowledge bases.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/li-reader-readers-layoutir | bash

Overview

LayoutIR Reader

A LlamaIndex PDF reader powered by LayoutIR, preserving tables and multi-column layout through an Intermediate Representation layer, with optional GPU-accelerated chunking. Use it for PDF ingestion where layout fidelity matters - tables and multi-column pages a simple converter would flatten - especially for a layout-aware searchable index.

What it does

Loads PDF documents into LlamaIndex via LayoutIR, a production-grade document ingestion and canonicalization engine with a compiler-like architecture. Unlike simple PDF-to-Markdown converters, it processes documents through an Intermediate Representation (IR) layer, which precisely preserves complex layouts, tables, and multi-column structures rather than flattening them. It offers deterministic processing (hash-based stable IDs for reproducible results), a canonical typed IR schema for reliable downstream processing, flexible chunking (semantic section-based or fixed-size), optional GPU acceleration for faster processing, and is designed for enterprise-grade document pipelines. Loaded documents preserve block-level metadata - block type and page number alongside the extracted text - and the reader can process a single file, a batch of files, or an entire directory via SimpleDirectoryReader's file_extractor mapping.

When to use - and when NOT to

Use it for PDF ingestion where layout fidelity matters - tables, multi-column pages, or section structure that a simple PDF-to-Markdown converter would flatten or lose - especially when building a layout-aware searchable index rather than a plain-text one.

Inputs and outputs

Input is one or more PDF file paths - a single document, or a batch such as a report, a technical spec, and a user manual processed in one call - optionally with a chunking strategy (semantic with a max heading level, or fixed-size) and a GPU flag. Output is a list of documents carrying block-type and page-number metadata, ready to feed a VectorStoreIndex for layout-aware querying.

Integrations

Built on the LayoutIR engine, with optional GPU acceleration via PyTorch/CUDA, and integrates directly with LlamaIndex's VectorStoreIndex and SimpleDirectoryReader via a file_extractor mapping for .pdf files.

Who it's for

For developers building search or retrieval over PDFs where table structure and multi-column layout need to survive ingestion - reports, technical specs, or knowledge-base documents - rather than a flat-text PDF extraction that loses that structure.

from llama_index.readers.layoutir import LayoutIRReader
from llama_index.core import VectorStoreIndex

### Load documents with preserved layout structure
reader = LayoutIRReader(
    use_gpu=True, chunk_strategy="semantic", max_heading_level=2
)
documents = reader.load_data(file_path="company_knowledge_base.pdf")

### Create index
index = VectorStoreIndex.from_documents(documents)

### Query with layout-aware context
query_engine = index.as_query_engine()
response = query_engine.query("What are the key financial metrics in Q4?")
print(response)
Source README

LayoutIR Reader

Overview

LayoutIR Reader uses LayoutIR - a production-grade document ingestion and canonicalization engine with compiler-like architecture. Unlike simple PDF-to-Markdown converters, LayoutIR processes documents through an Intermediate Representation (IR) layer, enabling precise preservation of complex layouts, tables, and multi-column structures.

Why LayoutIR?

LayoutIR stands out for its:

  • Deterministic Processing: Hash-based stable IDs ensure reproducible results
  • Layout Preservation: Maintains complex multi-column layouts and table structures
  • Canonical IR Schema: Typed intermediate representation for reliable downstream processing
  • Flexible Chunking: Semantic section-based or fixed-size chunking strategies
  • GPU Acceleration: Optional GPU support for faster document processing
  • Production-Ready: Designed for enterprise-grade document pipelines

Installation

Basic Installation

pip install llama-index-readers-layoutir

With GPU Support

For GPU acceleration, first install PyTorch with CUDA support:

pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu130
pip install llama-index-readers-layoutir

Usage

Basic Usage

Load a PDF document with default settings:

from llama_index.readers.layoutir import LayoutIRReader

reader = LayoutIRReader()
documents = reader.load_data(file_path="document.pdf")

### Each document preserves block structure and metadata
for doc in documents:
    print(f"Block Type: {doc.metadata['block_type']}")
    print(f"Page: {doc.metadata['page_number']}")
    print(f"Content: {doc.text[:100]}...")

With GPU Acceleration

Enable GPU processing for faster performance:

from llama_index.readers.layoutir import LayoutIRReader

reader = LayoutIRReader(use_gpu=True)
documents = reader.load_data(file_path="large_document.pdf")

Custom Chunking Strategy

Use semantic section-based chunking:

from llama_index.readers.layoutir import LayoutIRReader

reader = LayoutIRReader(
    chunk_strategy="semantic",
    max_heading_level=2,  # Split at h1 and h2 headings
)
documents = reader.load_data(file_path="structured_document.pdf")

Processing Multiple Files

Process a batch of documents:

from llama_index.readers.layoutir import LayoutIRReader
from pathlib import Path

reader = LayoutIRReader(use_gpu=True)

file_paths = ["report_2024.pdf", "technical_spec.pdf", "user_manual.pdf"]

documents = reader.load_data(file_path=file_paths)
print(f"Loaded {len(documents)} document blocks from {len(file_paths)} files")

Integration with VectorStoreIndex

Build a searchable index from LayoutIR-processed documents:

from llama_index.readers.layoutir import LayoutIRReader
from llama_index.core import VectorStoreIndex

### Load documents with preserved layout structure
reader = LayoutIRReader(
    use_gpu=True, chunk_strategy="semantic", max_heading_level=2
)
documents = reader.load_data(file_path="company_knowledge_base.pdf")

### Create index
index = VectorStoreIndex.from_documents(documents)

### Query with layout-aware context
query_engine = index.as_query_engine()
response = query_engine.query("What are the key financial metrics in Q4?")
print(response)

With SimpleDirectoryReader

Integrate LayoutIR for PDF processing in directory operations:

from llama_index.core import SimpleDirectoryReader
from llama_index.readers.layoutir import LayoutIRReader

reader = LayoutIRReader(use_gpu=True)

dir_reader = SimpleDirectoryReader(
    input_dir="/path/to/documents",
    file_extractor={".pdf": reader},
)

documents = dir_reader.load_data()
print(f"Processed {len(documents)} blocks")

Advanced Configuration

Full configuration example:

from llama_index.readers.layoutir import LayoutIRReader

reader = LayoutIRReader(
    use_gpu=True,  # Enable GPU acceleration
    ch

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.