Class AnnotationText

  • All Implemented Interfaces:
    Cloneable

    public final class AnnotationText
    extends PDFAnnotation
    This class represents the type of PDFAnnotation created by the "Text Markup" tool in Acrobat. This is simply a box which may contain one or more lines of text.
    Since:
    2.3.7
    • Constructor Detail

      • AnnotationText

        public AnnotationText()
        Create a new Text annotation
    • Method Detail

      • setContents

        public void setContents​(String content)
        Set the contents of the annotation. If there is any rich-text Content, this method will overwrite it.
        Overrides:
        setContents in class PDFAnnotation
        Parameters:
        content - the content of the Text annotation. May contain "\n" characters to indicate newlines
      • setRichTextContents

        public void setRichTextContents​(String content)

        Set the Rich-text contents of the annotation. This method takes an XML-formatted "Rich Text String" as defined in the PDF Specification, chapter 8. Broadly this is a highly simplified XHTML document containing a <body>, one or more <p> tags which contain zero or more <span>, <i> and <b> tags. The only permitted attribute is "style". An example would be:

          <?xml version="1.0"?>
          <body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:9.0.0" xfa:spec="2.0.2" style="font-size:14pt;text-align:left;color:#000000;font-weight:normal;font-style:normal;font-family:Helvetica,sans-serif">
           <p>
            <span>This text is <i>italic</i> and this is in <span style="color:#FF0000">red&#13;</span>
           </p>
           <p>
            <span>This is the next line of text</span>
           </p>
          </body>
         

        Note that due to quirks in Acrobat, newlines in the text should be indicated with a "&#10;" character as well as with a paragraph end. Failing to do so will lose the rich-text formatting if the field is subsequently edited in Acrobat.

        Calling this method will also update the plain-text version of the Content, as returned by PDFAnnotation.getContents().

        Parameters:
        content - a Rich Text String
        Throws:
        IllegalArgumentException - if the supplied content is not well formed XHTML.
        Since:
        2.11
        See Also:
        setContents(java.lang.String), PDFAnnotation.getContents(), getRichTextContents()
      • putRichTextResource

        public void putRichTextResource​(String key,
                                        Object value)
        Add a resource that is referenced by the rich content set in setRichTextContents(java.lang.String). For example, if the rich content included a <span style='font-family:MyFont'> you would need to make the MyFont font available to the annotation by doing putRichTextResource("MyFont", font), where font is a PDFFont.
        Parameters:
        key - the name of the resource
        value - the resources - any object, but typically a PDFFont or null to remove a previously set value.
        Since:
        2.11.25
      • getRichTextContents

        public String getRichTextContents()
        Get the rich-text content of this annotation if specified, or null if only plain-text content is available
        Since:
        2.11
      • setStyle

        public void setStyle​(PDFStyle style)
        Set the style to display the text in
        Parameters:
        style - the style to display the text in
      • setBackgroundStyle

        public void setBackgroundStyle​(PDFStyle style)
        Set the background style for the annotation.
        Since:
        2.11
      • getStyle

        public PDFStyle getStyle()
        Get the text style of the annotation.
      • getBackgroundStyle

        public PDFStyle getBackgroundStyle()
        Get the background style for the annotation
        Since:
        2.11
      • getColor

        public Color getColor()
        Return the background color of the annotation - since 2.11, the equivalent of calling getBackgroundStyle().getFillColor()
        Overrides:
        getColor in class PDFAnnotation
      • setColor

        public void setColor​(Color color)
        Set the background color of the annotation.
        Overrides:
        setColor in class PDFAnnotation
      • setCallout

        public void setCallout​(float[] cl)

        Set the "Callout" for this box. Since Acrobat 7.0 a Text annotation may have a "callout arrow" which is drawn in one or two segments from the box itself. The paramater "cl" is an array of 4 or 6 floats - the first two parameters are the point the callout points to, the last two parameters are the point the line joins onto the box, and if the array is 6 items long, the middle two points are the "elbow" of the line. A value of null removes the callout line.

        As an example, if the rectangle of the box is (100, 100, 200, 200), a callout could be specified as (0, 0, 0, 150, 100, 150) to draw a line from the bottom-left of the page up the left hand side, and then across to join the box in the middle.

        If the first point of the callout is inside the box itself, an IllegalArgumentException is thrown. Otherwise the points will be adjusted if necessary to join onto the box in a sensible manner.

        Parameters:
        cl - the callout points - either an array of 4 points as (x1, y1, x2, y2), or an array of 6 points as (x1, y1, x2, y2, x3, y3)
        Since:
        2.11.7
      • setCalloutEnding

        public void setCalloutEnding​(String type)
        Set the type of Line-Ending that's used to mark the end of a callout - an arrow, circle or similar. The list of valid endings is the same as those for the AnnotationShape class. This method will only work if a callout is set, ensure you call setCallout(float[]) first when creating a text callout!
        See Also:
        Since 2.11.7
      • getCallout

        public float[] getCallout()
        Get the callout points, as set by setCallout(float[])
        Since:
        2.11.7
      • getContentRectangle

        public float[] getContentRectangle()
        Return the rectangle of the content of this annotation. If a callout is specified this will be the rectangle of the box itself, as opposed to the rectangle of the entire annotation including the callout arrow. If no callout is in place the return value is identical to PDFAnnotation.getRectangle()
        Since:
        2.11.7
      • setContentRectangle

        public void setContentRectangle​(float x1,
                                        float y1,
                                        float x2,
                                        float y2)
        Set the rectangle of the content of this annotation. If a callout is specified this will be the rectangle of the box itself, as opposed to the rectangle of the entire annotation including the callout arrow. If no callout is in place this method is identical to PDFAnnotation.setRectangle(float, float, float, float)
        Since:
        2.11.7
      • rebuild

        public void rebuild()
        Description copied from class: PDFAnnotation
        Rebuild the annotation's appearance. This will be done automatically when required, usually just before saving the PDF or rasterizing it to a bitmap. However this method can be called explicitly if necessary, usually to ensure the rebuild (which may fire a PropertyChangeEvent) is run on a specific thread.
        Overrides:
        rebuild in class PDFAnnotation
      • toString

        public String toString()