Class PDAbstractAppearanceHandler

    • Field Detail

      • SHORT_STYLES

        protected static final java.util.Set<java.lang.String> SHORT_STYLES
        Line ending styles where the line has to be drawn shorter (minus line width).
      • ARROW_ANGLE

        static final double ARROW_ANGLE
      • INTERIOR_COLOR_STYLES

        protected static final java.util.Set<java.lang.String> INTERIOR_COLOR_STYLES
        Line ending styles where there is an interior color.
      • ANGLED_STYLES

        protected static final java.util.Set<java.lang.String> ANGLED_STYLES
        Line ending styles where the shape changes its angle, e.g. arrows.
    • Constructor Detail

      • PDAbstractAppearanceHandler

        public PDAbstractAppearanceHandler​(PDAnnotation annotation)
      • PDAbstractAppearanceHandler

        public PDAbstractAppearanceHandler​(PDAnnotation annotation,
                                           PDDocument document)
    • Method Detail

      • createCOSStream

        protected COSStream createCOSStream()
      • getAppearance

        PDAppearanceDictionary getAppearance()
        Get the annotations appearance dictionary.

        This will get the annotations appearance dictionary. If this is not existent an empty appearance dictionary will be created.

        Returns:
        the annotations appearance dictionary
      • getNormalAppearanceAsContentStream

        PDAppearanceContentStream getNormalAppearanceAsContentStream()
                                                              throws java.io.IOException
        Get the annotations normal appearance content stream.

        This will get the annotations normal appearance content stream, to 'draw' to. It will be uncompressed.

        Returns:
        the appearance entry representing the normal appearance.
        Throws:
        java.io.IOException
      • getNormalAppearanceAsContentStream

        PDAppearanceContentStream getNormalAppearanceAsContentStream​(boolean compress)
                                                              throws java.io.IOException
        Get the annotations normal appearance content stream.

        This will get the annotations normal appearance content stream, to 'draw' to.

        Parameters:
        compress - whether the content stream is to be compressed. Set this to true when creating long content streams.
        Returns:
        the appearance entry representing the normal appearance.
        Throws:
        java.io.IOException
      • getDownAppearance

        PDAppearanceEntry getDownAppearance()
        Get the annotations down appearance.

        This will get the annotations down appearance. If this is not existent an empty appearance entry will be created.

        Returns:
        the appearance entry representing the down appearance.
      • getRolloverAppearance

        PDAppearanceEntry getRolloverAppearance()
        Get the annotations rollover appearance.

        This will get the annotations rollover appearance. If this is not existent an empty appearance entry will be created.

        Returns:
        the appearance entry representing the rollover appearance.
      • getPaddedRectangle

        PDRectangle getPaddedRectangle​(PDRectangle rectangle,
                                       float padding)
        Get a padded rectangle.

        Creates a new rectangle with padding applied to each side. .

        Parameters:
        rectangle - the rectangle.
        padding - the padding to apply.
        Returns:
        the padded rectangle.
      • addRectDifferences

        PDRectangle addRectDifferences​(PDRectangle rectangle,
                                       float[] differences)
        Get a rectangle enlarged by the differences.

        Creates a new rectangle with differences added to each side. If there are no valid differences, then the original rectangle is returned.

        Parameters:
        rectangle - the rectangle.
        differences - the differences to apply.
        Returns:
        the padded rectangle.
      • applyRectDifferences

        PDRectangle applyRectDifferences​(PDRectangle rectangle,
                                         float[] differences)
        Get a rectangle with the differences applied to each side.

        Creates a new rectangle with differences added to each side. If there are no valid differences, then the original rectangle is returned.

        Parameters:
        rectangle - the rectangle.
        differences - the differences to apply.
        Returns:
        the padded rectangle.
      • setOpacity

        void setOpacity​(PDAppearanceContentStream contentStream,
                        float opacity)
                 throws java.io.IOException
        Throws:
        java.io.IOException
      • drawStyle

        void drawStyle​(java.lang.String style,
                       PDAppearanceContentStream cs,
                       float x,
                       float y,
                       float width,
                       boolean hasStroke,
                       boolean hasBackground,
                       boolean ending)
                throws java.io.IOException
        Draw a line ending style.
        Parameters:
        style -
        cs -
        x -
        y -
        width -
        hasStroke -
        hasBackground -
        ending - false if left, true if right of an imagined horizontal line (important for arrows).
        Throws:
        java.io.IOException
      • drawArrow

        void drawArrow​(PDAppearanceContentStream cs,
                       float x,
                       float y,
                       float len)
                throws java.io.IOException
        Add the two arms of a horizontal arrow.
        Parameters:
        cs - Content stream
        x -
        y -
        len - The arm length. Positive goes to the right, negative goes to the left.
        Throws:
        java.io.IOException - If the content stream could not be written
      • drawDiamond

        void drawDiamond​(PDAppearanceContentStream cs,
                         float x,
                         float y,
                         float r)
                  throws java.io.IOException
        Add a square diamond shape (corner on top) to the path.
        Parameters:
        cs - Content stream
        x -
        y -
        r - Radius (to a corner)
        Throws:
        java.io.IOException - If the content stream could not be written
      • drawCircle

        void drawCircle​(PDAppearanceContentStream cs,
                        float x,
                        float y,
                        float r)
                 throws java.io.IOException
        Add a circle shape to the path in clockwise direction.
        Parameters:
        cs - Content stream
        x -
        y -
        r - Radius
        Throws:
        java.io.IOException - If the content stream could not be written.
      • drawCircle2

        void drawCircle2​(PDAppearanceContentStream cs,
                         float x,
                         float y,
                         float r)
                  throws java.io.IOException
        Add a circle shape to the path in counterclockwise direction. You'll need this e.g. when drawing a doughnut shape. See "Nonzero Winding Number Rule" for more information.
        Parameters:
        cs - Content stream
        x -
        y -
        r - Radius
        Throws:
        java.io.IOException - If the content stream could not be written.
      • createShortStyles

        private static java.util.Set<java.lang.String> createShortStyles()
      • createInteriorColorStyles

        private static java.util.Set<java.lang.String> createInteriorColorStyles()
      • createAngledStyles

        private static java.util.Set<java.lang.String> createAngledStyles()
      • getNormalAppearance

        private PDAppearanceEntry getNormalAppearance()
        Get the annotations normal appearance.

        This will get the annotations normal appearance. If this is not existent an empty appearance entry will be created.

        Returns:
        the appearance entry representing the normal appearance.
      • getAppearanceEntryAsContentStream

        private PDAppearanceContentStream getAppearanceEntryAsContentStream​(PDAppearanceEntry appearanceEntry,
                                                                            boolean compress)
                                                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • setTransformationMatrix

        private void setTransformationMatrix​(PDAppearanceStream appearanceStream)