CPDFView.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. //
  2. // CPDFView.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 <UIKit/UIKit.h>
  13. typedef NS_ENUM(NSInteger, CPDFDisplayDirection) {
  14. CPDFDisplayDirectionVertical = 0,
  15. CPDFDisplayDirectionHorizontal = 1,
  16. };
  17. typedef NS_ENUM(NSInteger, CPDFDisplayMode) {
  18. CPDFDisplayModeNormal = 0,
  19. CPDFDisplayModeNight = 1,
  20. CPDFDisplayModeSoft = 2,
  21. CPDFDisplayModeGreen = 3,
  22. CPDFDisplayModeCustom = 4
  23. };
  24. @class CPDFView, CPDFDocument, CPDFPage, CPDFSelection, CPDFDestination, CPDFFreeTextAnnotation, CPDFTextWidgetAnnotation;
  25. @protocol CPDFViewDelegate <NSObject>
  26. @optional
  27. - (void)PDFViewDocumentDidLoaded:(CPDFView *)pdfView;
  28. - (void)PDFViewCurrentPageDidChanged:(CPDFView *)pdfView;
  29. - (void)PDFViewDidClickOnLink:(CPDFView *)pdfView withURL:(NSString *)url;
  30. - (void)PDFViewPerformURL:(CPDFView *)pdfView withContent:(NSString *)content;
  31. - (void)PDFViewPerformUOP:(CPDFView *)pdfView withContent:(NSString *)content;
  32. - (void)PDFViewPerformPrint:(CPDFView *)pdfView;
  33. - (void)PDFViewPerformReset:(CPDFView *)pdfView;
  34. - (void)PDFViewShouldBeginEditing:(CPDFView *)pdfView textView:(UITextView *)textView forAnnotation:(CPDFFreeTextAnnotation *)annotation;
  35. - (void)PDFViewShouldEndEditing:(CPDFView *)pdfView textView:(UITextView *)textView forAnnotation:(CPDFFreeTextAnnotation *)annotation;
  36. - (void)PDFViewShouldBeginEditing:(CPDFView *)pdfView textView:(UITextView *)textView forTextWidget:(CPDFTextWidgetAnnotation *)textWidget;
  37. - (void)PDFViewShouldEndEditing:(CPDFView *)pdfView textView:(UITextView *)textView forTextWidget:(CPDFTextWidgetAnnotation *)textWidget;
  38. - (void)PDFViewDidEndDragging:(CPDFView *)pdfView;
  39. @end
  40. /**
  41. * This class is the main view of ComPDFKit you can instantiate a CPDFView that will host the contents of a CPDFDocument.
  42. *
  43. * @discussion CPDFView may be the only class you need to deal with for adding PDF functionality to your application.
  44. * It lets you display PDF data and allows users to select content, navigate through a document, set zoom level, and copy textual content to the Pasteboard.
  45. * CPDFView also keeps track of page history. You can subclass CPDFView to create a custom PDF viewer.
  46. */
  47. @interface CPDFView : UIView
  48. #pragma mark - Document
  49. /**
  50. * Methods for associating a CPDFDocument with a CPDFView.
  51. */
  52. @property (nonatomic,retain) CPDFDocument *document;
  53. #pragma mark - Accessors
  54. /**
  55. * Returns the view’s delegate.
  56. *
  57. * @see CPDFViewDelegate
  58. */
  59. @property (nonatomic,assign) id<CPDFViewDelegate> delegate;
  60. /**
  61. * A Boolean value indicating whether the document displays two pages side-by-side.
  62. */
  63. @property (nonatomic,assign) BOOL displayTwoUp;
  64. /**
  65. * Specifies whether the first page is to be presented as a cover and displayed by itself (for two-up modes).
  66. */
  67. @property (nonatomic,assign) BOOL displaysAsBook;
  68. /**
  69. * The layout direction, either vertical or horizontal, for the given display mode.
  70. *
  71. * @discussion Defaults to vertical layout (CPDFDisplayDirectionVertical).
  72. * @see CPDFDisplayDirection
  73. */
  74. @property (nonatomic,assign) CPDFDisplayDirection displayDirection;
  75. /**
  76. * A Boolean value indicating whether the view is displaying page breaks.
  77. *
  78. * @discussion Toggle displaying or not displaying page breaks (spacing) between pages. This spacing value is defined by the pageBreakMargins property.
  79. * If displaysPageBreaks is NO, then pageBreakMargins will always return { 10.0, 10.0, 10.0, 10.0 }. Default is YES.
  80. */
  81. @property (nonatomic,assign) BOOL displaysPageBreaks;
  82. /**
  83. * The spacing between pages as defined by the top, bottom, left, and right margins.
  84. *
  85. * @discussion If displaysPageBreaks is enabled, you may customize the spacing between pages by defining margins for the top, bottom, left, and right of each page.
  86. * Note that pageBreakMargins only allows positive values and will clamp any negative value to 0.0.
  87. * By default, if displaysPageBreaks is enabled, pageBreakMargins is { 10.0, 10.0, 10.0, 10.0 } (with respect to top, left, bottom, right), otherwise it is { 0.0, 0.0, 0.0, 0.0 }.
  88. */
  89. @property (nonatomic,assign) UIEdgeInsets pageBreakMargins;
  90. /**
  91. * The page render mode, either normal, night, soft, green or custom, for the given display mode.
  92. *
  93. * @see CPDFDisplayMode
  94. */
  95. @property (nonatomic,assign) CPDFDisplayMode displayMode;
  96. /**
  97. * If displayMode is CPDFDisplayModeCustom, you may customize the color of the page rendering.
  98. */
  99. @property (nonatomic,retain) UIColor *displayModeCustomColor;
  100. /**
  101. * A Boolean value indicating whether the view is displaying page crop.
  102. *
  103. * @discussion Automatically crop out valid content from the page, If there is no content in the page, no cropping will be done.
  104. */
  105. @property (nonatomic,assign) BOOL displayCrop;
  106. /**
  107. * A Boolean value that determines whether scrolling is enabled for the document view.
  108. */
  109. @property (nonatomic,assign) BOOL scrollEnabled;
  110. /**
  111. * A Boolean value that determines whether scrolling is disabled in the vertical direction for the document view.
  112. */
  113. @property (nonatomic,assign) BOOL directionaHorizontalLockEnabled;
  114. /**
  115. * The current scale factor for the view.
  116. *
  117. * @discussion Method to get / set the current scaling on the displayed PDF document. Default is 1.0.
  118. */
  119. @property (nonatomic,assign) CGFloat scaleFactor;
  120. - (void)setScaleFactor:(CGFloat)scaleFactor animated:(BOOL)animated;
  121. #pragma mark - Draw
  122. @property (nonatomic,readonly) BOOL isDrawing;
  123. @property (nonatomic,readonly) BOOL isDrawErasing;
  124. - (void)beginDrawing;
  125. - (void)endDrawing;
  126. - (void)commitDrawing;
  127. - (void)setDrawErasing:(BOOL)isErasing;
  128. - (void)drawUndo;
  129. - (void)drawRedo;
  130. #pragma mark - Annotation
  131. - (void)editAnnotationFreeText:(CPDFFreeTextAnnotation *)freeText;
  132. - (void)commitEditAnnotationFreeText;
  133. - (void)setEditAnnotationFreeTextFont:(UIFont *)font;
  134. - (void)setEditAnnotationFreeTextColor:(UIColor *)color;
  135. #pragma mark - Page
  136. /**
  137. * Returns the current page index.
  138. */
  139. @property (nonatomic,readonly) NSInteger currentPageIndex;
  140. /**
  141. * Scrolls to the specified page.
  142. */
  143. - (void)goToPageIndex:(NSInteger)pageIndex animated:(BOOL)animated;
  144. /**
  145. * Returns a CPDFDestination object representing the current page and the current point in the view specified in page space.
  146. */
  147. @property (nonatomic,readonly) CPDFDestination *currentDestination;
  148. /**
  149. * Goes to the specified destination.
  150. *
  151. * Destinations include a page and a point on the page specified in page space.
  152. */
  153. - (void)goToDestination:(CPDFDestination *)destination animated:(BOOL)animated;
  154. /**
  155. * Goes to the specified rectangle on the specified page.
  156. *
  157. * @discussion This allows you to scroll the CPDFView object to a specific CPDFAnnotation or CPDFSelection object,
  158. * because both of these objects have bounds methods that return an annotation or selection position in page space.
  159. * Note that rect is specified in page-space coordinates. Page space is a coordinate system with the origin at the lower-left corner of the current page.
  160. */
  161. - (void)goToRect:(CGRect)rect onPage:(CPDFPage *)page animated:(BOOL)animated;
  162. /**
  163. * Returns an array of CPDFPage objects that represent the currently visible pages.
  164. */
  165. @property (nonatomic,readonly) NSArray<CPDFPage *> *visiblePages;
  166. #pragma mark - Selection
  167. /**
  168. * Enter text selection mode.
  169. *
  170. * @discussion The scrollEnabled is NO in the text selection mode.
  171. */
  172. @property (nonatomic,assign) BOOL textSelectionMode;
  173. /**
  174. * Returns actual instance of the current CPDFSelection object.
  175. *
  176. * @discussion The view redraws as necessary but does not scroll.
  177. */
  178. @property (nonatomic,readonly) CPDFSelection *currentSelection;
  179. /**
  180. * Clears the selection.
  181. *
  182. * @discussion The view redraws as necessary but does not scroll.
  183. */
  184. - (void)clearSelection;
  185. /**
  186. * Goes to the first character of the specified selection.
  187. */
  188. - (void)goToSelection:(CPDFSelection *)selection animated:(BOOL)animated;
  189. /**
  190. * The following calls allow you to associate a CPDFSelection with a CPDFView.
  191. *
  192. * @discussion The selection do not go away when the user clicks in the CPDFView, etc. You must explicitly remove them by passing nil to -[setHighlightedSelection:animated:].
  193. * This method allow you to highlight text perhaps to indicate matches from a text search. Commonly used for highlighting search results.
  194. */
  195. - (void)setHighlightedSelection:(CPDFSelection *)selection animated:(BOOL)animated;
  196. #pragma mark - Display
  197. /**
  198. * The innermost view used by CPDFView or by your CPDFView subclass.
  199. *
  200. * @discussion The innermost view is the one displaying the visible document pages.
  201. */
  202. - (UIScrollView *)documentView;
  203. /**
  204. * Performs layout of the inner views.
  205. *
  206. * @discussion The CPDFView actually contains several subviews. Changes to the PDF content may require changes to these inner views,
  207. * so you must call this method explicitly if you use PDF Kit utility classes to add or remove a page, rotate a page, or perform other operations affecting visible layout.
  208. * This method is called automatically from CPDFView methods that affect the visible layout (such as setDocument:).
  209. */
  210. - (void)layoutDocumentView;
  211. /**
  212. * Draw and render of the currently visible pages.
  213. */
  214. - (void)setNeedsDisplayForVisiblePages;
  215. /**
  216. * Draw and render of the specified page.
  217. */
  218. - (void)setNeedsDisplayForPage:(CPDFPage *)page;
  219. #pragma mark - Rendering
  220. /**
  221. * Draw and render a visible page to a context.
  222. *
  223. * @discussion For subclasses. This method is called for each visible page requiring rendering. By subclassing you can draw on top of the PDF page.
  224. */
  225. - (void)drawPage:(CPDFPage *)page toContext:(CGContextRef)context;
  226. #pragma mark - Menu
  227. - (NSArray<UIMenuItem *> *)menuItemsAtPoint:(CGPoint)point forPage:(CPDFPage *)page;
  228. #pragma mark - Touch
  229. - (void)touchBeganAtPoint:(CGPoint)point forPage:(CPDFPage *)page;
  230. - (void)touchMovedAtPoint:(CGPoint)point forPage:(CPDFPage *)page;
  231. - (void)touchEndedAtPoint:(CGPoint)point forPage:(CPDFPage *)page;
  232. - (void)touchCancelledAtPoint:(CGPoint)point forPage:(CPDFPage *)page;
  233. #pragma mark - Conversion
  234. /**
  235. * Converts a point from view space to page space.
  236. *
  237. * @discussion Page space is a coordinate system with the origin at the lower-left corner of the current page.
  238. * View space is a coordinate system with the origin at the upper-left corner of the current PDF view.
  239. */
  240. - (CGPoint)convertPoint:(CGPoint)point toPage:(CPDFPage *)page;
  241. /**
  242. * Converts a rectangle from view space to page space.
  243. *
  244. * @discussion Page space is a coordinate system with the origin at the lower-left corner of the current page.
  245. * View space is a coordinate system with the origin at the upper-left corner of the current PDF view.
  246. */
  247. - (CGRect)convertRect:(CGRect)rect toPage:(CPDFPage *)page;
  248. /**
  249. * Converts a point from page space to view space.
  250. *
  251. * @discussion Page space is a coordinate system with the origin at the lower-left corner of the current page.
  252. * View space is a coordinate system with the origin at the upper-left corner of the current PDF view.
  253. */
  254. - (CGPoint)convertPoint:(CGPoint)point fromPage:(CPDFPage *)page;
  255. /**
  256. * Converts a rectangle from page space to view space.
  257. *
  258. * @discussion Page space is a coordinate system with the origin at the lower-left corner of the current page.
  259. * View space is a coordinate system with the origin at the upper-left corner of the current PDF view.
  260. */
  261. - (CGRect)convertRect:(CGRect)rect fromPage:(CPDFPage *)page;
  262. @end