Skip to main content
For long documents, use page ranges and document segmentation to limit extraction to the content you need. Before you begin, make sure you have:
  1. A Datalab account with an API key (new accounts include $5 in free credits)
  2. Python 3.10+ installed
  3. The Datalab SDK: pip install datalab-python-sdk
  4. Your DATALAB_API_KEY environment variable set

Restrict to Specific Pages

If you know which pages contain the data you need, use page_range:
Page-based charges use the selected pages. Complex extraction requests may also use compute-based pricing; see Billing.

Segment and Chain Extractions

For documents with distinct sections (like financial reports or contracts), extract the table of contents first, then process each section separately.

Step 1: Extract Table of Contents

Step 2: Extract Each Section

page_range uses original, 0-indexed PDF pages. Printed table-of-contents numbers can have a different offset or use Roman numerals. Verify and map each extracted page_number to a PDF page index before running these examples. Set total_pages to the actual PDF page count so the final section includes all remaining pages.

Use Document Segmentation

For documents without a clear table of contents, use Document Segmentation to locate named sections in the parsed document.

Full Example

Process sections after verifying the table of contents and mapping its page numbers to PDF page indices:

Tips

  1. Process pages you need - Use page_range to avoid processing unnecessary pages
  2. Extract TOC first - Build page ranges dynamically from the document structure
  3. Choose extraction and parsing independently - Set extraction_mode for extraction quality and mode for parsing quality; see Extraction Modes
  4. Handle errors - Some sections may not match your schema exactly

Next Steps

Structured Extraction

Learn the full structured extraction API and schema options.

Document Segmentation

Automatically split documents by section headers.

Batch Processing

Process multiple long documents efficiently in parallel.

Pipelines

Chain processors into versioned, reusable pipelines.