Package org.apache.pdfbox.text
Class PDFMarkedContentExtractor
- java.lang.Object
-
- org.apache.pdfbox.contentstream.PDFStreamEngine
-
- org.apache.pdfbox.text.LegacyPDFStreamEngine
-
- org.apache.pdfbox.text.PDFMarkedContentExtractor
-
public class PDFMarkedContentExtractor extends LegacyPDFStreamEngine
This is an stream engine to extract the marked content of a pdf.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.util.List<TextPosition>>characterListMappingprivate java.util.Deque<PDMarkedContent>currentMarkedContentsprivate java.util.List<PDMarkedContent>markedContentsprivate booleansuppressDuplicateOverlappingText
-
Constructor Summary
Constructors Constructor Description PDFMarkedContentExtractor()Instantiate a new PDFMarkedContentExtractor object.PDFMarkedContentExtractor(java.lang.String encoding)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeginMarkedContentSequence(COSName tag, COSDictionary properties)Called when a marked content group beginsvoidendMarkedContentSequence()Called when a marked content group endsjava.util.List<PDMarkedContent>getMarkedContents()booleanisSuppressDuplicateOverlappingText()voidmarkedContentPoint(COSName tag, COSDictionary properties)Handles MP and DP operators.protected voidprocessTextPosition(TextPosition text)This will process a TextPosition object and add the text to the list of characters on a page.voidsetSuppressDuplicateOverlappingText(boolean suppressDuplicateOverlappingText)By default the class will attempt to remove text that overlaps each other.private booleanwithin(float first, float second, float variance)This will determine of two floating point numbers are within a specified variance.voidxobject(PDXObject xobject)-
Methods inherited from class org.apache.pdfbox.text.LegacyPDFStreamEngine
computeFontHeight, processPage, showGlyph
-
Methods inherited from class org.apache.pdfbox.contentstream.PDFStreamEngine
addOperator, applyTextAdjustment, beginText, decreaseLevel, endText, getAppearance, getCurrentPage, getGraphicsStackSize, getGraphicsState, getInitialMatrix, getLevel, getResources, getTextLineMatrix, getTextMatrix, increaseLevel, isShouldProcessColorOperators, operatorException, processAnnotation, processChildStream, processOperator, processOperator, processSoftMask, processTilingPattern, processTilingPattern, processTransparencyGroup, processType3Stream, restoreGraphicsStack, restoreGraphicsState, saveGraphicsStack, saveGraphicsState, setLineDashPattern, setTextLineMatrix, setTextMatrix, showAnnotation, showFontGlyph, showForm, showText, showTextString, showTextStrings, showTransparencyGroup, showType3Glyph, transformedPoint, transformWidth, unsupportedOperator
-
-
-
-
Field Detail
-
suppressDuplicateOverlappingText
private boolean suppressDuplicateOverlappingText
-
markedContents
private final java.util.List<PDMarkedContent> markedContents
-
currentMarkedContents
private final java.util.Deque<PDMarkedContent> currentMarkedContents
-
characterListMapping
private final java.util.Map<java.lang.String,java.util.List<TextPosition>> characterListMapping
-
-
Constructor Detail
-
PDFMarkedContentExtractor
public PDFMarkedContentExtractor()
Instantiate a new PDFMarkedContentExtractor object.
-
PDFMarkedContentExtractor
public PDFMarkedContentExtractor(java.lang.String encoding)
Constructor. Will apply encoding-specific conversions to the output text.- Parameters:
encoding- The encoding that the output will be written in.
-
-
Method Detail
-
isSuppressDuplicateOverlappingText
public boolean isSuppressDuplicateOverlappingText()
- Returns:
- the suppressDuplicateOverlappingText setting.
-
setSuppressDuplicateOverlappingText
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- The suppressDuplicateOverlappingText setting to set.
-
within
private boolean within(float first, float second, float variance)This will determine of two floating point numbers are within a specified variance.- Parameters:
first- The first number to compare to.second- The second number to compare to.variance- The allowed variance.
-
beginMarkedContentSequence
public void beginMarkedContentSequence(COSName tag, COSDictionary properties)
Description copied from class:PDFStreamEngineCalled when a marked content group begins- Overrides:
beginMarkedContentSequencein classPDFStreamEngine- Parameters:
tag- indicates the role or significance of the sequenceproperties- optional properties
-
endMarkedContentSequence
public void endMarkedContentSequence()
Description copied from class:PDFStreamEngineCalled when a marked content group ends- Overrides:
endMarkedContentSequencein classPDFStreamEngine
-
markedContentPoint
public void markedContentPoint(COSName tag, COSDictionary properties)
Description copied from class:PDFStreamEngineHandles MP and DP operators.- Overrides:
markedContentPointin classPDFStreamEngine- Parameters:
tag- indicates the role or significance of the sequenceproperties- optional properties
-
xobject
public void xobject(PDXObject xobject)
-
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:
processTextPositionin classLegacyPDFStreamEngine- Parameters:
text- The text to process.
-
getMarkedContents
public java.util.List<PDMarkedContent> getMarkedContents()
-
-