Skip to content

Layout recognition

Layout recognition (LR) analyzes the layout structure of a PDF page and returns a traversable structure tree. You can use it to identify paragraphs, headings, tables, cells, figures, and other elements, then extract positions, text ranges, or structural attributes.

It suits server-side structure analysis, table region detection, content reorganization, layout-based processing, and downstream steps that depend on layout information.

Use cases

Layout recognition is suited for:

  • Server-side PDF structure analysis, passing element coordinates to a front end for display, confirmation, and correction
  • Structural analysis of tabular documents—headers, cells, and data regions
  • PDF to HTML, translation backfill, or content review based on layout and text ranges
  • Reading content by paragraph, heading, cell, and other structures for comparison, extraction, and further processing

Prerequisites

  • Initialize Foxit PDF SDK with a license that includes the LayoutRecognition module
  • Load the target PDF document and page successfully before use
  • LR takes a PDFPage as input; iterate pages in application code for whole documents

Capabilities

The primary output is a structure tree to traverse, not finished business data. You continue business logic on that tree.

LR output typically includes:

  • Structure types such as Document, Sect, P, H1, H2, Table, TR, TH, TD, Figure
  • Geometry such as BBox on structure or content elements
  • Attributes such as WritingMode, RowSpan, ColSpan, TableHeaders
  • Content mapping: ranges in graphics objects, matrices, and related graphics objects

For tables, traverse Table, TR, TH, TD to locate candidate regions, then use BBox and attributes in your logic.

Main APIs

ClassPurpose
LRContextRun layout parsing on a PDFPage and return the structure tree root
LRElementBase LR element; element type and category
LRStructureElementStructure tree node; children, parent, bounding box, attributes
LRContentElementContent element; content range, bounding box, matrix, related graphics
LRGraphicsObjectElementGraphics object element; GraphicsObject, bounding box, matrix, index

Basic workflow

  1. Initialize Foxit PDF SDK
  2. Load the PDF and get the target page
  3. Create LRContext
  4. Call StartParse()
  5. Get the root with GetRootElement()
  6. Recursively traverse the tree and read types and attributes as needed

See /examples/simple_demo/layout_recognition/layout_recognition.cpp in the SDK package. The snippet below shows page parsing and tree retrieval:

c++
#include "include/addon/layoutrecognition/fs_layoutrecognition.h"

using namespace foxit;
using namespace foxit::addon::layoutrecognition;

void ParsePageLayout(const wchar_t* input_file) {
  // Foxit PDF SDK should have been initialized before LR starts.
  PDFDoc doc(input_file);
  if (doc.Load() != foxit::e_ErrSuccess) {
    return;
  }

  PDFPage page = doc.GetPage(0);
  LRContext context(page);

  common::Progressive progressive = context.StartParse(NULL);
  while (progressive.GetRateOfProgress() != 100) {
    if (progressive.Continue() != common::Progressive::e_ToBeContinued) {
      break;
    }
  }

  LRStructureElement root = context.GetRootElement();
  if (root.IsEmpty()) {
    return;
  }

  int child_count = root.GetChildCount();
  for (int i = 0; i < child_count; ++i) {
    LRElement child = root.GetChild(i);
    String type_name = child.StringifyType();
    // Handle type_name per your app: debug output, filter by structure type, map to business logic, etc.
  }
}

Traversing the structure tree

In practice, recursively traverse LRStructureElement and filter by type.

Common operations:

  • Traverse with GetChildCount() / GetChild()
  • Identify types with GetElementType() or StringifyType()
  • Read regions with GetBBox()
  • Enumerate attributes with GetSupportedAttributeCount() / GetSupportedAttribute()
  • Read values with GetAttributeValueType() and the matching GetAttributeValue*() methods

To map layout back to page content or graphics objects:

  • LRContentElement::GetGraphicsObjectRange()
  • LRContentElement::GetBBox()
  • LRGraphicsObjectElement::GetGraphicsObject()

Output interpretation

Treat LR output as structural analysis, not final business data.

Typical follow-on work:

  • Locate candidate table regions
  • Group headings, paragraphs, cells, and other structures
  • Extract region coordinates
  • Map content to page objects
  • Extract and post-process business fields

The SDK sample writes the structure tree to layout_recognition_info.txt so you can inspect types, attributes, and values.

Development tips

  • LRContext input is a single PDFPage; process documents page by page
  • StartParse() is progressive; continue Progressive until complete on complex pages
  • Tables, paragraphs, and headings often need business rules for confirmation
  • Bordered regular tables are a good first integration target; borderless or complex layouts may need manual correction or extra logic
  • For front-end display, use structure or content element BBox as page coordinates

When to use layout recognition

Use LR when the goal is to understand page structure and process content by structure—not only raw text.

Examples:

  • Identify tables, paragraphs, headings, cells, and other layout elements
  • Restructure page content for HTML, translation, comparison, or extraction
  • Obtain coordinates, hierarchy, and relationships between elements

To see SDK usage quickly, read /examples/simple_demo/layout_recognition/layout_recognition.cpp in the SDK package.