public class

AnnotUtils

extends Object
java.lang.Object
   ↳ com.pdftron.pdf.utils.AnnotUtils

Class Overview

A utility class for handling annotation.

Summary

Nested Classes
interface AnnotUtils.AnnotVisitor Visitor that visits annotations on a single page or in an entire document. 
interface AnnotUtils.PageVisitor Visitor that visits pages within a document. 
Fields
public static String KEY_FreeTextDate
public static String KEY_FreeTextFill
public static String KEY_InReplyTo
public static String KEY_NM
public static String KEY_RawRichContent
public static String KEY_ReplyTo
public static String KEY_RichContent
public static String Key_State
public static String Key_StateAccepted
public static String Key_StateCancelled
public static String Key_StateCompleted
public static String Key_StateModel
public static String Key_StateModelMarked
public static String Key_StateModelReview
public static String Key_StateNone
public static String Key_StateRejected
public static String VALUE_Group
Public Constructors
AnnotUtils()
Public Methods
static void applyCustomFreeTextAppearance(PDFViewCtrl pdfViewCtrl, AutoScrollEditText editText, Annot annot, int pageNum)
Applies custom appearance for a FreeText with custom spacing annotation.
static boolean canUseBitmapAppearance(Annot annot)
A read lock is expected around this method.
static int compareCreationDate(Annot thisObj, Annot thatObj)
static int compareDate(Annot thisObj, Annot thatObj)
static Rect computeAnnotInbox(PDFViewCtrl pdfViewCtrl, Annot annot, int pg)
Returns the bounding box of the specified annotation in screen space.
static void createAnnotationGroup(PDFViewCtrl pdfViewCtrl, Annot primary, ArrayList<Annot> allInGroup)
Creates a group of annotations
static Annot createAnnotationReply(String parentAnnotId, int pageNum, PDFViewCtrl pdfViewCtrl, String authorId, String contents)
static Annot createAnnotationStateReply(String parentAnnotId, int pageNum, PDFViewCtrl pdfViewCtrl, String authorId, AnnotReviewState state)
static void createCustomFreeTextAppearance(View view, PDFViewCtrl pdfViewCtrl, Annot annot, int pageNum, Rect bbox)
Applies custom appearance for a FreeText annotation that is generated from Android EditText A write lock is expected around this call
static void createRCFreeTextAppearance(PTRichEditor richEditor, PDFViewCtrl pdfViewCtrl, Annot annot, int pageNum)
Creates the FreeText appearance from PTRichEditor This method does not lock document, a write lock should be acquired outside
static String createScreenshot(File tempDir, PDFDoc pdfDoc, Annot annot, int pageNum)
Static function to create a screenshot out of the bounds of an annot rect bbox.
static createScreenshotAsync(File tempDir, PDFDoc pdfDoc, Annot annot, int annotPageNumber)
Asyncronous method for creating screenshots, as some complex files might take some time to render.
static void deleteAnnotationReply(String replyId, int pageNum, PDFViewCtrl pdfViewCtrl, ToolManager toolManager)
static void flattenAnnot(PDFViewCtrl pdfViewCtrl, Annot annot, int pageNum)
Flattens an annotation.
static int getAnnotColor(Annot annot)
Returns the annotation color of the specified annotation.
static int getAnnotImageResId(int type)
Returns the annotation image resource ID.
static Date getAnnotLocalCreationDate(Annot annot)
Gets the annotation creation date in local date time
static Date getAnnotLocalDate(Annot annot)
Gets the annotation date in local date time
static float getAnnotOpacity(Annot annot)
Returns the annotation opacity of the specified annotation.
static AnnotStyle getAnnotStyle(Annot annot)
Gets the annot style A read lock is required for this function.
static int getAnnotType(Annot annot)
static String getAnnotTypeAsPluralString(Annot annot)
Returns annotation type as raw plural string (not localized).
static String getAnnotTypeAsPluralString(Context context, Annot annot)
Returns annotation type as string.
static String getAnnotTypeAsString(Annot annot)
Returns annotation type as raw string (not localized).
static String getAnnotTypeAsString(Context context, Annot annot)
Returns annotation type as string.
static String getAnnotTypeAsString(Context context, int typeId)
Returns annotation type as string.
static Bitmap getAnnotationAppearance(PDFViewCtrl pdfViewCtrl, Annot annot)
static getAnnotationAppearanceAsync(PDFViewCtrl pdfViewCtrl, Annot annot)
static int getAnnotationCountOnPage(PDFViewCtrl pdfViewCtrl, int pageNum, ArrayList<Integer> excludeType)
Gets annotation count on page excluding certain types A read lock should be acquired outside of this method
static ArrayList<Annot> getAnnotationsInGroup(PDFViewCtrl pdfViewCtrl, Annot annot, int pageNum)
Returns all annotations in this group if the annotation passed in is in an annotation group
static String getCurrentTime(String format)
static String getIRTAsString(Annot annot)
Gets the unique Id of the IRT parent annotation of this annotation
static Date getLocalDate(Date date)
Converts a com.pdftron.pdf.Date to local Date object
static Rect getPageRectFromScreenRect(PDFViewCtrl pdfViewCtrl, Rect screenRect, int pg)
static ArrayList<Point> getPolyVertices(Annot annot)
Gets the vertices of a Polyline or a Polygon.
static Annot getPrimaryAnnotInGroup(PDFViewCtrl pdfViewCtrl, ArrayList<Annot> annots)
static RectF getScreenRectFromPageRect(PDFViewCtrl pdfViewCtrl, Rect pageRect, int pg)
static int getStampDegree(Annot annot)
Gets the rotation degree from Stamp annotation.
static int getStampDegreeOld(Annot annot)
Gets the deprecated rotation degree from Stamp annotation.
static double[] getStampSize(Context context, String stampName)
Gets the page corresponding to a certain stamp in our stamps repository.
static boolean hasReplyTypeGroup(Annot annot)
Checks if the annotation is part of a group annotation
static boolean hasReplyTypeReply(Annot annot)
Checks if the annotation is an annotation reply
static boolean isAreaMeasure(Annot annot)
Checks if the annotation is area measurement A read lock is expected around this method.
static boolean isArrow(Annot annot)
Checks if the annotation is an arrow A read lock is expected around this method.
static boolean isCallout(Annot annot)
Checks if the annotation is a callout A read lock is expected around this method.
static boolean isCloud(Annot annot)
Checks if the annotation is a cloud polygon A read lock is expected around this method.
static boolean isFreeHighlighter(Annot annot)
Checks if the annotation is a free highlighter A read lock is expected around this method.
static boolean isFreeTextDate(Annot annot)
Checks if the annotation is a date text A read lock is expected around this method.
static boolean isFreeTextSpacing(Annot annot)
Checks if the annotation is a fill and sign type free text A read lock is expected around this method.
static boolean isGroupSelected(PDFViewCtrl pdfViewCtrl, ArrayList<Annot> selected, int page)
Check whether the selected annotations match an existing group
static boolean isListBox(Annot annot)
Checks if the annotation is a list box widget A read lock is expected around this method.
static boolean isPerimeterMeasure(Annot annot)
Checks if the annotation is perimeter measurement A read lock is expected around this method.
static boolean isRuler(Annot annot)
Checks if the annotation is an ruler A read lock is expected around this method.
static boolean isSimpleLine(Annot annot)
Checks if the annotation is a line with no ending styles A read lock is expected around this method.
static loadSystemFonts()
static void putStampDegree(Annot annot, int rotation)
Sets the rotation degree from Stamp annotation.
static Rect quadToRect(QuadPoint qp)
static void refreshAnnotAppearance(Context context, Annot annot)
helper function to refresh annotation appearance.
static boolean refreshCustomRichFreeTextAppearance(File appearance, Annot annot)
static void safeDeleteAllAnnots(PDFDoc doc)
Delete all annotations except for links and form fields This method does not lock document, a write lock should be acquired outside
static void safeDeleteAnnotsOnPage(PDFDoc doc, ArrayList<Integer> pages)
Delete all annotations except for links and form fields on pages This method does not lock document, a write lock should be acquired outside
static void saveFreeTextCache(FreeTextCacheStruct freeTextCacheStruct, PDFViewCtrl pdfViewCtrl)
Saves the free text in cache.
static void setAuthor(Annot annot, String author)
Sets the author for the specified annotation, if possible.
static void setAuthor(Markup markup, String author)
Sets the author for the specified markup annotation.
static void setDateToNow(PDFViewCtrl pdfViewCtrl, Annot annot)
static void setUniqueId(Annot annot, String id)
Sets the unique identifier for the specified annotation, if possible.
static void traverseAnnots(Page page, AnnotUtils.AnnotVisitor visitor)
Traverse over all annotations on the specified page.
static void traverseAnnots(PDFDoc doc, AnnotUtils.AnnotVisitor visitor)
Traverse over all annotations in the specified document.
static void traversePages(PDFDoc doc, AnnotUtils.PageVisitor visitor)
Traverse over all pages in the specified document.
static void ungroupAnnotations(PDFViewCtrl pdfViewCtrl, ArrayList<Annot> allInGroup)
static Annot updateAnnotationReply(String replyId, int pageNum, PDFViewCtrl pdfViewCtrl, ToolManager toolManager, String contents)
[Expand]
Inherited Methods
From class java.lang.Object

