Package org.apache.pdfbox.util
Class PDFTextStripperByArea
- java.lang.Object
-
- org.apache.pdfbox.util.PDFStreamEngine
-
- org.apache.pdfbox.util.PDFTextStripper
-
- org.apache.pdfbox.util.PDFTextStripperByArea
-
public class PDFTextStripperByArea extends PDFTextStripper
This will extract text from a specified region in the PDF.- Version:
- $Revision: 1.5 $
- Author:
- Ben Litchfield
-
-
Field Summary
-
Fields inherited from class org.apache.pdfbox.util.PDFTextStripper
charactersByArticle, document, output, outputEncoding, systemLineSeparator
-
-
Constructor Summary
Constructors Constructor Description PDFTextStripperByArea()
Constructor.PDFTextStripperByArea(java.lang.String encoding)
Instantiate a new PDFTextStripperArea object.PDFTextStripperByArea(java.util.Properties props)
Instantiate a new PDFTextStripperArea object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRegion(java.lang.String regionName, java.awt.geom.Rectangle2D rect)
Add a new region to group text by.void
extractRegions(PDPage page)
Process the page to extract the region text.java.util.List<java.lang.String>
getRegions()
Get the list of regions that have been setup.java.lang.String
getTextForRegion(java.lang.String regionName)
Get the text for the region, this should be called after extractRegions().protected void
processTextPosition(TextPosition text)
This will process a TextPosition object and add the text to the list of characters on a page.void
removeRegion(java.lang.String regionName)
Delete a region to group text by.protected void
writePage()
This will print the processed page text to the output stream.-
Methods inherited from class org.apache.pdfbox.util.PDFTextStripper
endArticle, endDocument, endPage, getAddMoreFormatting, getArticleEnd, getArticleStart, getAverageCharTolerance, getCharactersByArticle, getCurrentPageNo, getDropThreshold, getEndBookmark, getEndPage, getIndentThreshold, getLineSeparator, getListItemPatterns, getOutput, getPageEnd, getPageSeparator, getPageStart, getParagraphEnd, getParagraphStart, getSeparateByBeads, getSortByPosition, getSpacingTolerance, getStartBookmark, getStartPage, getSuppressDuplicateOverlappingText, getText, getText, getWordSeparator, handleLineSeparation, inspectFontEncoding, isParagraphSeparation, matchListItemPattern, matchPattern, processPage, processPages, resetEngine, setAddMoreFormatting, setArticleEnd, setArticleStart, setAverageCharTolerance, setDropThreshold, setEndBookmark, setEndPage, setIndentThreshold, setLineSeparator, setListItemPatterns, setPageEnd, setPageSeparator, setPageStart, setParagraphEnd, setParagraphStart, setShouldSeparateByBeads, setSortByPosition, setSpacingTolerance, setStartBookmark, setStartPage, setSuppressDuplicateOverlappingText, setWordSeparator, startArticle, startArticle, startDocument, startPage, writeCharacters, writeLineSeparator, writePageEnd, writePageSeperator, writePageStart, writeParagraphEnd, writeParagraphSeparator, writeParagraphStart, writeString, writeString, writeText, writeText, writeWordSeparator
-
Methods inherited from class org.apache.pdfbox.util.PDFStreamEngine
getColorSpaces, getCurrentPage, getFonts, getGraphicsStack, getGraphicsState, getGraphicsStates, getResources, getTextLineMatrix, getTextMatrix, getTotalCharCnt, getValidCharCnt, getXObjects, isForceParsing, processEncodedText, processOperator, processOperator, processStream, processSubStream, registerOperatorProcessor, setColorSpaces, setFonts, setForceParsing, setGraphicsStack, setGraphicsState, setGraphicsStates, setTextLineMatrix, setTextMatrix
-
-
-
-
Constructor Detail
-
PDFTextStripperByArea
public PDFTextStripperByArea() throws java.io.IOException
Constructor.- Throws:
java.io.IOException
- If there is an error loading properties.
-
PDFTextStripperByArea
public PDFTextStripperByArea(java.util.Properties props) throws java.io.IOException
Instantiate a new PDFTextStripperArea object. Loading all of the operator mappings from the properties object that is passed in. Does not convert the text to more encoding-specific output.- Parameters:
props
- The properties containing the mapping of operators to PDFOperator classes.- Throws:
java.io.IOException
- If there is an error reading the properties.
-
PDFTextStripperByArea
public PDFTextStripperByArea(java.lang.String encoding) throws java.io.IOException
Instantiate a new PDFTextStripperArea object. This object will load properties from PDFTextStripper.properties and will apply encoding-specific conversions to the output text.- Parameters:
encoding
- The encoding that the output will be written in.- Throws:
java.io.IOException
- If there is an error reading the properties.
-
-
Method Detail
-
addRegion
public void addRegion(java.lang.String regionName, java.awt.geom.Rectangle2D rect)
Add a new region to group text by.- Parameters:
regionName
- The name of the region.rect
- The rectangle area to retrieve the text from.
-
removeRegion
public void removeRegion(java.lang.String regionName)
Delete a region to group text by. If the region does not exist, this method does nothing.- Parameters:
regionName
- The name of the region to delete.
-
getRegions
public java.util.List<java.lang.String> getRegions()
Get the list of regions that have been setup.- Returns:
- A list of java.lang.String objects to identify the region names.
-
getTextForRegion
public java.lang.String getTextForRegion(java.lang.String regionName)
Get the text for the region, this should be called after extractRegions().- Parameters:
regionName
- The name of the region to get the text from.- Returns:
- The text that was identified in that region.
-
extractRegions
public void extractRegions(PDPage page) throws java.io.IOException
Process the page to extract the region text.- Parameters:
page
- The page to extract the regions from.- Throws:
java.io.IOException
- If there is an error while extracting text.
-
processTextPosition
protected void processTextPosition(TextPosition text)
This will process a TextPosition object and add the text to the list of characters on a page. It takes care of overlapping text.- Overrides:
processTextPosition
in classPDFTextStripper
- Parameters:
text
- The text to process.
-
writePage
protected void writePage() throws java.io.IOException
This will print the processed page text to the output stream.- Overrides:
writePage
in classPDFTextStripper
- Throws:
java.io.IOException
- If there is an error writing the text.
-
-