CPDFPage.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. //
  2. // CPDFPage.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. /**
  14. * The following box types may be used with CPDFPage drawing and bounds-setting methods.
  15. * See the Adobe PDF Specification for more information on box types, units, and coordinate systems.
  16. */
  17. typedef NS_ENUM(NSInteger, CPDFDisplayBox) {
  18. /** A rectangle defining the boundaries of the physical medium for display or printing, expressed in default user-space units. */
  19. CPDFDisplayMediaBox = 0,
  20. /** A rectangle defining the boundaries of the visible region , expressed in default user-space units. Default value equal to CPDFDisplayMediaBox. */
  21. CPDFDisplayCropBox = 1,
  22. /** A rectangle defining the boundaries of the clip region for the page contents in a production environment. Default value equal to CPDFDisplayCropBox. */
  23. CPDFDisplayBleedBox = 2,
  24. /** A rectangle defining the intended boundaries of the finished page. Default value equal to CPDFDisplayCropBox. */
  25. CPDFDisplayTrimBox = 3,
  26. /** A rectangle defining the boundaries of the page’s meaningful content including surrounding white space intended for display. Default value equal to CPDFDisplayCropBox. */
  27. CPDFDisplayArtBox = 4
  28. };
  29. @class CPDFDocument, CPDFAnnotation, CPDFSelection;
  30. /**
  31. * CPDFPage, a subclass of NSObject, defines methods used to render PDF pages and work with annotations, text, and selections.
  32. *
  33. * @discussion CPDFPage is a logical representation of a PDF document's page. Your application instantiates a CPDFPage object by asking for one from a CPDFDocument object.
  34. * For simple display and navigation of PDF documents within your application, you don’t need to use CPDFPage. You need only use CPDFView.
  35. */
  36. @interface CPDFPage : NSObject
  37. #pragma mark - Accessors
  38. /**
  39. * Returns the CPDFDocument object with which the page is associated.
  40. */
  41. @property (nonatomic,readonly) CPDFDocument *document;
  42. /**
  43. * Returns the label for the page.
  44. *
  45. * @discussion Typically, the label is “1” for the first page, “2” for the second page, and so on, but nonnumerical labels are also possible (such as “xxi”, “4-1” and so on).
  46. */
  47. @property (nonatomic,readonly) NSString *label;
  48. /**
  49. * Returns the bounds for the specified PDF display box.
  50. *
  51. * @see CPDFDisplayBox
  52. */
  53. - (CGRect)boundsForBox:(CPDFDisplayBox)box;
  54. /**
  55. * Sets the bounds for the specified box.
  56. *
  57. * @discussion If the box does not exist, this method creates it for you.
  58. * @see CPDFDisplayBox
  59. */
  60. - (void)setBounds:(CGRect)bounds forBox:(CPDFDisplayBox)box;
  61. /**
  62. * Sets the rotation angle for the page in degrees.
  63. *
  64. * @discussion Rotation on a page. Must be 0, 90, 180 or 270 (negative rotations will be "normalized" to one of 0, 90, 180 or 270).
  65. * Some PDF's have an inherent rotation and so -[rotation] may be non-zero when a PDF is first opened.
  66. */
  67. @property (nonatomic,assign) NSInteger rotation;
  68. @property (nonatomic,readonly) CGRect bounds;
  69. /**
  70. * Returns the size of page after rotation.
  71. */
  72. @property (nonatomic,readonly) CGSize size;
  73. #pragma mark - Annotations
  74. /**
  75. * Returns an array containing the page’s annotations.
  76. *
  77. * @discussion The elements of the array will most likely be typed to subclasses of the CPDFAnnotation class.
  78. */
  79. @property (nonatomic,readonly) NSArray<CPDFAnnotation *> *annotations;
  80. /**
  81. * Adds the specified annotation object to the page.
  82. */
  83. - (void)addAnnotation:(CPDFAnnotation *)annotation;
  84. /**
  85. * Removes the specified annotation from the page.
  86. */
  87. - (void)removeAnnotation:(CPDFAnnotation *)annotation;
  88. /**
  89. * Removes all annotations from the page.
  90. */
  91. - (void)removeAllAnnotations;
  92. /**
  93. * Returns the annotation, if there is one, at the specified point.
  94. *
  95. * @discussion Use this method for hit-testing based on the current cursor position. If more than one annotation shares the specified point,
  96. * the frontmost (or topmost) one is returned (the annotations are searched in reverse order of their appearance in the PDF data file). Returns NULL if there is no annotation at point.
  97. * Specify the point in page space. Page space is a coordinate system with the origin at the lower-left corner of the current page.
  98. */
  99. - (CPDFAnnotation *)annotationAtPoint:(CGPoint)point;
  100. - (BOOL)annotation:(CPDFAnnotation *)annotation atPoint:(CGPoint)point;
  101. #pragma mark - Conversion
  102. /**
  103. * This transform correctly rotates and offsets based on the given page's rotation property.
  104. */
  105. - (CGAffineTransform)transform;
  106. #pragma mark - Rendering
  107. /**
  108. * Convenience function that returns an image of this page, with annotations.
  109. */
  110. - (CPDFKitPlatformImage *)thumbnailOfSize:(CGSize)size;
  111. #pragma mark - Text
  112. /**
  113. * Returns the number of characters on the page, including whitespace characters.
  114. *
  115. * @discussion Number of characters on the page (including linefeeds and spaces inserted).
  116. */
  117. @property (nonatomic,readonly) NSUInteger numberOfCharacters;
  118. /**
  119. * Returns the bounds, in page space, of the character at the specified index.
  120. *
  121. * @discussion In the unlikely event that there is more than one character at the specified index point, only the bounds of the first character is returned.
  122. * Page space is a coordinate system with the origin at the lower-left corner of the current page. Note that the bounds returned are not guaranteed to have integer coordinates.
  123. */
  124. - (CGRect)characterBoundsAtIndex:(NSInteger)index;
  125. /**
  126. * Returns the character index value for the specified point in page space.
  127. *
  128. * @discussion Returns the index of the first character if multiple characters are at this point. If there is no character at the specified point, the method returns -1.
  129. * Page space is a coordinate system with the origin at the lower-left corner of the current page.
  130. */
  131. - (NSInteger)characterIndexAtPoint:(CGPoint)point;
  132. /**
  133. * Returns an NSString object representing the text on the page.
  134. *
  135. * @discussion String (with linefeeds and in some cases spaces inserted) representing the text on the page.
  136. */
  137. @property (nonatomic,readonly) NSString *string;
  138. /**
  139. * Returns the text enclosed within the specified rectangle, expressed in page coordinates.
  140. *
  141. * @discussion Given a rect in page-space, returns a selection representing enclosed text on page.
  142. */
  143. - (NSString *)stringForRect:(CGRect)rect;
  144. /**
  145. * Returns the text enclosed within the specified range.
  146. */
  147. - (NSString *)stringForRange:(NSRange)range;
  148. #pragma mark - Selections
  149. /**
  150. * Returns the text contained within the specified range.
  151. *
  152. * @discussion Given a range, returns a selection representing text within that range. Will clamp any range that goes out of bounds. Will return NULL for an empty selection.
  153. */
  154. - (CPDFSelection *)selectionForRange:(NSRange)range;
  155. #pragma mark - Redact
  156. /**
  157. * Applies redaction annotations in the page.
  158. */
  159. - (void)applyRedactions;
  160. @end