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

public Class DrawPrintTextLocations

extends PDFTextStripper
Class Inheritance
Imports
java.awt.BasicStroke, .Color, .Graphics2D, .Shape, java.awt.geom.AffineTransform, .GeneralPath, .Rectangle2D, java.awt.image.BufferedImage, java.io.ByteArrayOutputStream, .File, .IOException, .OutputStreamWriter, .Writer, java.util.List, javax.imageio.ImageIO, org.apache.fontbox.util.BoundingBox, org.apache.pdfbox.Loader, org.apache.pdfbox.pdmodel.PDDocument, .PDPage, org.apache.pdfbox.pdmodel.common.PDRectangle, org.apache.pdfbox.pdmodel.font.PDCIDFontType2, .PDFont, .PDTrueTypeFont, .PDType0Font, .PDType3CharProc, .PDType3Font, .PDVectorFont, org.apache.pdfbox.pdmodel.interactive.pagenavigation.PDThreadBead, org.apache.pdfbox.rendering.PDFRenderer, org.apache.pdfbox.text.PDFTextStripper, .TextPosition, org.apache.pdfbox.util.Matrix, .Vector

This is an example on how to get some x/y coordinates of text and to show them in a rendered image.
Authors
Ben Litchfield, Tilman Hausherr

Field Summary

Modifier and TypeField and Description
private final String
private AffineTransform
private Graphics2D
private AffineTransform
pack-priv static final int
private AffineTransform
Inherited from org.apache.pdfbox.text.PDFTextStripper:
charactersByArticledocumentLINE_SEPARATORoutput

Constructor Summary

AccessConstructor and Description
public
DrawPrintTextLocations(PDDocument document, String filename)

Instantiate a new PDFTextStripper object.

Method Summary

Modifier and TypeMethod and Description
private Shape
calculateGlyphBounds(Matrix textRenderingMatrix, PDFont font, int code)

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

This will print the documents data.

protected void
showGlyph(Matrix
the current text rendering matrix, Trm
textRenderingMatrix
,
PDFont
the current font
font
,
int
internal PDF character code for the glyph
code
,
Vector
the displacement (i.e. advance) of the glyph in text space
displacement
)

Overrides org.apache.pdfbox.text.LegacyPDFStreamEngine.showGlyph.

Called when a glyph is to be processed.

private void
stripPage(int page)

private static void
usage()

This will print the usage for this document.

protected void
writeString(String
The text to write to the stream.
string
,
List<TextPosition>
The TextPositions belonging to the text.
textPositions
)

Overrides org.apache.pdfbox.text.PDFTextStripper.writeString.

Override the default functionality of PDFTextStripper.

Inherited from org.apache.pdfbox.text.PDFTextStripper:
beginMarkedContentSequenceendArticleendDocumentendMarkedContentSequenceendPagegetAddMoreFormattinggetArticleEndgetArticleStartgetAverageCharTolerancegetCharactersByArticlegetCurrentPageNogetDropThresholdgetEndBookmarkgetEndPagegetIgnoreContentStreamSpaceGlyphsgetIndentThresholdgetLineSeparatorgetListItemPatternsgetOutputgetPageEndgetPageStartgetParagraphEndgetParagraphStartgetSeparateByBeadsgetSortByPositiongetSpacingTolerancegetStartBookmarkgetStartPagegetSuppressDuplicateOverlappingTextgetTextgetWordSeparatormatchPatternprocessPageprocessPagesprocessTextPositionsetAddMoreFormattingsetArticleEndsetArticleStartsetAverageCharTolerancesetDropThresholdsetEndBookmarksetEndPagesetIgnoreContentStreamSpaceGlyphssetIndentThresholdsetLineSeparatorsetListItemPatternssetPageEndsetPageStartsetParagraphEndsetParagraphStartsetShouldSeparateByBeadssetSortByPositionsetSpacingTolerancesetStartBookmarksetStartPagesetSuppressDuplicateOverlappingTextsetWordSeparatorstartArticlestartArticlestartDocumentstartPagewriteCharacterswriteLineSeparatorwritePagewritePageEndwritePageStartwriteParagraphEndwriteParagraphSeparatorwriteParagraphStartwriteStringwriteTextwriteWordSeparator

Field Detail

filenameback to summary
private final String filename
flipATback to summary
private AffineTransform flipAT
g2dback to summary
private Graphics2D g2d
rotateATback to summary
private AffineTransform rotateAT
SCALEback to summary
pack-priv static final int SCALE
transATback to summary
private AffineTransform transAT

Constructor Detail

DrawPrintTextLocationsback to summary
public DrawPrintTextLocations(PDDocument document, String filename) throws IOException

Instantiate a new PDFTextStripper object.

Exceptions
IOException:
If there is an error loading the properties.

Method Detail

calculateGlyphBoundsback to summary
private Shape calculateGlyphBounds(Matrix textRenderingMatrix, PDFont font, int code) throws IOException
mainback to summary
public static void main(String[] args) throws IOException

This will print the documents data.

Parameters
args:String[]

The command line arguments.

Exceptions
IOException:
If there is an error parsing the document.
showGlyphback to summary
protected void showGlyph(Matrix textRenderingMatrix, PDFont font, int code, Vector displacement) throws IOException

Overrides org.apache.pdfbox.text.LegacyPDFStreamEngine.showGlyph.

Doc from org.apache.pdfbox.text.LegacyPDFStreamEngine.showGlyph.

Called when a glyph is to be processed. The heuristic calculations here were originally written by Ben Litchfield for PDFStreamEngine.

Parameters
textRenderingMatrix:Matrix

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

the current text rendering matrix, Trm

font:PDFont

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

the current font

code:int

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

internal PDF character code for the glyph

displacement:Vector

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

the displacement (i.e. advance) of the glyph in text space

Annotations
@Override
Exceptions
IOException:

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

if the glyph cannot be processed

stripPageback to summary
private void stripPage(int page) throws IOException
usageback to summary
private static void usage()

This will print the usage for this document.

writeStringback to summary
protected void writeString(String string, List<TextPosition> textPositions) throws IOException

Overrides org.apache.pdfbox.text.PDFTextStripper.writeString.

Override the default functionality of PDFTextStripper.

Parameters
string:String

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

The text to write to the stream.

textPositions:List<TextPosition>

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

The TextPositions belonging to the text.

Annotations
@Override
Exceptions
IOException:

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

If there is an error when writing the text.