Package org.apache.pdfbox.examples.util
Class DrawPrintTextLocations
java.lang.Object
org.apache.pdfbox.contentstream.PDFStreamEngine
org.apache.pdfbox.text.LegacyPDFStreamEngine
org.apache.pdfbox.text.PDFTextStripper
org.apache.pdfbox.examples.util.DrawPrintTextLocations
This is an example on how to get some x/y coordinates of text and to show them in a rendered
image.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Stringprivate AffineTransformprivate Graphics2Dprivate AffineTransform(package private) static final intprivate AffineTransformFields inherited from class org.apache.pdfbox.text.PDFTextStripper
charactersByArticle, document, LINE_SEPARATOR, output -
Constructor Summary
ConstructorsConstructorDescriptionDrawPrintTextLocations(PDDocument document, String filename) Instantiate a new PDFTextStripper object. -
Method Summary
Modifier and TypeMethodDescriptionprivate ShapecalculateGlyphBounds(Matrix textRenderingMatrix, PDFont font, int code) static voidThis will print the documents data.protected voidCalled when a glyph is to be processed.private voidstripPage(int page) private static voidusage()This will print the usage for this document.protected voidwriteString(String string, List<TextPosition> textPositions) Override the default functionality of PDFTextStripper.Methods inherited from class org.apache.pdfbox.text.PDFTextStripper
beginMarkedContentSequence, endArticle, endDocument, endMarkedContentSequence, endPage, getAddMoreFormatting, getArticleEnd, getArticleStart, getAverageCharTolerance, getCharactersByArticle, getCurrentPageNo, getDropThreshold, getEndBookmark, getEndPage, getIgnoreContentStreamSpaceGlyphs, getIndentThreshold, getLineSeparator, getListItemPatterns, getOutput, getPageEnd, getPageStart, getParagraphEnd, getParagraphStart, getSeparateByBeads, getSortByPosition, getSpacingTolerance, getStartBookmark, getStartPage, getSuppressDuplicateOverlappingText, getText, getWordSeparator, matchPattern, processPage, processPages, processTextPosition, setAddMoreFormatting, setArticleEnd, setArticleStart, setAverageCharTolerance, setDropThreshold, setEndBookmark, setEndPage, setIgnoreContentStreamSpaceGlyphs, setIndentThreshold, setLineSeparator, setListItemPatterns, setPageEnd, setPageStart, setParagraphEnd, setParagraphStart, setShouldSeparateByBeads, setSortByPosition, setSpacingTolerance, setStartBookmark, setStartPage, setSuppressDuplicateOverlappingText, setWordSeparator, startArticle, startArticle, startDocument, startPage, writeCharacters, writeLineSeparator, writePage, writePageEnd, writePageStart, writeParagraphEnd, writeParagraphSeparator, writeParagraphStart, writeString, writeText, writeWordSeparatorMethods inherited from class org.apache.pdfbox.text.LegacyPDFStreamEngine
computeFontHeightMethods inherited from class org.apache.pdfbox.contentstream.PDFStreamEngine
addOperator, applyTextAdjustment, beginText, decreaseLevel, endText, getAppearance, getCurrentPage, getGraphicsStackSize, getGraphicsState, getInitialMatrix, getLevel, getResources, getTextLineMatrix, getTextMatrix, increaseLevel, isShouldProcessColorOperators, markedContentPoint, 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 Details
-
flipAT
-
rotateAT
-
transAT
-
filename
-
SCALE
static final int SCALE- See Also:
-
g2d
-
-
Constructor Details
-
DrawPrintTextLocations
Instantiate a new PDFTextStripper object.- Parameters:
document-filename-- Throws:
IOException- If there is an error loading the properties.
-
-
Method Details
-
main
This will print the documents data.- Parameters:
args- The command line arguments.- Throws:
IOException- If there is an error parsing the document.
-
showGlyph
protected void showGlyph(Matrix textRenderingMatrix, PDFont font, int code, Vector displacement) throws IOException Description copied from class:LegacyPDFStreamEngineCalled when a glyph is to be processed. The heuristic calculations here were originally written by Ben Litchfield for PDFStreamEngine.- Overrides:
showGlyphin classLegacyPDFStreamEngine- Parameters:
textRenderingMatrix- the current text rendering matrix, Trmfont- the current fontcode- internal PDF character code for the glyphdisplacement- the displacement (i.e. advance) of the glyph in text space- Throws:
IOException- if the glyph cannot be processed
-
calculateGlyphBounds
private Shape calculateGlyphBounds(Matrix textRenderingMatrix, PDFont font, int code) throws IOException - Throws:
IOException
-
stripPage
- Throws:
IOException
-
writeString
Override the default functionality of PDFTextStripper.- Overrides:
writeStringin classPDFTextStripper- Parameters:
string- The text to write to the stream.textPositions- The TextPositions belonging to the text.- Throws:
IOException- If there is an error when writing the text.
-
usage
private static void usage()This will print the usage for this document.
-