Fields

public static String KEY_FreeTextDate

public static String KEY_FreeTextFill

public static String KEY_InReplyTo

public static String KEY_NM

public static String KEY_RawRichContent

public static String KEY_ReplyTo

public static String KEY_RichContent

public static String Key_State

public static String Key_StateAccepted

public static String Key_StateCancelled

public static String Key_StateCompleted

public static String Key_StateModel

public static String Key_StateModelMarked

public static String Key_StateModelReview

public static String Key_StateNone

public static String Key_StateRejected

public static String VALUE_Group

Public Constructors

public AnnotUtils ()

Public Methods

public static void applyCustomFreeTextAppearance (PDFViewCtrl pdfViewCtrl, AutoScrollEditText editText, Annot annot, int pageNum)

Applies custom appearance for a FreeText with custom spacing annotation. Note: appearance will only be applied for Android Lollipop and above. A write lock is expected around this call

Parameters
pdfViewCtrl the viewer
editText the EditText where appearance is from
annot the annotation to apply the appearance to
pageNum the page number of the annot

public static boolean canUseBitmapAppearance (Annot annot)

A read lock is expected around this method.

public static int compareCreationDate (Annot thisObj, Annot thatObj)

public static int compareDate (Annot thisObj, Annot thatObj)

public static Rect computeAnnotInbox (PDFViewCtrl pdfViewCtrl, Annot annot, int pg)

