CPDFAnnotation Class Reference

Inherits from NSObject
Declared in CPDFAnnotation.h

Overview

CPDFAnnotation does not conform to NSCopying. Use \c copyToPage: to copy an annotation to a target page.

– initWithPage:document:

Creates a new annotation object associated with the given page and document.

- (nullable instancetype)initWithPage:(CPDFPage *)page document:(CPDFDocument *)document

Parameters

page

The page on which the annotation will eventually reside.

document

The document that owns the page.

Return Value

A new annotation instance, or @c nil if creation failed.

Discussion

Creates a new annotation object associated with the given page and document.

This initializer creates the underlying engine annotation object (via @c CreateAnnot) and binds it to the page. Call @c [CPDFPage updateAndAddAnnotation:] to finish the wrapper-side registration, appearance generation, and undo/redo notification.

Declared In

CPDFAnnotation.h

  page

Returns the page that the annotation is associated with (may return nil if annotation not associated with a page).

@property (nonatomic, readonly, weak) CPDFPage *page

Discussion

Returns the page that the annotation is associated with (may return nil if annotation not associated with a page).

New annotation objects are associated with a page during @c initWithPage:document: creation.

Declared In

CPDFAnnotation.h

– copyToPage:

Copies the annotation to the specified target page.

- (nullable CPDFAnnotation *)copyToPage:(CPDFPage *)page

Parameters

page

The target page to copy the annotation to. The copied annotation will be added to this page.

Return Value

For an ordinary annotation, a new annotation wrapper on the target page. For a restorable copy returned by @c copyForUndoRestore, the original wrapper may be returned when it is still alive and has been physically removed. Returns @c nil when copying or safe restoration fails.

Discussion

Copies the annotation to the specified target page.

Declared In

CPDFAnnotation.h

– copyForUndoRestore

Creates a restorable copy for undo/redo before the receiver is removed.

- (nullable CPDFAnnotation *)copyForUndoRestore

Return Value

A restorable annotation copy, or nil if the copy failed.

Discussion

Creates a restorable copy for undo/redo before the receiver is removed.

The returned annotation is backed by an internal temporary document that is retained by the copied annotation. Keep the returned object in your undo item, then call @c copyToPage: on it to restore a new annotation to the target page during undo/redo. Call this method before removing the original annotation from its page. The SDK weakly associates the original wrapper with this copy. Restoring through @c copyToPage: reuses that wrapper when safe, without retaining its page or native annotation. If the original wrapper has already been released, restoration creates a new wrapper as a compatibility fallback.

Declared In

CPDFAnnotation.h

– releaseUndoRestoreDocument

Releases the temporary document retained by @c copyForUndoRestore.

- (void)releaseUndoRestoreDocument

Discussion

Releases the temporary document retained by @c copyForUndoRestore.

Call this after the undo/redo restore has successfully copied the restorable annotation back to the target page with @c copyToPage:. After calling this method, do not use the same restorable annotation as a copy source again.

Declared In

CPDFAnnotation.h

  type

Returns the type of the annotation. Examples include: “Text”, “Link”, “Line”, etc.

@property (nonatomic, readonly) NSString *type

Discussion

Returns the type of the annotation. Examples include: “Text”, “Link”, “Line”, etc.

The type of the annotation. Types include Line, Link, Text, and so on, referring to the CPDFAnnotation subclasses. In the Adobe PDF Specification, this attribute is called Subtype, and the common “type” for all annotations in the PDF Specification is Annot.

Declared In

CPDFAnnotation.h

  bounds

Method to get / set the bounding box for the annotation in page space. Required for all annotations.

@property (nonatomic, assign) CGRect bounds

Discussion

Method to get / set the bounding box for the annotation in page space. Required for all annotations.

Page space is coordinate system with the origin at the lower-left corner of the current page.

Declared In

CPDFAnnotation.h

  contents

Method to get / set the textual content (if any) associated with the annotation.

@property (nonatomic, strong) NSString *contents

Discussion

Method to get / set the textual content (if any) associated with the annotation.

Textual content is typically associated with CPDFTextAnnotation and CPDFFreeTextAnnotation annotations.

Declared In

CPDFAnnotation.h

  borderWidth

Method to get / set the stroke thickness for the annotation.

@property (nonatomic, assign) CGFloat borderWidth

Discussion

Method to get / set the stroke thickness for the annotation.

For the “geometry” annotations (Circle, Ink, Line, Square), the stroke thickness indicates the line width. CPDFAnnotation markup types (Highlight, Strikethrough, Underline) ignores the stroke thickness.

Declared In

CPDFAnnotation.h

  border

Optional border or border style that describes how to draw the annotation border (if any).

@property (nonatomic, strong) CPDFBorder *border

Discussion

