Class PDDefaultAppearanceString

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

class PDDefaultAppearanceString extends Object
Represents a default appearance string, as found in the /DA entry of free text annotations.

The default appearance string (DA) contains any graphics state or text state operators needed to establish the graphics state parameters, such as text size and colour, for displaying the field’s variable text. Only operators that are allowed within text objects shall occur in this string. Note: This class is not yet public, as its API is still unstable.

  • Field Details

    • DEFAULT_FONT_SIZE

      private static final float DEFAULT_FONT_SIZE
      The default font size used by Acrobat.
      See Also:
    • defaultResources

      private final PDResources defaultResources
    • fontName

      private COSName fontName
    • font

      private PDFont font
    • fontSize

      private float fontSize
    • fontColor

      private PDColor fontColor
  • Constructor Details

    • PDDefaultAppearanceString

      PDDefaultAppearanceString(COSString defaultAppearance, PDResources defaultResources) throws IOException
      Constructor for reading an existing DA string.
      Parameters:
      defaultResources - DR entry
      defaultAppearance - DA entry
      Throws:
      IOException - If the DA could not be parsed
  • Method Details

    • processAppearanceStringOperators

      private void processAppearanceStringOperators(byte[] content) throws IOException
      Processes the operators of the given content stream.
      Parameters:
      content - the content to parse.
      Throws:
      IOException - if there is an error reading or parsing the content stream.
    • processOperator

      private void processOperator(Operator operator, List<COSBase> operands) throws IOException
      This is used to handle an operation.
      Parameters:
      operator - The operation to perform.
      operands - The list of arguments.
      Throws:
      IOException - If there is an error processing the operation.
    • processSetFont

      private void processSetFont(List<COSBase> operands) throws IOException
      Process the set font and font size operator.
      Parameters:
      operands - the font name and size
      Throws:
      IOException - in case there are missing operators or the font is not within the resources
    • processSetFontColor

      private void processSetFontColor(List<COSBase> operands) throws IOException
      Process the font color operator. This is assumed to be an RGB color.
      Parameters:
      operands - the color components
      Throws:
      IOException - in case of the color components not matching
    • getFontName

      COSName getFontName()
      Get the font name
      Returns:
      the font name to use for resource lookup
    • setFontName

      void setFontName(COSName fontName)
      Set the font name.
      Parameters:
      fontName - the font name to use for resource lookup
    • getFont

      PDFont getFont()
      Returns the font.
    • setFont

      void setFont(PDFont font)
      Set the font.
      Parameters:
      font - the font to use.
    • getFontSize

      public float getFontSize()
      Returns the font size.
    • setFontSize

      void setFontSize(float fontSize)
      Set the font size.
      Parameters:
      fontSize - the font size.
    • getFontColor

      PDColor getFontColor()
      Returns the font color
    • setFontColor

      void setFontColor(PDColor fontColor)
      Set the font color.
      Parameters:
      fontColor - the fontColor to use.
    • writeTo

      void writeTo(PDPageContentStream contents, float zeroFontSize) throws IOException
      Writes the DA string to the given content stream.
      Throws:
      IOException
    • copyNeededResourcesTo

      void copyNeededResourcesTo(PDAppearanceStream appearanceStream) throws IOException
      Copies any needed resources from the document’s DR dictionary into the stream’s Resources dictionary. Resources with the same name shall be left intact.
      Throws:
      IOException