Returns the bounding box of the specified annotation in screen space.

Parameters
pdfViewCtrl The PDFViewCtrl
annot The annotation
pg The page number
Returns
  • The bounding box

public static void createAnnotationGroup (PDFViewCtrl pdfViewCtrl, Annot primary, ArrayList<Annot> allInGroup)

Creates a group of annotations

Parameters
primary the primary annotation
allInGroup all annotations to be added to this group

public static Annot createAnnotationReply (String parentAnnotId, int pageNum, PDFViewCtrl pdfViewCtrl, String authorId, String contents)

public static Annot createAnnotationStateReply (String parentAnnotId, int pageNum, PDFViewCtrl pdfViewCtrl, String authorId, AnnotReviewState state)

public static void createCustomFreeTextAppearance (View view, PDFViewCtrl pdfViewCtrl, Annot annot, int pageNum, Rect bbox)

Applies custom appearance for a FreeText annotation that is generated from Android EditText A write lock is expected around this call

Parameters
view the EditText where appearance is from
pdfViewCtrl the viewer
annot the annotation to apply the appearance to
pageNum the page number of the annot
bbox when a bbox is supplied, this will be used as bbox of the annotation

public static void createRCFreeTextAppearance (PTRichEditor richEditor, PDFViewCtrl pdfViewCtrl, Annot annot, int pageNum)

