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

public Class PDFMarkedContentExtractor

extends LegacyPDFStreamEngine
Class Inheritance
Imports
java.util.ArrayDeque, .ArrayList, .HashMap, .List, .Map, .Deque, org.apache.pdfbox.cos.COSDictionary, .COSName, org.apache.pdfbox.pdmodel.documentinterchange.markedcontent.PDMarkedContent, org.apache.pdfbox.pdmodel.graphics.PDXObject, org.apache.pdfbox.contentstream.operator.markedcontent.BeginMarkedContentSequence, .BeginMarkedContentSequenceWithProperties, .DrawObject, .EndMarkedContentSequence

This is an stream engine to extract the marked content of a pdf.
Author
Johannes Koch

Field Summary

Modifier and TypeField and Description
private final Map<String, List<TextPosition>>
private final Deque<PDMarkedContent>
private final List<PDMarkedContent>
private boolean

Constructor Summary

AccessConstructor and Description
public
PDFMarkedContentExtractor()

Instantiate a new PDFTextStripper object.

public
PDFMarkedContentExtractor(String
The encoding that the output will be written in.
encoding
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public void
beginMarkedContentSequence(COSName
indicates the role or significance of the sequence
tag
,
COSDictionary
optional properties
properties
)

Overrides org.apache.pdfbox.contentstream.PDFStreamEngine.beginMarkedContentSequence.

Called when a marked content group begins

public void
public List<PDMarkedContent>
public boolean

Returns:

the suppressDuplicateOverlappingText setting.
isSuppressDuplicateOverlappingText
()

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

Overrides org.apache.pdfbox.text.LegacyPDFStreamEngine.processTextPosition.

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

public void
setSuppressDuplicateOverlappingText(boolean
The suppressDuplicateOverlappingText setting to set.
suppressDuplicateOverlappingText
)

By default the class will attempt to remove text that overlaps each other.

private boolean
within(float
The first number to compare to.
first
,
float
The second number to compare to.
second
,
float
The allowed variance.
variance
)

This will determine of two floating point numbers are within a specified variance.

public void
xobject(PDXObject xobject)

Inherited from org.apache.pdfbox.text.LegacyPDFStreamEngine:
computeFontHeightprocessPageshowGlyph

Field Detail

characterListMappingback to summary
private final Map<String, List<TextPosition>> characterListMapping
currentMarkedContentsback to summary
private final Deque<PDMarkedContent> currentMarkedContents
markedContentsback to summary
private final List<PDMarkedContent> markedContents
suppressDuplicateOverlappingTextback to summary
private boolean suppressDuplicateOverlappingText

Constructor Detail

PDFMarkedContentExtractorback to summary
public PDFMarkedContentExtractor()

Instantiate a new PDFTextStripper object.

PDFMarkedContentExtractorback to summary
public PDFMarkedContentExtractor(String encoding)

Constructor. Will apply encoding-specific conversions to the output text.

Parameters
encoding:String

The encoding that the output will be written in.

Method Detail

beginMarkedContentSequenceback to summary
public void beginMarkedContentSequence(COSName tag, COSDictionary properties)

Overrides org.apache.pdfbox.contentstream.PDFStreamEngine.beginMarkedContentSequence.

Doc from org.apache.pdfbox.contentstream.PDFStreamEngine.beginMarkedContentSequence.

Called when a marked content group begins

Parameters
tag:COSName

indicates the role or significance of the sequence

properties:COSDictionary

optional properties

Annotations
@Override
endMarkedContentSequenceback to summary
public void endMarkedContentSequence()

Overrides org.apache.pdfbox.contentstream.PDFStreamEngine.endMarkedContentSequence.

Doc from org.apache.pdfbox.contentstream.PDFStreamEngine.endMarkedContentSequence.

Called when a marked content group ends

Annotations
@Override
getMarkedContentsback to summary
public List<PDMarkedContent> getMarkedContents()
isSuppressDuplicateOverlappingTextback to summary
public boolean isSuppressDuplicateOverlappingText()
Returns:boolean

the suppressDuplicateOverlappingText setting.

processTextPositionback to summary
protected void processTextPosition(TextPosition text)

Overrides org.apache.pdfbox.text.LegacyPDFStreamEngine.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
setSuppressDuplicateOverlappingTextback to summary
public void setSuppressDuplicateOverlappingText(boolean suppressDuplicateOverlappingText)

By default the class will attempt to remove text that overlaps 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.

Parameters
suppressDuplicateOverlappingText:boolean

The suppressDuplicateOverlappingText setting to set.

withinback to summary
private boolean within(float first, float second, float variance)

This will determine of two floating point numbers are within a specified variance.

Parameters
first:float

The first number to compare to.

second:float

The second number to compare to.

variance:float

The allowed variance.

xobjectback to summary
public void xobject(PDXObject xobject)