Word Group Strategy Extracts Word Groups and Their Metrics
Table of Contents
Introduction
The word group strategy allows you to extract groups of words which are related to each other, such as words in a column or paragraph. It is represented by the class SetaPDF_Extractor_Strategy_WordGroup
.
The result will be an instance of SetaPDF_Extractor_Result_WordGroups
(more details are available here). Each group in this collection will be an instance of SetaPDF_Extractor_Result_Words
, which holds several instances of SetaPDF_Extractor_Result_Word
items.
Process
As the basis of this strategy are words, the strategy uses the same logic to create words as the word strategy first.
These words are inserted into a spatial storage with a scaled rectangle then. The scaling factors can be controlled with the setRectScaleFactorX()
and setRectScaleFactorY()
methods. This factor is multiplied by the font size of a word to get the final scaling value.
The strategy will then start to re-extract the words from the storage while it keeps colliding words together.
The strategy additionally allows you to define a value for a difference of font-sizes between different words through the setAllowedFontSizeDifference()
method.
Because all words are ordered in advance the resulting groups are simply re-ordered by this data.
After that an optional (active by default) process is started which reassembles words which are separated by hyphens on several lines. This can be controlled with the setDehyphen()
method.
Usage
An instance has to be created individually and passed to the main class:
$wordStrategy = new \SetaPDF_Extractor_Strategy_WordGroup(); $extractor = new \SetaPDF_Extractor($document); $extractor->setStrategy($wordStrategy);
You can get the result by this strategy by calling the getResultByPageNumber()
method for each individual page.
Each word group will be represented by an instance of SetaPDF_Extractor_Result_WordGroups
. The items in this collection will be represented by instances of SetaPDF_Extractor_Result_Word
(default) or SetaPDF_Extractor_Result_WordWithGlyphs
which both implement the SetaPDF_Extractor_Result_HasBoundsInterface
interfaces.
The detail level of the result can be controlled through the setDetailLevel()
method. It accepts following constant values as arguments:
Detail level constant.
Default detail level resulting in instances of SetaPDF_Extractor_Result_Word
.
Detail level constant.
Extended detail level resulting in instances of SetaPDF_Extractor_Result_WordWithGlyphs
.
The default result class SetaPDF_Extractor_Result_Word
will not hold information about glyphs but is less memory intensive. To get additional information about the glyphs of a word set the detail level to glyphs.
The strategy allows you to pass a filter instance to limit the result e.g. by a specific area on a page.