Top Description Fields Constructors Methods
org.apache.pdfbox.text

public Class PDFTextStripperByArea

extends PDFTextStripper
Class Inheritance
Imports
java.awt.geom.Rectangle2D, java.io.IOException, .StringWriter, java.util.ArrayList, .HashMap, .List, .Map, org.apache.pdfbox.pdmodel.PDPage

This will extract text from a specified region in the PDF.
Author
Ben Litchfield

Field Summary

Modifier and TypeField and Description
private final Map<String, Rectangle2D>
private final Map<String, ArrayList<List<TextPosition>>>
private final List<String>
private final Map<String, StringWriter>
Inherited from org.apache.pdfbox.text.PDFTextStripper:
charactersByArticledocumentLINE_SEPARATORoutput

Constructor Summary

AccessConstructor and Description
public
PDFTextStripperByArea()

Constructor.

Method Summary

Modifier and TypeMethod and Description
public void
addRegion(String
The name of the region.
regionName
,
Rectangle2D
The rectangle area to retrieve the text from. The y-coordinates are java coordinates (y == 0 is top), not PDF coordinates (y == 0 is bottom).
rect
)

Add a new region to group text by.

public void
extractRegions(PDPage
The page to extract the regions from.
page
)

Process the page to extract the region text.

public List<String>

Returns:

A list of java.lang.String objects to identify the region names.
getRegions
()

Get the list of regions that have been setup.

public String

Returns:

The text that was identified in that region.
getTextForRegion
(String
The name of the region to get the text from.
regionName
)

Get the text for the region, this should be called after extractRegions().

protected void
processTextPosition(TextPosition
The text to process.
text
)

Overrides org.apache.pdfbox.text.PDFTextStripper.processTextPosition.

This will process a TextPosition object and add the text to the list of characters on a page.

public void
removeRegion(String
The name of the region to delete.
regionName
)

Delete a region to group text by.

public final void
setShouldSeparateByBeads(boolean
The new grouping of beads.
aShouldSeparateByBeads
)

Overrides org.apache.pdfbox.text.PDFTextStripper.setShouldSeparateByBeads.

This method does nothing in this derived class, because beads and regions are incompatible.

protected void
writePage()

Overrides org.apache.pdfbox.text.PDFTextStripper.writePage.

This will print the processed page text to the output stream.

Inherited from org.apache.pdfbox.text.PDFTextStripper:
beginMarkedContentSequenceendArticleendDocumentendMarkedContentSequenceendPagegetAddMoreFormattinggetArticleEndgetArticleStartgetAverageCharTolerancegetCharactersByArticlegetCurrentPageNogetDropThresholdgetEndBookmarkgetEndPagegetIgnoreContentStreamSpaceGlyphsgetIndentThresholdgetLineSeparatorgetListItemPatternsgetOutputgetPageEndgetPageStartgetParagraphEndgetParagraphStartgetSeparateByBeadsgetSortByPositiongetSpacingTolerancegetStartBookmarkgetStartPagegetSuppressDuplicateOverlappingTextgetTextgetWordSeparatormatchPatternprocessPageprocessPagessetAddMoreFormattingsetArticleEndsetArticleStartsetAverageCharTolerancesetDropThresholdsetEndBookmarksetEndPagesetIgnoreContentStreamSpaceGlyphssetIndentThresholdsetLineSeparatorsetListItemPatternssetPageEndsetPageStartsetParagraphEndsetParagraphStartsetSortByPositionsetSpacingTolerancesetStartBookmarksetStartPagesetSuppressDuplicateOverlappingTextsetWordSeparatorstartArticlestartArticlestartDocumentstartPagewriteCharacterswriteLineSeparatorwritePageEndwritePageStartwriteParagraphEndwriteParagraphSeparatorwriteParagraphStartwriteStringwriteStringwriteTextwriteWordSeparator

Field Detail

regionAreaback to summary
private final Map<String, Rectangle2D> regionArea
regionCharacterListback to summary
private final Map<String, ArrayList<List<TextPosition>>> regionCharacterList
regionsback to summary
private final List<String> regions
regionTextback to summary
private final Map<String, StringWriter> regionText

Constructor Detail

PDFTextStripperByAreaback to summary
public PDFTextStripperByArea() throws IOException

Constructor.

Exceptions
IOException:
If there is an error loading properties.

Method Detail

addRegionback to summary
public void addRegion(String regionName, Rectangle2D rect)

Add a new region to group text by.

Parameters
regionName:String

The name of the region.

rect:Rectangle2D

The rectangle area to retrieve the text from. The y-coordinates are java coordinates (y == 0 is top), not PDF coordinates (y == 0 is bottom).

extractRegionsback to summary
public void extractRegions(PDPage page) throws IOException

Process the page to extract the region text.

Parameters
page:PDPage

The page to extract the regions from.

Exceptions
IOException:
If there is an error while extracting text.
getRegionsback to summary
public List<String> getRegions()

Get the list of regions that have been setup.

Returns:List<String>

A list of java.lang.String objects to identify the region names.

getTextForRegionback to summary
public String getTextForRegion(String regionName)

Get the text for the region, this should be called after extractRegions().

Parameters
regionName:String

The name of the region to get the text from.

Returns:String

The text that was identified in that region.

processTextPositionback to summary
protected void processTextPosition(TextPosition text)

Overrides org.apache.pdfbox.text.PDFTextStripper.processTextPosition.

Doc from org.apache.pdfbox.text.PDFTextStripper.processTextPosition.

This will process a TextPosition object and add the text to the list of characters on a page. It takes care of overlapping text.

Parameters
text:TextPosition

The text to process.

Annotations
@Override
removeRegionback to summary
public void removeRegion(String regionName)

Delete a region to group text by. If the region does not exist, this method does nothing.

Parameters
regionName:String

The name of the region to delete.

setShouldSeparateByBeadsback to summary
public final void setShouldSeparateByBeads(boolean aShouldSeparateByBeads)

Overrides org.apache.pdfbox.text.PDFTextStripper.setShouldSeparateByBeads.

This method does nothing in this derived class, because beads and regions are incompatible. Beads are ignored when stripping by area.

Parameters
aShouldSeparateByBeads:boolean

The new grouping of beads.

Annotations
@Override
writePageback to summary
protected void writePage() throws IOException

Overrides org.apache.pdfbox.text.PDFTextStripper.writePage.

This will print the processed page text to the output stream.

Annotations
@Override
Exceptions
IOException:
If there is an error writing the text.