Class AppearanceGeneratorHelper

java.lang.Object
org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper

class AppearanceGeneratorHelper extends Object
Create the AcroForms field appearance helper.
  • Field Details

    • LOG

      private static final org.apache.commons.logging.Log LOG
    • BMC

      private static final Operator BMC
    • EMC

      private static final Operator EMC
    • field

      private final PDVariableText field
    • defaultAppearance

      private PDDefaultAppearanceString defaultAppearance
    • value

      private String value
    • HIGHLIGHT_COLOR

      private static final float[] HIGHLIGHT_COLOR
      The highlight color The color setting is used by Adobe to display the highlight box for selected entries in a list box. Regardless of other settings in an existing appearance stream Adobe will always use this value.
    • FONTSCALE

      private static final int FONTSCALE
      The scaling factor for font units to PDF units
      See Also:
    • DEFAULT_FONT_SIZE

      private static final float DEFAULT_FONT_SIZE
      The default font size used for multiline text
      See Also:
    • MINIMUM_FONT_SIZE

      private static final float MINIMUM_FONT_SIZE
      The minimum/maximum font sizes used for multiline text auto sizing
      See Also:
    • MAXIMUM_FONT_SIZE

      private static final float MAXIMUM_FONT_SIZE
      See Also:
    • DEFAULT_PADDING

      private static final float DEFAULT_PADDING
      The default padding applied by Acrobat to the fields bbox.
      See Also:
  • Constructor Details

    • AppearanceGeneratorHelper

      AppearanceGeneratorHelper(PDVariableText field) throws IOException
      Constructs a COSAppearance from the given field.
      Parameters:
      field - the field which you wish to control the appearance of
      Throws:
      IOException
  • Method Details

    • validateAndEnsureAcroFormResources

      private void validateAndEnsureAcroFormResources()
    • setAppearanceValue

      public void setAppearanceValue(String apValue) throws IOException
      This is the public method for setting the appearance stream.
      Parameters:
      apValue - the String value which the appearance should represent
      Throws:
      IOException - If there is an error creating the stream.
    • getFormattedValue

      private String getFormattedValue(String apValue)
    • isValidAppearanceStream

      private static boolean isValidAppearanceStream(PDAppearanceEntry appearance)
    • prepareNormalAppearanceStream

      private PDAppearanceStream prepareNormalAppearanceStream(PDAnnotationWidget widget)
    • getWidgetDefaultAppearanceString

      private PDDefaultAppearanceString getWidgetDefaultAppearanceString(PDAnnotationWidget widget) throws IOException
      Throws:
      IOException
    • resolveRotation

      private int resolveRotation(PDAnnotationWidget widget)
    • initializeAppearanceContent

      private void initializeAppearanceContent(PDAnnotationWidget widget, PDAppearanceCharacteristicsDictionary appearanceCharacteristics, PDAppearanceStream appearanceStream) throws IOException
      Initialize the content of the appearance stream. Get settings like border style, border width and colors to be used to draw a rectangle and background color around the widget
      Parameters:
      widget - the field widget
      appearanceStream - the appearance stream to be used
      appearanceCharacteristics - the appearance characteristics dictionary from the widget or null
      Throws:
      IOException - in case we can't write to the appearance stream
    • tokenize

      private List<Object> tokenize(PDAppearanceStream appearanceStream) throws IOException
      Parses an appearance stream into tokens.
      Throws:
      IOException
    • setAppearanceContent

      private void setAppearanceContent(PDAnnotationWidget widget, PDAppearanceStream appearanceStream) throws IOException
      Constructs and sets new contents for given appearance stream.
      Throws:
      IOException
    • insertGeneratedAppearance

      private void insertGeneratedAppearance(PDAnnotationWidget widget, PDAppearanceStream appearanceStream, OutputStream output) throws IOException
      Generate and insert text content and clipping around it.
      Throws:
      IOException
    • getTextAlign

      private int getTextAlign(PDAnnotationWidget widget)
    • calculateMatrix

      private AffineTransform calculateMatrix(PDRectangle bbox, int rotation)
    • isMultiLine

      private boolean isMultiLine()
    • shallComb

      private boolean shallComb()
      Determine if the appearance shall provide a comb output.

      May be set only if the MaxLen entry is present in the text field dictionary and if the Multiline, Password, and FileSelect flags are clear. If set, the field shall be automatically divided into as many equally spaced positions, or combs, as the value of MaxLen, and the text is laid out into those combs.

      Returns:
      the comb state
    • insertGeneratedCombAppearance

      private void insertGeneratedCombAppearance(PDPageContentStream contents, PDAppearanceStream appearanceStream, PDFont font, float fontSize) throws IOException
      Generate the appearance for comb fields.
      Parameters:
      contents - the content stream to write to
      appearanceStream - the appearance stream used
      font - the font to be used
      fontSize - the font size to be used
      Throws:
      IOException
    • insertGeneratedListboxSelectionHighlight

      private void insertGeneratedListboxSelectionHighlight(PDPageContentStream contents, PDAppearanceStream appearanceStream, PDFont font, float fontSize) throws IOException
      Throws:
      IOException
    • insertGeneratedListboxAppearance

      private void insertGeneratedListboxAppearance(PDPageContentStream contents, PDAppearanceStream appearanceStream, PDRectangle contentRect, PDFont font, float fontSize) throws IOException
      Throws:
      IOException
    • writeToStream

      private void writeToStream(byte[] data, PDAppearanceStream appearanceStream) throws IOException
      Writes the stream to the actual stream in the COSStream.
      Throws:
      IOException - If there is an error writing to the stream
    • calculateFontSize

      private float calculateFontSize(PDFont font, PDRectangle contentRect) throws IOException
      My "not so great" method for calculating the fontsize. It does not work superb, but it handles ok.
      Returns:
      the calculated font-size
      Throws:
      IOException - If there is an error getting the font information.
    • resolveCapHeight

      private float resolveCapHeight(PDFont font) throws IOException
      Throws:
      IOException
    • resolveDescent

      private float resolveDescent(PDFont font) throws IOException
      Throws:
      IOException
    • resolveGlyphHeight

      private float resolveGlyphHeight(PDFont font, int code) throws IOException
      Throws:
      IOException
    • resolveBoundingBox

      private PDRectangle resolveBoundingBox(PDAnnotationWidget fieldWidget, PDAppearanceStream appearanceStream)
      Resolve the bounding box.
      Parameters:
      fieldWidget - the annotation widget.
      appearanceStream - the annotations appearance stream.
      Returns:
      the resolved boundingBox.
    • applyPadding

      private PDRectangle applyPadding(PDRectangle box, float padding)
      Apply padding to a box.
      Parameters:
      box - box
      Returns:
      the padded box.