Creates the FreeText appearance from PTRichEditor This method does not lock document, a write lock should be acquired outside

public static String createScreenshot (File tempDir, PDFDoc pdfDoc, Annot annot, int pageNum)

Static function to create a screenshot out of the bounds of an annot rect bbox. Note that this requires a read lock on the PDFDoc.

Parameters
tempDir temporary directory to store the created PNG file
pdfDoc current PDFDoc
annot annot to get the screenshot off of
pageNum current page number of the annot
Returns
  • the string of the path of the PNG file (in a temp file path)
Throws
PDFNetException any exception thrown. will be handled somewhere else

public static createScreenshotAsync (File tempDir, PDFDoc pdfDoc, Annot annot, int annotPageNumber)

Asyncronous method for creating screenshots, as some complex files might take some time to render.

Parameters
tempDir temporary directory path
pdfDoc PDFDoc that contains the annotation
annot (square) annot used to create the screenshot with
annotPageNumber page number that the annotation is on
Returns
  • loation of the temp screenshot created

public static void deleteAnnotationReply (String replyId, int pageNum, PDFViewCtrl pdfViewCtrl, ToolManager toolManager)

public static void flattenAnnot (PDFViewCtrl pdfViewCtrl, Annot annot, int pageNum)

Flattens an annotation. A document lock is required around this method.

public static int getAnnotColor (Annot annot)

Returns the annotation color of the specified annotation.

Parameters
annot The annotation
Returns
  • The annotation color

public static int getAnnotImageResId (int type)

Returns the annotation image resource ID.

Parameters
type The type of annotation
Returns
  • The annotation image resource ID

public static Date getAnnotLocalCreationDate (Annot annot)

Gets the annotation creation date in local date time

Parameters
annot the annotation
Returns
  • the date

public static Date getAnnotLocalDate (Annot annot)

Gets the annotation date in local date time

Parameters
annot the annotation
Returns
  • the date

public static float getAnnotOpacity (Annot annot)

Returns the annotation opacity of the specified annotation.

Parameters
annot The annotation
Returns
  • The annotation opacity

public static AnnotStyle getAnnotStyle (Annot annot)

Gets the annot style A read lock is required for this function.

Parameters
annot the annotation
Returns
  • the annot style
Throws
PDFNetException PDFNet exception

public static int getAnnotType (Annot annot)

public static String getAnnotTypeAsPluralString (Annot annot)

Returns annotation type as raw plural string (not localized).

Parameters
annot The annotation
Returns
  • The annotation type as string

public static String getAnnotTypeAsPluralString (Context context, Annot annot)

Returns annotation type as string.

Parameters
context The context
annot The annotation
Returns
  • The annotation type as string

public static String getAnnotTypeAsString (Annot annot)

Returns annotation type as raw string (not localized).

Parameters
annot The annotation
Returns
  • The annotation type as string

public static String getAnnotTypeAsString (Context context, Annot annot)

Returns annotation type as string.

Parameters
context The context
annot The annotation
Returns
  • The annotation type as string

public static String getAnnotTypeAsString (Context context, int typeId)

Returns annotation type as string.

Parameters
context The context
typeId The annotation type ID
Returns
  • The annotation type as string

public static Bitmap getAnnotationAppearance (PDFViewCtrl pdfViewCtrl, Annot annot)

public static getAnnotationAppearanceAsync (PDFViewCtrl pdfViewCtrl, Annot annot)

public static int getAnnotationCountOnPage (PDFViewCtrl pdfViewCtrl, int pageNum, ArrayList<Integer> excludeType)

Gets annotation count on page excluding certain types A read lock should be acquired outside of this method

