Top Description Fields Constructors Methods
org.apache.pdfbox.examples.util

public Class PDFHighlighter

extends PDFTextStripper
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .File, .IOException, .OutputStreamWriter, .Writer, java.nio.charset.Charset, .StandardCharsets, java.util.regex.Matcher, .Pattern, org.apache.pdfbox.Loader, org.apache.pdfbox.pdmodel.PDDocument, .PDPage, org.apache.pdfbox.text.PDFTextStripper

Highlighting of words in a PDF document with an XML file.
Authors
slagraulet ([email protected]), Ben Litchfield
See Also
Adobe Highlight File Format

Field Summary

Modifier and TypeField and Description
private static final Charset
private Writer
private String[]
private ByteArrayOutputStream
private Writer
Inherited from org.apache.pdfbox.text.PDFTextStripper:
charactersByArticledocumentLINE_SEPARATORoutput

Constructor Summary

AccessConstructor and Description
public
PDFHighlighter()

Default constructor.

Method Summary

Modifier and TypeMethod and Description
protected void
endPage(PDPage
The page we are about to process.
pdPage
)

Overrides org.apache.pdfbox.text.PDFTextStripper.endPage.

End a page.

public void
generateXMLHighlight(PDDocument
The PDF to find words in.
pdDocument
,
String
The word to search for.
highlightWord
,
Writer
The resulting output xml file.
xmlOutput
)

Generate an XML highlight string based on the PDF.

public void
generateXMLHighlight(PDDocument
The PDF to find words in.
pdDocument
,
String[]
The words to search for.
sWords
,
Writer
The resulting output xml file.
xmlOutput
)

Generate an XML highlight string based on the PDF.

public static void
main(String[]
The command line arguments to the application.
args
)

Command line application.

private static void
Inherited from org.apache.pdfbox.text.PDFTextStripper:
beginMarkedContentSequenceendArticleendDocumentendMarkedContentSequencegetAddMoreFormattinggetArticleEndgetArticleStartgetAverageCharTolerancegetCharactersByArticlegetCurrentPageNogetDropThresholdgetEndBookmarkgetEndPagegetIgnoreContentStreamSpaceGlyphsgetIndentThresholdgetLineSeparatorgetListItemPatternsgetOutputgetPageEndgetPageStartgetParagraphEndgetParagraphStartgetSeparateByBeadsgetSortByPositiongetSpacingTolerancegetStartBookmarkgetStartPagegetSuppressDuplicateOverlappingTextgetTextgetWordSeparatormatchPatternprocessPageprocessPagesprocessTextPositionsetAddMoreFormattingsetArticleEndsetArticleStartsetAverageCharTolerancesetDropThresholdsetEndBookmarksetEndPagesetIgnoreContentStreamSpaceGlyphssetIndentThresholdsetLineSeparatorsetListItemPatternssetPageEndsetPageStartsetParagraphEndsetParagraphStartsetShouldSeparateByBeadssetSortByPositionsetSpacingTolerancesetStartBookmarksetStartPagesetSuppressDuplicateOverlappingTextsetWordSeparatorstartArticlestartArticlestartDocumentstartPagewriteCharacterswriteLineSeparatorwritePagewritePageEndwritePageStartwriteParagraphEndwriteParagraphSeparatorwriteParagraphStartwriteStringwriteStringwriteTextwriteWordSeparator

Field Detail

ENCODINGback to summary
private static final Charset ENCODING
highlighterOutputback to summary
private Writer highlighterOutput
searchedWordsback to summary
private String[] searchedWords
textOSback to summary
private ByteArrayOutputStream textOS
textWriterback to summary
private Writer textWriter

Constructor Detail

PDFHighlighterback to summary
public PDFHighlighter() throws IOException

Default constructor.

Exceptions
IOException:
If there is an error constructing this class.

Method Detail

endPageback to summary
protected void endPage(PDPage pdPage) throws IOException

Overrides org.apache.pdfbox.text.PDFTextStripper.endPage.

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

End a page. Default implementation is to do nothing. Subclasses may provide additional information.

Parameters
pdPage:PDPage

The page we are about to process.

Annotations
@Override
Exceptions
IOException:
If there is any error writing to the stream.
generateXMLHighlightback to summary
public void generateXMLHighlight(PDDocument pdDocument, String highlightWord, Writer xmlOutput) throws IOException

Generate an XML highlight string based on the PDF.

Parameters
pdDocument:PDDocument

The PDF to find words in.

highlightWord:String

The word to search for.

xmlOutput:Writer

The resulting output xml file.

Exceptions
IOException:
If there is an error reading from the PDF, or writing to the XML.
generateXMLHighlightback to summary
public void generateXMLHighlight(PDDocument pdDocument, String[] sWords, Writer xmlOutput) throws IOException

Generate an XML highlight string based on the PDF.

Parameters
pdDocument:PDDocument

The PDF to find words in.

sWords:String[]

The words to search for.

xmlOutput:Writer

The resulting output xml file.

Exceptions
IOException:
If there is an error reading from the PDF, or writing to the XML.
mainback to summary
public static void main(String[] args) throws IOException

Command line application.

Parameters
args:String[]

The command line arguments to the application.

Exceptions
IOException:
If there is an error generating the highlight file.
usageback to summary
private static void usage()