Class FreeTextAnnotation

  • All Implemented Interfaces:

    
    public class FreeTextAnnotation
    extends Annotation
                        

    Represents a free text annotation on the page. The annotation’s text color comes from the color property of Annotation.

    • Constructor Detail

      • FreeTextAnnotation

        FreeTextAnnotation(int pageIndex, RectF rect, String contents)
        Creates a new FreeText annotation.
        Parameters:
        pageIndex - Page to which this annotation will be attached to.
        rect - Bounding rectangle for this annotation's text.
        contents - Text of the annotation.
      • FreeTextAnnotation

        FreeTextAnnotation(AnnotationPropertyMap properties, boolean markDirty)
        Intended for internal usage only.
    • Method Detail

      • getType

        @NonNull() AnnotationType getType()

        Gets the annotation type of the annotation.

        Returns:

        The type of the annotation. Makes down casting easier.

      • getContents

        @Nullable() String getContents()

        Returns text contents of the annotation. This is usually the displayed text for annotations that display text or accessibility label for annotations that don't.

        Returns:

        Annotation contents string or null if it's not set.

      • setContents

         void setContents(@Nullable() String contents)

        Sets text contents of the annotation. This is usually the displayed text for annotations that display text or accessibility label for annotations that don't.

        Parameters:
        contents - Contents string or null to clear the field.
      • setContentsWithoutSync

         void setContentsWithoutSync(@Nullable() String contents)

        Sets text contents of the annotation without synchronizing the change to the native object.

        Parameters:
        contents - Contents string or null to clear the field.
      • isResizable

         boolean isResizable()

        Check if the annotation is resizable, or if this is a non-resizable annotation.

        Returns:

        true if the annotation can be resized (e.g. ink annotation) or false if it is a non-resizable one (e.g. note annotation).

      • getMinimumSize

        @NonNull() Size getMinimumSize()

        Returns the minimum size of the annotation.

        Returns:

        The minimum annotation size in PDF points.

      • updateTransformationProperties

         void updateTransformationProperties(@NonNull() RectF newBoundingBox, @NonNull() RectF oldBoundingBox)

        Annotations may override this method to transform their properties (i.e. points, rects, sizes) whenever the bounding box of the annotation changed.

        Parameters:
        newBoundingBox - New bounding box of the annotation (in PDF points).
        oldBoundingBox - Old bounding box of the annotation (in PDF points).
      • getTextInsets

        @NonNull() EdgeInsets getTextInsets()

        Gets the insets that are applied to the text. This describes the offset of the inner rect containing the text, to the bounding box.

        Returns:

        The inset of the text rect to the bounds.

      • setTextInsets

         void setTextInsets(@NonNull() EdgeInsets edgeInsets)

        Sets the insets that are applied to the text.

        Parameters:
        edgeInsets - The amount to inset the text in the bounding box.
      • setCallOutPoints

         void setCallOutPoints(@NonNull() List<PointF> points)

        Sets the call out points for this free text annotation. This needs to be either 2 or 3 points, with the first point also having a line end.

        Parameters:
        points - The points for the call out line.
      • getTextSize

         float getTextSize()

        Returns the text size set to this annotation.

        Returns:

        Text size for this annotation (in PDF points).

      • setTextSize

         void setTextSize(float textSize)

        Sets the text size of this annotation.

        Parameters:
        textSize - Text size to be set (in PDF points).
      • getTextStrokeColor

        @ColorInt() int getTextStrokeColor()

        Returns text stroke color of this annotation. For the main text color use getColor.

        Returns:

        Text stroke color of this annotations or 0 if no color was set.

      • setTextStrokeColor

         void setTextStrokeColor(@ColorInt() int color)

        Sets the color of annotations text stroke. For the main text color use setColor.

        Parameters:
        color - Text stroke color of this annotation or 0 to clear the value.
      • getRotation

         int getRotation()

        Returns the clockwise rotation of this free text annotation in degrees.

        Returns:

        The clockwise rotation of this free text annotation in degrees.

      • setRotation

         void setRotation(int rotation, @NonNull() Size contentSize, boolean adjustBounds)

        Sets the rotation of this free text annotation.

        See also adjustBoundsForRotation.

        Parameters:
        rotation - The clockwise rotation in degrees.
        contentSize - The size of the annotation content, it will be rotated and scaled to fit inside the actual bounding box.
        adjustBounds - If true will also adjust the bounding box to match the new rotation.
      • setRotation

         void setRotation(int rotation)

        Sets the rotation of this free text annotation. This will adjust the bounding box so rotating the annotation will cause the bounds to change.

        Parameters:
        rotation - The clockwise rotation in degrees.
      • adjustBoundsForRotation

         void adjustBoundsForRotation()

        This adjusts the annotations bounding box to the smallest possible size that will encompass the rotated annotations at it's default size.

      • isUiRotationSupported

         boolean isUiRotationSupported()

        Returns true if this Annotation can be rotated in the UI.

      • resizeToFitText

         void resizeToFitText(@NonNull() AnnotationConfigurationRegistry annotationConfigurationRegistry, @NonNull() Size pageSize)

        Resizes the annotation to fit the text. This will update the bounding box of the annotation.

        Parameters:
        annotationConfigurationRegistry - The annotation configuration registry to use for updating the annotation, can be retrieved by PdfFragment.getAnnotationConfigurationRegistry().
        pageSize - The size of the page the annotation is on.
      • setFlags

         void setFlags(@NonNull() EnumSet<AnnotationFlags> flags)

        Sets the annotation flags for this annotation. Since a FreeTextAnnotation with an intent of type FREE_TEXT_CALLOUT does not work with the NOZOOM flag, we will remove it if it exists from the provided flags set

        Parameters:
        flags - Set of annotation flags to be set.
      • setContentSize

         void setContentSize(@Nullable() RectF contentSize, boolean adjustedForPageRotation)

        Sets the inner bounds that are used when rotating the annotation. In order to keep the size consistent when rotating we need to remember the size when rotated 0° degrees.

        Core adds the page rotation to the annotation rotation when handling stamps/free text rotation. So when creating them we can't use the bounding box to initialize the content size when the page they are on is 90° or 270°. We need to flip the width and height so it is correct. The adjustedForPageRotation parameter indicates whether this was already done by the calling code or if it should be done automatically when the annotation is attached to the document.

        Parameters:
        contentSize - The content size to set in PDF coordinates.
        adjustedForPageRotation - true if the content size was already adjusted for the page rotation, false if it should be adjusted as soon as the annotation is attached to the document.