public static ArrayList<Annot> getAnnotationsInGroup (PDFViewCtrl pdfViewCtrl, Annot annot, int pageNum)

Returns all annotations in this group if the annotation passed in is in an annotation group

public static String getCurrentTime (String format)

public static String getIRTAsString (Annot annot)

Gets the unique Id of the IRT parent annotation of this annotation

public static Date getLocalDate (Date date)

Converts a com.pdftron.pdf.Date to local Date object

Parameters
date to convert
Returns
  • the local date

public static Rect getPageRectFromScreenRect (PDFViewCtrl pdfViewCtrl, Rect screenRect, int pg)

public static ArrayList<Point> getPolyVertices (Annot annot)

Gets the vertices of a Polyline or a Polygon. This method does not lock the document, so a read lock should be acquired outside.

Parameters
annot annotation with type of polyline or polygon
Returns
  • the vertices

public static Annot getPrimaryAnnotInGroup (PDFViewCtrl pdfViewCtrl, ArrayList<Annot> annots)

public static RectF getScreenRectFromPageRect (PDFViewCtrl pdfViewCtrl, Rect pageRect, int pg)

public static int getStampDegree (Annot annot)

Gets the rotation degree from Stamp annotation. A read lock is expected around this method.

public static int getStampDegreeOld (Annot annot)

Gets the deprecated rotation degree from Stamp annotation. A read lock is expected around this method.

public static double[] getStampSize (Context context, String stampName)

Gets the page corresponding to a certain stamp in our stamps repository.

Parameters
context The context
stampName The name of stamp icon
Returns
  • The page size; null if cannot find the stamp

public static boolean hasReplyTypeGroup (Annot annot)

Checks if the annotation is part of a group annotation

Parameters
annot the annotation
Returns
  • true if it is part of a group annotation, false otherwise

public static boolean hasReplyTypeReply (Annot annot)

Checks if the annotation is an annotation reply

Parameters
annot the annotation
Returns
  • true if it is an annotation reply, false otherwise

public static boolean isAreaMeasure (Annot annot)

Checks if the annotation is area measurement A read lock is expected around this method.

Parameters
annot The annotation
Returns
  • True if the annotation is area measurement

public static boolean isArrow (Annot annot)

Checks if the annotation is an arrow A read lock is expected around this method.

Parameters
annot The annotation
Returns
  • True if the annotation is arrow
Throws
PDFNetException PDFNet exception

public static boolean isCallout (Annot annot)

Checks if the annotation is a callout A read lock is expected around this method.

Parameters
annot The annotation
Returns
  • True if the annotation is callout

public static boolean isCloud (Annot annot)

Checks if the annotation is a cloud polygon A read lock is expected around this method.

Parameters
annot The annotation
Returns
  • True if the annotation is cloud
Throws
PDFNetException PDFNet exception

public static boolean isFreeHighlighter (Annot annot)

Checks if the annotation is a free highlighter A read lock is expected around this method.

Parameters
annot The annotation
Returns
  • True if the annotation is free highlighter
Throws
PDFNetException PDFNet exception

public static boolean isFreeTextDate (Annot annot)

Checks if the annotation is a date text A read lock is expected around this method.

Parameters
annot The annotation
Returns
  • True if the annotation is date text

public static boolean isFreeTextSpacing (Annot annot)

Checks if the annotation is a fill and sign type free text A read lock is expected around this method.

Parameters
annot The annotation
Returns
  • True if the annotation is date text

public static boolean isGroupSelected (PDFViewCtrl pdfViewCtrl, ArrayList<Annot> selected, int page)

Check whether the selected annotations match an existing group

Parameters
selected the selected annotations
Returns
  • whether the selected annotations match an existing group

public static boolean isListBox (Annot annot)

Checks if the annotation is a list box widget A read lock is expected around this method.

Parameters
annot The annotation
Returns
  • True if the annotation is list box widget

public static boolean isPerimeterMeasure (Annot annot)

Checks if the annotation is perimeter measurement A read lock is expected around this method.

