Skip to content

Blocks

The LAY methods that work on the blocks are:

LAY.getBlocksCount()

Returns the number of blocks detected in the document layout.

For example the instruction:

var nBlocks = LAY.getBlocksCount();
returns the integer value 69 in the nBlocks variable.

Note

Blocks count starts from 1. The entire page is the block number 1.

Visually you can see the block numbers, the ids, as in the following picture:

LAY.getBlock(id)

Returns an object that contains keys and properties of the the block with the given id or undefined if no block has the given id.

Info

Block ids are not zero-based so they start from 1.

For example the instruction:

var block = LAY.getBlock(3);

returns the following object in the block variable:

{
    "id": 3,
    "parent": 1,
    "pageNumber": 1,
    "type": "text",
    "x0": 67,
    "y0": 139,
    "x1": 152,
    "y1": 176,
    "children": [],
    "beginPos": 8,
    "endPos": 24,
    "tokenBegin": 1,
    "tokenEnd": 8,
    "wordBegin": 1,
    "wordEnd": 2,
    "label": ""
}

where:

Field name Description Field type Default value
id A unique id associated to the block Integer -1
parent The id of the parent block Integer -1
pageNumber The page number in which the block is situated Integer -1
type The type of block (text, title, cell, and so on) String ""
label A label with some additional information on the block String ""
x0 The x-axis coordinate of the upper-left corner of the block, relative to the page Integer 0
y0 The y-axis coordinate of the upper-left corner of the block, relative to the page Integer 0
x1 The x-axis coordinate of the lower-right corner of the block, relative to the page Integer 0
y1 The y-axis coordinate of the lower-right corner of the block, relative to the page Integer 0
children The id of the blocks that are children of the block (like the blocks of a page or the cells of a table) List of Integers [ ]
beginPos The position in the text in which the block content starts Integer -1
endPos The position in the text in which the block content ends Integer -1
tokenBegin The index of the first token in the block content Integer -1
tokenEnd The index of the last token in the block content Integer -1
wordBegin The index of the first word in the block Integer -1
wordEnd The index of the last word in the block Integer -1

LAY.getBlockText(id)

Returns the text contained in the block with the given id, or undefined if the id is not valid.

Info

Block ids are not zero-based so they start from 1.

For example the instruction:

var blockText = LAY.getBlockText(3);

returns the string value:

DATE: 
10/21/2015

in the variable blockText.