CPDFAnnotation.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //
  2. // CPDFAnnotation.h
  3. // ComPDFKit
  4. //
  5. // Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  8. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  9. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  10. // This notice may not be removed from this file.
  11. //
  12. #import <ComPDFKit/CPDFKitPlatform.h>
  13. #import <ComPDFKit/CPDFPage.h>
  14. #import <ComPDFKit/CPDFBorder.h>
  15. /**
  16. * A set of flags specifying various characteristics of the annotation.
  17. * ComPDFKit doesn't support all of those flag settings.
  18. */
  19. typedef NS_OPTIONS(NSInteger, CPDFAnnotationFlags) {
  20. /* [IGNORED] If set, ignore annotation AP stream if there is no handler available. */
  21. CPDFAnnotationFlagInvisible = 1,
  22. /* If set, do not display or print the annotation or allow it to interact with the user. */
  23. CPDFAnnotationFlagHidden = 1 << 1,
  24. /* [IGNORED] If set, print the annotation when the page is printed. */
  25. CPDFAnnotationFlagPrint = 1 << 2,
  26. /* [IGNORED] If set, don't scale the annotation’s appearance to match the magnification of the page. */
  27. CPDFAnnotationFlagNoZoom = 1 << 3,
  28. /* [IGNORED] If set, don't rotate the annotation’s appearance to match the rotation of the page. */
  29. CPDFAnnotationFlagNoRotate = 1 << 4,
  30. /* [IGNORED] If set, don't display the annotation on the screen. (But printing might be allowed) */
  31. CPDFAnnotationFlagNoView = 1 << 5,
  32. /**
  33. * If set, don’t allow the annotation to be deleted or its properties to be modified, including `contents`.
  34. * This is ignored for widget annotations (form elements).
  35. * For widget annotations the `isReadOnly` property of the associated form field should be used instead.
  36. * This flag only restricts the ComPDFKit UI and does not impact programmatic modification of the annotation.
  37. */
  38. CPDFAnnotationFlagReadOnly = 1 << 6,
  39. /* If set, don’t allow the annotation to be deleted or its properties to be modified, except for `contents`. */
  40. CPDFAnnotationFlagLocked = 1 << 7,
  41. /* [IGNORED] If set, invert the interpretation of the `.noView` flag for certain events. */
  42. CPDFAnnotationFlagToggleNoView = 1 << 8,
  43. /* [IGNORED] If set, don't allow the `contents` of the annotation to be modified by the user. */
  44. CPDFAnnotationFlagLockedContents = 1 << 9
  45. };
  46. /**
  47. * An annotation in a PDF document.
  48. *
  49. * @discussion In addition to its primary textual content, a PDF file can contain annotations that represent links, form elements, highlighting circles, textual notes, and so on.
  50. * Each annotation is associated with a specific location on a page and may offer interactivity with the user.
  51. *
  52. * This is the base class for all annotations. A CPDFAnnotation object by itself is not useful, only subclasses (like CPDFCircleAnnotation, CPDFTextAnnotation) are interesting.
  53. * In parsing a PDF however, any unknown or unsupported annotations will be represented as this base class.
  54. */
  55. @interface CPDFAnnotation : NSObject
  56. #pragma mark - Initializers
  57. /**
  58. * Initializes a PDF annotation object.
  59. *
  60. * @discussion Subclasses of CPDFAnnotation should use this method to initialize annotation instances.
  61. * Invoking initWithDocument: directly on a CPDFAnnotation object creates an illegal NULL type.
  62. */
  63. - (instancetype)initWithDocument:(CPDFDocument *)document;
  64. #pragma mark - Accessors
  65. /**
  66. * Returns the page that the annotation is associated with (may return nil if annotation not associated with a page).
  67. *
  68. * @discussion The addAnnotation: method in the CPDFPage class lets you associate an annotation with a page.
  69. */
  70. @property (nonatomic,readonly) CPDFPage *page;
  71. /**
  72. * Returns the type of the annotation. Examples include: "Text", "Link", "Line", etc.
  73. *
  74. * @discussion The type of the annotation. Types include Line, Link, Text, and so on, referring to the CPDFAnnotation subclasses.
  75. * In the Adobe PDF Specification, this attribute is called Subtype, and the common “type” for all annotations in the PDF Specification is Annot.
  76. */
  77. @property (nonatomic,readonly) NSString *type;
  78. /**
  79. * Method to get / set the bounding box for the annotation in page space. Required for all annotations.
  80. *
  81. * @discussion Page space is coordinate system with the origin at the lower-left corner of the current page.
  82. */
  83. @property (nonatomic,assign) CGRect bounds;
  84. /**
  85. * Method to get / set the textual content (if any) associated with the annotation.
  86. *
  87. * @discussion Textual content is typically associated with CPDFTextAnnotation and CPDFFreeTextAnnotation annotations.
  88. */
  89. @property (nonatomic,retain) NSString *contents;
  90. /**
  91. * Method to get / set the stroke thickness for the annotation.
  92. *
  93. * @discussion For the "geometry" annotations (Circle, Ink, Line, Square), the stroke thickness indicates the line width.
  94. * CPDFAnnotation markup types (Highlight, Strikethrough, Underline) ignores the stroke thickness.
  95. */
  96. @property (nonatomic,assign) CGFloat borderWidth;
  97. /**
  98. * Optional border or border style that describes how to draw the annotation border (if any).
  99. * @discussion 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.
  100. * CPDFAnnotation markup types (Highlight, Strikethrough, Underline) ignores the border.
  101. */
  102. @property (nonatomic,retain) CPDFBorder *border;
  103. /**
  104. * Method to get / set the opacity for the annotation.
  105. */
  106. @property (nonatomic,assign) CGFloat opacity;
  107. /**
  108. * Method to get / set the color for the annotation.
  109. * @discussion For many annotations ("Circle", "Square") the stroke color. Used for other annotations as well.
  110. */
  111. @property (nonatomic,retain) CPDFKitPlatformColor *color;
  112. @property (nonatomic,assign) BOOL isNoRotate;
  113. /**
  114. * Returns the modification date of the annotation.
  115. */
  116. - (NSDate *)modificationDate;
  117. - (void)setModificationDate:(NSDate *)modificationDate;
  118. /**
  119. * Returns the name of the user who created the annotation.
  120. */
  121. - (NSString *)userName;
  122. - (void)setUserName:(NSString *)userName;
  123. /**
  124. * Returns the flags of the annotation.
  125. *
  126. * @see CPDFAnnotationFlags
  127. */
  128. - (CPDFAnnotationFlags)flags;
  129. /**
  130. * Sets the flags of the annotation.
  131. *
  132. * @see CPDFAnnotationFlags
  133. */
  134. - (void)setFlags:(CPDFAnnotationFlags)flags;
  135. /**
  136. * This is a convenience property that checks for `CPDFAnnotationFlagHidden` in `flags`.
  137. */
  138. - (BOOL)isHidden;
  139. - (void)setHidden:(BOOL)hidden;
  140. /**
  141. * This is a convenience property that checks for `CPDFAnnotationFlagReadOnly` in `flags`.
  142. */
  143. - (BOOL)isReadOnly;
  144. - (void)setReadOnly:(BOOL)readOnly;
  145. /**
  146. * This is a convenience property that checks for `CPDFAnnotationFlagLocked` in `flags`.
  147. */
  148. - (BOOL)isLocked;
  149. - (void)setLocked:(BOOL)locked;
  150. /**
  151. * Update appearance stream for the annotation.
  152. *
  153. * @discussion ComPDFKit will update the annotation appearance by default when you modify the annotation properties.
  154. * You can also manually update the appearance by calling the updateAppearanceStream method,
  155. * but you must call the updateAppearanceStream method manually when you modify the bounds of CPDFTextAnnotation, CPDFStampAnnotation, CPDFSignatureAnnotation annotations.
  156. */
  157. - (void)updateAppearanceStream;
  158. #pragma mark - Drawing
  159. /**
  160. * Draw method. Draws in page-space relative to origin of "box" passed in and to the given context.
  161. */
  162. - (void)drawWithBox:(CPDFDisplayBox)box inContext:(CGContextRef)context;
  163. @end