Optional border or border style that describes how to draw the annotation border (if any).

For the “geometry” annotations (Circle, Ink, Line, Square), the border indicates the line width and whether to draw with a dash pattern or solid pattern. CPDFAnnotation markup types (Highlight, Strikethrough, Underline) ignores the border.

Declared In

CPDFAnnotation.h

  opacity

Method to get / set the opacity for the annotation.

@property (nonatomic, assign) CGFloat opacity

Discussion

Method to get / set the opacity for the annotation.

Declared In

CPDFAnnotation.h

  color

Method to get / set the color for the annotation.

@property (nonatomic, strong) CPDFKitPlatformColor *color

Discussion

Method to get / set the color for the annotation.

For many annotations (“Circle”, “Square”) the stroke color. Used for other annotations as well.

Declared In

CPDFAnnotation.h

– removeColor

remove color(Set it to transparent, or set SetColor: to nil)

- (BOOL)removeColor

Discussion

remove color(Set it to transparent, or set SetColor: to nil)

Declared In

CPDFAnnotation.h

  isNoRotate

@property (nonatomic, assign) BOOL isNoRotate

– modificationDate

Returns the modification date of the annotation.

- (NSDate *_Nullable)modificationDate

Discussion

Returns the modification date of the annotation.

Declared In

CPDFAnnotation.h

– setModificationDate:

- (void)setModificationDate:(NSDate *_Nullable)modificationDate

– creationDate

Returns the creation date of the annotation.

- (NSDate *_Nullable)creationDate

Discussion

Returns the creation date of the annotation.

Declared In

CPDFAnnotation.h

– setCreationDate:

- (void)setCreationDate:(NSDate *_Nullable)creationDate

– userName

Returns the name of the user who created the annotation.

- (NSString *)userName

Discussion

Returns the name of the user who created the annotation.

Declared In

CPDFAnnotation.h

– setUserName:

- (void)setUserName:(NSString *)userName

– anntationImage

  • Returns the image of the annotation.
- (CPDFKitPlatformImage *_Nonnull)anntationImage

Discussion

  • Returns the image of the annotation.

Declared In

CPDFAnnotation.h

– flags

Returns the flags of the annotation.

- (CPDFAnnotationFlags)flags

Discussion

Returns the flags of the annotation.

Declared In

CPDFAnnotation.h

– setFlags:

Sets the flags of the annotation.

- (void)setFlags:(CPDFAnnotationFlags)flags

Discussion

Sets the flags of the annotation.

Declared In

CPDFAnnotation.h

– isHidden

This is a convenience property that checks for CPDFAnnotationFlagHidden in flags.

- (BOOL)isHidden

Discussion

This is a convenience property that checks for CPDFAnnotationFlagHidden in flags.

Declared In

CPDFAnnotation.h

– setHidden:

- (void)setHidden:(BOOL)hidden

– isReadOnly

This is a convenience property that checks for CPDFAnnotationFlagReadOnly in flags.

- (BOOL)isReadOnly

Discussion

This is a convenience property that checks for CPDFAnnotationFlagReadOnly in flags.

Declared In

CPDFAnnotation.h

– setReadOnly:

- (void)setReadOnly:(BOOL)readOnly

– isLocked

This is a convenience property that checks for CPDFAnnotationFlagLocked in flags.

- (BOOL)isLocked

Discussion

This is a convenience property that checks for CPDFAnnotationFlagLocked in flags.

Declared In

CPDFAnnotation.h

– setLocked:

- (void)setLocked:(BOOL)locked

– updateAppearanceStream

Update appearance stream for the annotation.

- (void)updateAppearanceStream

Discussion

Update appearance stream for the annotation.

ComPDFKit will update the annotation appearance by default when you modify the annotation properties. You can also manually update the appearance by calling the updateAppearanceStream method, but you must call the updateAppearanceStream method manually when you modify the bounds of CPDFTextAnnotation, CPDFStampAnnotation, CPDFSignatureAnnotation annotations.

Declared In

CPDFAnnotation.h

– updateAnnotationRotationAppearanceStream

- (void)updateAnnotationRotationAppearanceStream

  annotationRotation

Sets the rotation angle for the annotation in degrees.

@property (nonatomic, readonly) NSInteger annotationRotation

Discussion

Sets the rotation angle for the annotation in degrees.

Rotation on a annotation. Must be -180 ~ 180.

Declared In

CPDFAnnotation.h

  saveRectRotationPoints

Method to get the all rect vertex points after rotation.

@property (nonatomic, readonly) NSArray<NSValue*> *saveRectRotationPoints

Discussion

Method to get the all rect vertex points after rotation.

Vertex points of the current page.

Declared In

CPDFAnnotation.h

  saveSourceRect