Parameters
annot The annotation
Returns
  • True if the annotation is perimeter measurement

public static boolean isRuler (Annot annot)

Checks if the annotation is an ruler A read lock is expected around this method.

Parameters
annot The annotation
Returns
  • True if the annotation is ruler

public static boolean isSimpleLine (Annot annot)

Checks if the annotation is a line with no ending styles A read lock is expected around this method.

Parameters
annot The annotation
Returns
  • True if the annotation is arrow
Throws
PDFNetException PDFNet exception

public static loadSystemFonts ()

public static void putStampDegree (Annot annot, int rotation)

Sets the rotation degree from Stamp annotation. A write lock is expected around this method.

public static Rect quadToRect (QuadPoint qp)

public static void refreshAnnotAppearance (Context context, Annot annot)

helper function to refresh annotation appearance. Note that some annotations may have their own custom appearance such as Text annotation.

Parameters
context The Context
annot The annotation
Throws
PDFNetException PDFNet exception

public static boolean refreshCustomRichFreeTextAppearance (File appearance, Annot annot)

public static void safeDeleteAllAnnots (PDFDoc doc)

Delete all annotations except for links and form fields This method does not lock document, a write lock should be acquired outside

Parameters
doc the PDFDoc

public static void safeDeleteAnnotsOnPage (PDFDoc doc, ArrayList<Integer> pages)

Delete all annotations except for links and form fields on pages This method does not lock document, a write lock should be acquired outside

Parameters
doc the PDFDoc

public static void saveFreeTextCache (FreeTextCacheStruct freeTextCacheStruct, PDFViewCtrl pdfViewCtrl)

Saves the free text in cache.

Parameters
freeTextCacheStruct The FreeTextCacheStruct
pdfViewCtrl The PDFViewCtrl

public static void setAuthor (Annot annot, String author)

Sets the author for the specified annotation, if possible.

This method does not lock the document, so a write lock should be acquired outside.

Parameters
annot the Annot
author the desired author name

public static void setAuthor (Markup markup, String author)

Sets the author for the specified markup annotation.

This method does not lock the document, so a write lock should be acquired outside.

Parameters
markup the Markup annotation
author the desired author name

public static void setDateToNow (PDFViewCtrl pdfViewCtrl, Annot annot)

public static void setUniqueId (Annot annot, String id)

Sets the unique identifier for the specified annotation, if possible.

This method does not lock the document, so a write lock should be acquired outside.

Parameters
annot the Annot
id the unique identifier

public static void traverseAnnots (Page page, AnnotUtils.AnnotVisitor visitor)

Traverse over all annotations on the specified page. The visitor will be called for each annot via visit(Annot), allowing for arbitrary operations to be performed on the annot.

This method does not lock the document, so a read lock should be acquired outside.

Parameters
page the Page
visitor the AnnotUtils.AnnotVisitor to visit each annot

public static void traverseAnnots (PDFDoc doc, AnnotUtils.AnnotVisitor visitor)

Traverse over all annotations in the specified document. The AnnotUtils.AnnotVisitor will be called for each annot via visit(Annot), allowing for arbitrary operations to be performed on the annot.

This method does not lock the document, so a read lock should be acquired outside.

Parameters
doc the PDFDoc
visitor the AnnotUtils.AnnotVisitor to visit each annot

public static void traversePages (PDFDoc doc, AnnotUtils.PageVisitor visitor)

Traverse over all pages in the specified document. The visitor will be called for each page via visit(Page), allowing for arbitrary operations to be performed on the page.

This method does not lock the document, so a read lock should be acquired outside.

Parameters
doc the PDFDoc
visitor the AnnotUtils.PageVisitor to visit each page

public static void ungroupAnnotations (PDFViewCtrl pdfViewCtrl, ArrayList<Annot> allInGroup)

public static Annot updateAnnotationReply (String replyId, int pageNum, PDFViewCtrl pdfViewCtrl, ToolManager toolManager, String contents)