Class PDAbstractAppearanceHandler

java.lang.Object
org.apache.pdfbox.pdmodel.interactive.annotation.handlers.PDAbstractAppearanceHandler
All Implemented Interfaces:
PDAppearanceHandler
Direct Known Subclasses:
PDCaretAppearanceHandler, PDCircleAppearanceHandler, PDFileAttachmentAppearanceHandler, PDFreeTextAppearanceHandler, PDHighlightAppearanceHandler, PDInkAppearanceHandler, PDLineAppearanceHandler, PDLinkAppearanceHandler, PDPolygonAppearanceHandler, PDPolylineAppearanceHandler, PDSoundAppearanceHandler, PDSquareAppearanceHandler, PDSquigglyAppearanceHandler, PDStrikeoutAppearanceHandler, PDTextAppearanceHandler, PDUnderlineAppearanceHandler

public abstract class PDAbstractAppearanceHandler extends Object implements PDAppearanceHandler
Generic handler to generate the fields appearance. Individual handler will provide specific implementations for different field types.
  • Field Details

    • annotation

      private final PDAnnotation annotation
    • document

      protected PDDocument document
    • SHORT_STYLES

      protected static final Set<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 Set<String> INTERIOR_COLOR_STYLES
      Line ending styles where there is an interior color.
    • ANGLED_STYLES

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

    • PDAbstractAppearanceHandler

      public PDAbstractAppearanceHandler(PDAnnotation annotation)
    • PDAbstractAppearanceHandler

      public PDAbstractAppearanceHandler(PDAnnotation annotation, PDDocument document)
  • Method Details

    • getAnnotation

      PDAnnotation getAnnotation()
    • getColor

      PDColor getColor()
    • getRectangle

      PDRectangle getRectangle()
    • 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 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:
      IOException
    • getNormalAppearanceAsContentStream

      PDAppearanceContentStream getNormalAppearanceAsContentStream(boolean compress) throws 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:
      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 IOException
      Throws:
      IOException
    • drawStyle

      void drawStyle(String style, PDAppearanceContentStream cs, float x, float y, float width, boolean hasStroke, boolean hasBackground, boolean ending) throws 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:
      IOException
    • drawArrow

      void drawArrow(PDAppearanceContentStream cs, float x, float y, float len) throws 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:
      IOException - If the content stream could not be written
    • drawDiamond

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

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

      void drawCircle2(PDAppearanceContentStream cs, float x, float y, float r) throws 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:
      IOException - If the content stream could not be written.
    • createShortStyles

      private static Set<String> createShortStyles()
    • createInteriorColorStyles

      private static Set<String> createInteriorColorStyles()
    • createAngledStyles

      private static Set<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 IOException
      Throws:
      IOException
    • setTransformationMatrix

      private void setTransformationMatrix(PDAppearanceStream appearanceStream)
    • handleBorderBox

      PDRectangle handleBorderBox(PDAnnotationSquareCircle annotation, float lineWidth)