Method to get the rect befer rotation.based on the rect when the rotation angle is 0 degrees.

@property (nonatomic, readonly) CGRect saveSourceRect

Discussion

Method to get the rect befer rotation.based on the rect when the rotation angle is 0 degrees.

rect of the current page.

Declared In

CPDFAnnotation.h

– updateAnnotationRotation:

Method to Quickly set the annotation rotation angle, and simultaneously update the saveRectRotationPoints and annotationRotation property.

- (void)updateAnnotationRotation:(NSInteger)annotationRotation

Discussion

Method to Quickly set the annotation rotation angle, and simultaneously update the saveRectRotationPoints and annotationRotation property.

Rotation on a annotation. The annotationRotation based on when the rotation angle is 0 degrees. Must be -180 ~ 180.

Declared In

CPDFAnnotation.h

– moveAnnotationWithActivePage:offset:

Method to move stampAnnotation

- (void)moveAnnotationWithActivePage:(CPDFPage *_Nonnull)newActivePage offset:(CPDFKitPlatformPoint)offset

Discussion

Method to move stampAnnotation

offset

Declared In

CPDFAnnotation.h

– dragAnnotationWithCurrentPagePoint:draggedIndex:

Method to drag stampAnnotation

- (void)dragAnnotationWithCurrentPagePoint:(CGPoint)currentPagePoint draggedIndex:(CPDFAnnotationDraggedHandle)draggedIndex

Discussion

Method to drag stampAnnotation

draggedIndex

Declared In

CPDFAnnotation.h

– createReplyAnnotation

- (CPDFAnnotation *)createReplyAnnotation

– createReplyStateAnnotation:

- (CPDFAnnotation *)createReplyStateAnnotation:(CPDFAnnotationState)state

  replyAnnotations

@property (nonatomic, readonly) NSArray<CPDFAnnotation*> *replyAnnotations

  replyAnnotationType

@property (nonatomic, readonly) CPDFReplyAnnotationType replyAnnotationType

– setAnnotState:

- (BOOL)setAnnotState:(CPDFAnnotationState)state

– getAnnotState

- (CPDFAnnotationState)getAnnotState

– drawWithBox:inContext:

Draw method. Draws in page-space relative to origin of “box” passed in and to the given context.

- (void)drawWithBox:(CPDFDisplayBox)box inContext:(CGContextRef _Nonnull)context

Discussion

Draw method. Draws in page-space relative to origin of “box” passed in and to the given context.

Declared In

CPDFAnnotation.h

– setCountMeasureInfo:document:

Applies count measurement information to the annotation.

- (void)setCountMeasureInfo:(CPDFCountMeasureInfo *_Nonnull)measureInfo document:(CPDFDocument *_Nonnull)document

Discussion

Applies count measurement information to the annotation.

Count measurement requires a document for initialization.

Declared In

CPDFAnnotation.h

– countMeasureInfo

- (CPDFCountMeasureInfo *_Nullable)countMeasureInfo

– setAngleMeasureInfo:

Applies angle measurement information to the annotation.

- (void)setAngleMeasureInfo:(CPDFAngleMeasureInfo *_Nonnull)measureInfo

Discussion

Applies angle measurement information to the annotation.

Declared In

CPDFAnnotation.h

– angleMeasureInfo

- (CPDFAngleMeasureInfo *_Nullable)angleMeasureInfo

+ prepareRulerSnappingSnapshotWithDocument:pageIndex:mode:

Initializes the ruler snapping snapshot for a given page.

+ (BOOL)prepareRulerSnappingSnapshotWithDocument:(CPDFDocument *_Nonnull)document pageIndex:(NSInteger)pageIndex mode:(CPDFSnappingMode)mode

Parameters

document

The target document.

pageIndex

Zero-based page index.

mode

The snapping mode.

Return Value

YES if succeeded.

Discussion

Initializes the ruler snapping snapshot for a given page.

Declared In

CPDFAnnotation.h

+ closeRulerSnappingSnapshot

Closes the ruler snapping snapshot.

+ (BOOL)closeRulerSnappingSnapshot

Discussion

Closes the ruler snapping snapshot.

Declared In

CPDFAnnotation.h

+ snapPointToNearest:outMode:radius:

Snaps a point to the nearest snapping target within a radius.

+ (BOOL)snapPointToNearest:(CPDFKitPlatformPoint *_Nonnull)point outMode:(CPDFSnappingMode *_Nullable)outMode radius:(double)radius

Parameters

point

The input point (page space). On success it will be updated to the snapped point.

outMode

The output snapping mode if snapped (optional).

radius

The snapping radius.

Return Value

YES if a snapping target is found.

Discussion

Snaps a point to the nearest snapping target within a radius.

Declared In

CPDFAnnotation.h