Class DrawPrintTextLocations


  • public class DrawPrintTextLocations
    extends PDFTextStripper
    This is an example on how to get some x/y coordinates of text and to show them in a rendered image.
    • Field Detail

      • flipAT

        private java.awt.geom.AffineTransform flipAT
      • rotateAT

        private java.awt.geom.AffineTransform rotateAT
      • transAT

        private java.awt.geom.AffineTransform transAT
      • filename

        private final java.lang.String filename
      • g2d

        private java.awt.Graphics2D g2d
    • Constructor Detail

      • DrawPrintTextLocations

        public DrawPrintTextLocations​(PDDocument document,
                                      java.lang.String filename)
                               throws java.io.IOException
        Instantiate a new PDFTextStripper object.
        Parameters:
        document -
        filename -
        Throws:
        java.io.IOException - If there is an error loading the properties.
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
                         throws java.io.IOException
        This will print the documents data.
        Parameters:
        args - The command line arguments.
        Throws:
        java.io.IOException - If there is an error parsing the document.
      • showGlyph

        protected void showGlyph​(Matrix textRenderingMatrix,
                                 PDFont font,
                                 int code,
                                 Vector displacement)
                          throws java.io.IOException
        Description copied from class: LegacyPDFStreamEngine
        Called when a glyph is to be processed. The heuristic calculations here were originally written by Ben Litchfield for PDFStreamEngine.
        Overrides:
        showGlyph in class LegacyPDFStreamEngine
        Parameters:
        textRenderingMatrix - the current text rendering matrix, Trm
        font - the current font
        code - internal PDF character code for the glyph
        displacement - the displacement (i.e. advance) of the glyph in text space
        Throws:
        java.io.IOException - if the glyph cannot be processed
      • calculateGlyphBounds

        private java.awt.Shape calculateGlyphBounds​(Matrix textRenderingMatrix,
                                                    PDFont font,
                                                    int code)
                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • stripPage

        private void stripPage​(int page)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • writeString

        protected void writeString​(java.lang.String string,
                                   java.util.List<TextPosition> textPositions)
                            throws java.io.IOException
        Override the default functionality of PDFTextStripper.
        Overrides:
        writeString in class PDFTextStripper
        Parameters:
        string - The text to write to the stream.
        textPositions - The TextPositions belonging to the text.
        Throws:
        java.io.IOException - If there is an error when writing the text.
      • usage

        private static void usage()
        This will print the usage for this document.