This class will take a pdf document and strip out all of the text and ignore the
formatting and such.
endDocument
protected void endDocument(PDDocument pdf)
throws IOException
This method is available for subclasses of this class. It will be called after processing
of the document finishes.
pdf
- The PDF document that is being processed.
endPage
protected void endPage(PDPage page)
throws IOException
End a page. Default implementation is to do nothing. Subclasses
may provide additional information.
page
- The page we are about to process.
endParagraph
protected void endParagraph()
throws IOException
End a paragraph. Default implementation is to do nothing. Subclasses
may provide additional information.
flushText
protected void flushText()
throws IOException
This will print the text to the output stream.
getCharactersByArticle
protected List getCharactersByArticle()
Character strings are grouped by articles. It is quite common that there
will only be a single article. This returns a List that contains List objects,
the inner lists will contain TextPosition objects.
- A double List of TextPositions for all text strings on the page.
getCurrentPageNo
protected int getCurrentPageNo()
Get the current page number that is being processed.
- A 1 based number representing the current page.
getEndBookmark
public PDOutlineItem getEndBookmark()
Get the bookmark where text extraction should end, inclusive. Default is null.
getEndPage
public int getEndPage()
This will get the last page that will be extracted. This is inclusive,
for example if a 5 page PDF an endPage value of 5 would extract the
entire document, an end page of 2 would extract pages 1 and 2. This defaults
to Integer.MAX_VALUE such that all pages of the pdf will be extracted.
- Value of property endPage.
getLineSeparator
public String getLineSeparator()
This will get the line separator.
- The desired line separator string.
getOutput
protected Writer getOutput()
The output stream that is being written to.
- The stream that output is being written to.
getPageSeparator
public String getPageSeparator()
This will get the page separator.
- The page separator string.
getStartBookmark
public PDOutlineItem getStartBookmark()
Get the bookmark where text extraction should start, inclusive. Default is null.
getStartPage
public int getStartPage()
This is the page that the text extraction will start on. The pages start
at page 1. For example in a 5 page PDF document, if the start page is 1
then all pages will be extracted. If the start page is 4 then pages 4 and 5
will be extracted. The default value is 1.
- Value of property startPage.
getText
public String getText(COSDocument doc)
throws IOException
doc
- The document to extract the text from.
getText
public String getText(PDDocument doc)
throws IOException
This will return the text of a document. See writeText.
NOTE: The document must not be encrypted when coming into this method.
doc
- The document to get the text from.
- The text of the PDF document.
getWordSeparator
public String getWordSeparator()
This will get the word separator.
- The desired word separator string.
processPage
protected void processPage(PDPage page,
COSStream content)
throws IOException
This will process the contents of a page.
page
- The page to process.content
- The contents of the page.
processPages
protected void processPages(List pages)
throws IOException
This will process all of the pages and the text that is in them.
pages
- The pages object in the document.
setEndBookmark
public void setEndBookmark(PDOutlineItem aEndBookmark)
Set the bookmark where the text extraction should stop.
aEndBookmark
- The ending bookmark.
setEndPage
public void setEndPage(int endPageValue)
This will set the last page to be extracted by this class.
endPageValue
- New value of property endPage.
setLineSeparator
public void setLineSeparator(String separator)
Set the desired line separator for output text. The line.separator
system property is used if the line separator preference is not set
explicitly using this method.
separator
- The desired line separator string.
setPageSeparator
public void setPageSeparator(String separator)
Set the desired page separator for output text. The line.separator
system property is used if the page separator preference is not set
explicitly using this method.
separator
- The desired page separator string.
setShouldSeparateByBeads
public void setShouldSeparateByBeads(boolean aShouldSeparateByBeads)
Set if the text stripper should group the text output by a list of beads. The default value is true!
aShouldSeparateByBeads
- The new grouping of beads.
setSortByPosition
public void setSortByPosition(boolean newSortByPosition)
The order of the text tokens in a PDF file may not be in the same
as they appear visually on the screen. For example, a PDF writer may
write out all text by font, so all bold or larger text, then make a second
pass and write out the normal text.
The default is to not sort by position.
A PDF writer could choose to write each character in a different order. By
default PDFBox does not sort the text tokens before processing them due to
performance reasons.
newSortByPosition
- Tell PDFBox to sort the text positions.
setStartBookmark
public void setStartBookmark(PDOutlineItem aStartBookmark)
Set the bookmark where text extraction should start, inclusive.
aStartBookmark
- The starting bookmark.
setStartPage
public void setStartPage(int startPageValue)
This will set the first page to be extracted by this class.
startPageValue
- New value of property startPage.
setSuppressDuplicateOverlappingText
public void setSuppressDuplicateOverlappingText(boolean suppressDuplicateOverlappingTextValue)
By default the text stripper will attempt to remove text that overlapps each other.
Word paints the same character several times in order to make it look bold. By setting
this to false all text will be extracted, which means that certain sections will be
duplicated, but better performance will be noticed.
suppressDuplicateOverlappingTextValue
- The suppressDuplicateOverlappingText to set.
setWordSeparator
public void setWordSeparator(String separator)
Set the desired word separator for output text. The PDFBox text extraction
algorithm will output a space character if there is enough space between
two words. By default a space character is used. If you need and accurate
count of characters that are found in a PDF document then you might want to
set the word separator to the empty string.
separator
- The desired page separator string.
shouldSeparateByBeads
public boolean shouldSeparateByBeads()
This will tell if the text stripper should separate by beads.
- If the text will be grouped by beads.
shouldSortByPosition
public boolean shouldSortByPosition()
This will tell if the text stripper should sort the text tokens
before writing to the stream.
- true If the text tokens will be sorted before being written.
shouldSuppressDuplicateOverlappingText
public boolean shouldSuppressDuplicateOverlappingText()
- Returns the suppressDuplicateOverlappingText.
showCharacter
protected void showCharacter(TextPosition text)
This will show add a character to the list of characters to be printed to
the text file.
- showCharacter in interface PDFStreamEngine
text
- The description of the character to display.
startDocument
protected void startDocument(PDDocument pdf)
throws IOException
This method is available for subclasses of this class. It will be called before processing
of the document start.
pdf
- The PDF document that is being processed.
startPage
protected void startPage(PDPage page)
throws IOException
Start a new page. Default implementation is to do nothing. Subclasses
may provide additional information.
page
- The page we are about to process.
startParagraph
protected void startParagraph()
throws IOException
Start a new paragraph. Default implementation is to do nothing. Subclasses
may provide additional information.
writeCharacters
protected void writeCharacters(TextPosition text)
throws IOException
Write the string to the output stream.
text
- The text to write to the stream.
writeText
public void writeText(COSDocument doc,
Writer outputStream)
throws IOException
doc
- The document to extract the text.outputStream
- The stream to write the text to.
writeText
public void writeText(PDDocument doc,
Writer outputStream)
throws IOException
This will take a PDDocument and write the text of that document to the print writer.
doc
- The document to get the data from.outputStream
- The location to put the text.