CPDFView.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. //
  2. // CPDFView.h
  3. // ComPDFKit
  4. //
  5. // Copyright © 2014-2023 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. #import <ComPDFKit/CPDFKitPlatform.h>
  14. @class CPDFView, CPDFDocument, CPDFPage, CPDFSelection, CPDFDestination, CPDFFreeTextAnnotation, CPDFTextWidgetAnnotation;
  15. typedef NS_OPTIONS(NSInteger, CEditingSelectState) {
  16. CEditingSelectStateEmpty = 0,
  17. CEditingSelectStateEditTextArea,
  18. CEditingSelectStateEditNoneText,
  19. CEditingSelectStateEditSelectText,
  20. };
  21. typedef NS_OPTIONS(NSInteger, CEditingLoadType) {
  22. CEditingLoadTypeText = (1UL << 0),
  23. CEditingLoadTypeImage = (1UL << 1),
  24. };
  25. typedef NS_ENUM(NSInteger, CPDFDisplayDirection) {
  26. CPDFDisplayDirectionVertical = 0,
  27. CPDFDisplayDirectionHorizontal = 1,
  28. };
  29. typedef NS_ENUM(NSInteger, CPDFDisplayMode) {
  30. CPDFDisplayModeNormal = 0,
  31. CPDFDisplayModeNight = 1,
  32. CPDFDisplayModeSoft = 2,
  33. CPDFDisplayModeGreen = 3,
  34. CPDFDisplayModeCustom = 4
  35. };
  36. extern NSNotificationName const CPDFViewDocumentChangedNotification;
  37. extern NSNotificationName const CPDFViewPageChangedNotification;
  38. #pragma mark - CPDFEditArea
  39. @interface CPDFEditArea : NSObject
  40. /**
  41. * Gets the current page of the text block.
  42. */
  43. @property (nonatomic,readonly) CPDFPage *page;
  44. /**
  45. * Gets the position size of the text block.
  46. */
  47. @property (nonatomic,readonly) CGRect bounds;
  48. /**
  49. * Gets the current selection.
  50. */
  51. @property (nonatomic,readonly) CPDFSelection *selection;
  52. /**
  53. * Whether it is text code block.
  54. */
  55. - (BOOL)IsTextArea;
  56. @end
  57. #pragma mark - CPDFEditTextArea
  58. @interface CPDFEditTextArea : CPDFEditArea
  59. @end
  60. @interface CPDFEditingConfig : NSObject
  61. /**
  62. * Sets the unselected border color of the text code block.
  63. */
  64. @property (nonatomic,retain) CPDFKitPlatformColor *editingBorderColor;
  65. /**
  66. * Sets the selected border color of the text code block.
  67. */
  68. @property (nonatomic,retain) CPDFKitPlatformColor *editingSelectionBorderColor;
  69. /**
  70. * Border width of the text code block.
  71. */
  72. @property (nonatomic,assign) CGFloat editingBorderWidth;
  73. /**
  74. * Array of dashed lines of the text code block.
  75. */
  76. @property (nonatomic,retain) NSArray * editingBorderDashPattern;
  77. @end
  78. @protocol CPDFViewDelegate <NSObject>
  79. @optional
  80. - (void)PDFViewDocumentDidLoaded:(CPDFView *)pdfView;
  81. - (void)PDFViewCurrentPageDidChanged:(CPDFView *)pdfView;
  82. - (void)PDFViewDidClickOnLink:(CPDFView *)pdfView withURL:(NSString *)url;
  83. - (void)PDFViewPerformURL:(CPDFView *)pdfView withContent:(NSString *)content;
  84. - (void)PDFViewPerformUOP:(CPDFView *)pdfView withContent:(NSString *)content;
  85. - (void)PDFViewPerformPrint:(CPDFView *)pdfView;
  86. - (void)PDFViewPerformReset:(CPDFView *)pdfView;
  87. - (void)PDFViewShouldBeginEditing:(CPDFView *)pdfView textView:(UITextView *)textView forAnnotation:(CPDFFreeTextAnnotation *)annotation;
  88. - (void)PDFViewShouldEndEditing:(CPDFView *)pdfView textView:(UITextView *)textView forAnnotation:(CPDFFreeTextAnnotation *)annotation;
  89. - (void)PDFViewShouldBeginEditing:(CPDFView *)pdfView textView:(UITextView *)textView forTextWidget:(CPDFTextWidgetAnnotation *)textWidget;
  90. - (void)PDFViewShouldEndEditing:(CPDFView *)pdfView textView:(UITextView *)textView forTextWidget:(CPDFTextWidgetAnnotation *)textWidget;
  91. - (void)PDFViewDidEndDragging:(CPDFView *)pdfView;
  92. - (void)PDFViewEditingOperationDidChanged:(CPDFView *)pdfView;
  93. - (void)PDFViewEditingSelectStateDidChanged:(CPDFView *)pdfView;
  94. - (void)PDFEditingViewShouldBeginEditing:(CPDFView *)pdfView textView:(UITextView *)textView;
  95. - (void)PDFEditingViewShouldEndEditing:(CPDFView *)pdfView textView:(UITextView *)textView;
  96. @end
  97. /**
  98. * This class is the main view of ComPDFKit you can instantiate a CPDFView that will host the contents of a CPDFDocument.
  99. *
  100. * @discussion CPDFView may be the only class you need to deal with for adding PDF functionality to your application.
  101. * 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.
  102. * CPDFView also keeps track of page history. You can subclass CPDFView to create a custom PDF viewer.
  103. */
  104. @interface CPDFView : UIView
  105. #pragma mark - Document
  106. /**
  107. * Methods for associating a CPDFDocument with a CPDFView.
  108. */
  109. @property (nonatomic,retain) CPDFDocument *document;
  110. #pragma mark - Accessors
  111. /**
  112. * Returns the view’s delegate.
  113. *
  114. * @see CPDFViewDelegate
  115. */
  116. @property (nonatomic,assign) id<CPDFViewDelegate> delegate;
  117. /**
  118. * A Boolean value indicating whether the document displays two pages side-by-side.
  119. */
  120. @property (nonatomic,assign) BOOL displayTwoUp;
  121. /**
  122. * Specifies whether the first page is to be presented as a cover and displayed by itself (for two-up modes).
  123. */
  124. @property (nonatomic,assign) BOOL displaysAsBook;
  125. /**
  126. * The layout direction, either vertical or horizontal, for the given display mode.
  127. *
  128. * @discussion Defaults to vertical layout (CPDFDisplayDirectionVertical).
  129. * @see CPDFDisplayDirection
  130. */
  131. @property (nonatomic,assign) CPDFDisplayDirection displayDirection;
  132. /**
  133. * A Boolean value indicating whether the view is displaying page breaks.
  134. *
  135. * @discussion Toggle displaying or not displaying page breaks (spacing) between pages. This spacing value is defined by the pageBreakMargins property.
  136. * If displaysPageBreaks is NO, then pageBreakMargins will always return { 10.0, 10.0, 10.0, 10.0 }. Default is YES.
  137. */
  138. @property (nonatomic,assign) BOOL displaysPageBreaks;
  139. /**
  140. * The spacing between pages as defined by the top, bottom, left, and right margins.
  141. *
  142. * @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.
  143. * Note that pageBreakMargins only allows positive values and will clamp any negative value to 0.0.
  144. * 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 }.
  145. */
  146. @property (nonatomic,assign) UIEdgeInsets pageBreakMargins;
  147. /**
  148. * The page render mode, either normal, night, soft, green or custom, for the given display mode.
  149. *
  150. * @see CPDFDisplayMode
  151. */
  152. @property (nonatomic,assign) CPDFDisplayMode displayMode;
  153. /**
  154. * If displayMode is CPDFDisplayModeCustom, you may customize the color of the page rendering.
  155. */
  156. @property (nonatomic,retain) UIColor *displayModeCustomColor;
  157. /**
  158. * A Boolean value indicating whether the view is displaying page crop.
  159. *
  160. * @discussion Automatically crop out valid content from the page, If there is no content in the page, no cropping will be done.
  161. */
  162. @property (nonatomic,assign) BOOL displayCrop;
  163. /**
  164. * A Boolean value that determines whether scrolling is enabled for the document view.
  165. */
  166. @property (nonatomic,assign) BOOL scrollEnabled;
  167. /**
  168. * A Boolean value that determines whether scrolling is disabled in the vertical direction for the document view.
  169. */
  170. @property (nonatomic,assign) BOOL directionaHorizontalLockEnabled;
  171. /**
  172. * The current scale factor for the view.
  173. *
  174. * @discussion Method to get / set the current scaling on the displayed PDF document. Default is 1.0.
  175. */
  176. @property (nonatomic,assign) CGFloat scaleFactor;
  177. - (void)setScaleFactor:(CGFloat)scaleFactor animated:(BOOL)animated;
  178. #pragma mark - Draw
  179. @property (nonatomic,readonly) BOOL isDrawing;
  180. @property (nonatomic,readonly) BOOL isDrawErasing;
  181. - (void)beginDrawing;
  182. - (void)endDrawing;
  183. - (void)commitDrawing;
  184. - (void)setDrawErasing:(BOOL)isErasing;
  185. - (void)drawUndo;
  186. - (void)drawRedo;
  187. #pragma mark - Annotation
  188. - (void)editAnnotationFreeText:(CPDFFreeTextAnnotation *)freeText;
  189. - (void)commitEditAnnotationFreeText;
  190. - (void)setEditAnnotationFreeTextFont:(UIFont *)font;
  191. - (void)setEditAnnotationFreeTextColor:(UIColor *)color;
  192. #pragma mark - Page
  193. /**
  194. * Returns the current page index.
  195. */
  196. @property (nonatomic,readonly) NSInteger currentPageIndex;
  197. /**
  198. * Scrolls to the specified page.
  199. */
  200. - (void)goToPageIndex:(NSInteger)pageIndex animated:(BOOL)animated;
  201. /**
  202. * Returns a CPDFDestination object representing the current page and the current point in the view specified in page space.
  203. */
  204. @property (nonatomic,readonly) CPDFDestination *currentDestination;
  205. /**
  206. * Goes to the specified destination.
  207. *
  208. * Destinations include a page and a point on the page specified in page space.
  209. */
  210. - (void)goToDestination:(CPDFDestination *)destination animated:(BOOL)animated;
  211. /**
  212. * Goes to the specified rectangle on the specified page.
  213. *
  214. * @discussion This allows you to scroll the CPDFView object to a specific CPDFAnnotation or CPDFSelection object,
  215. * because both of these objects have bounds methods that return an annotation or selection position in page space.
  216. * 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.
  217. */
  218. - (void)goToRect:(CGRect)rect onPage:(CPDFPage *)page animated:(BOOL)animated;
  219. /**
  220. * Returns an array of CPDFPage objects that represent the currently visible pages.
  221. */
  222. @property (nonatomic,readonly) NSArray<CPDFPage *> *visiblePages;
  223. #pragma mark - Selection
  224. /**
  225. * Enter text selection mode.
  226. *
  227. * @discussion The scrollEnabled is NO in the text selection mode.
  228. */
  229. @property (nonatomic,assign) BOOL textSelectionMode;
  230. /**
  231. * Returns actual instance of the current CPDFSelection object.
  232. *
  233. * @discussion The view redraws as necessary but does not scroll.
  234. */
  235. @property (nonatomic,readonly) CPDFSelection *currentSelection;
  236. /**
  237. * Clears the selection.
  238. *
  239. * @discussion The view redraws as necessary but does not scroll.
  240. */
  241. - (void)clearSelection;
  242. /**
  243. * Goes to the first character of the specified selection.
  244. */
  245. - (void)goToSelection:(CPDFSelection *)selection animated:(BOOL)animated;
  246. /**
  247. * The following calls allow you to associate a CPDFSelection with a CPDFView.
  248. *
  249. * @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:].
  250. * This method allow you to highlight text perhaps to indicate matches from a text search. Commonly used for highlighting search results.
  251. */
  252. - (void)setHighlightedSelection:(CPDFSelection *)selection animated:(BOOL)animated;
  253. #pragma mark - Display
  254. /**
  255. * The innermost view used by CPDFView or by your CPDFView subclass.
  256. *
  257. * @discussion The innermost view is the one displaying the visible document pages.
  258. */
  259. - (UIScrollView *)documentView;
  260. /**
  261. * Performs layout of the inner views.
  262. *
  263. * @discussion The CPDFView actually contains several subviews. Changes to the PDF content may require changes to these inner views,
  264. * 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.
  265. * This method is called automatically from CPDFView methods that affect the visible layout (such as setDocument:).
  266. */
  267. - (void)layoutDocumentView;
  268. /**
  269. * Draw and render of the currently visible pages.
  270. */
  271. - (void)setNeedsDisplayForVisiblePages;
  272. /**
  273. * Draw and render of the specified page.
  274. */
  275. - (void)setNeedsDisplayForPage:(CPDFPage *)page;
  276. #pragma mark - Rendering
  277. /**
  278. * Draw and render a visible page to a context.
  279. *
  280. * @discussion For subclasses. This method is called for each visible page requiring rendering. By subclassing you can draw on top of the PDF page.
  281. */
  282. - (void)drawPage:(CPDFPage *)page toContext:(CGContextRef)context;
  283. #pragma mark - Menu
  284. - (NSArray<UIMenuItem *> *)menuItemsAtPoint:(CGPoint)point forPage:(CPDFPage *)page;
  285. #pragma mark - Touch
  286. - (void)touchBeganAtPoint:(CGPoint)point forPage:(CPDFPage *)page;
  287. - (void)touchMovedAtPoint:(CGPoint)point forPage:(CPDFPage *)page;
  288. - (void)touchEndedAtPoint:(CGPoint)point forPage:(CPDFPage *)page;
  289. - (void)touchCancelledAtPoint:(CGPoint)point forPage:(CPDFPage *)page;
  290. #pragma mark - Conversion
  291. /**
  292. * Converts a point from view space to page space.
  293. *
  294. * @discussion Page space is a coordinate system with the origin at the lower-left corner of the current page.
  295. * View space is a coordinate system with the origin at the upper-left corner of the current PDF view.
  296. */
  297. - (CGPoint)convertPoint:(CGPoint)point toPage:(CPDFPage *)page;
  298. /**
  299. * Converts a rectangle from view space to page space.
  300. *
  301. * @discussion Page space is a coordinate system with the origin at the lower-left corner of the current page.
  302. * View space is a coordinate system with the origin at the upper-left corner of the current PDF view.
  303. */
  304. - (CGRect)convertRect:(CGRect)rect toPage:(CPDFPage *)page;
  305. /**
  306. * Converts a point from page space to view space.
  307. *
  308. * @discussion Page space is a coordinate system with the origin at the lower-left corner of the current page.
  309. * View space is a coordinate system with the origin at the upper-left corner of the current PDF view.
  310. */
  311. - (CGPoint)convertPoint:(CGPoint)point fromPage:(CPDFPage *)page;
  312. /**
  313. * Converts a rectangle from page space to view space.
  314. *
  315. * @discussion Page space is a coordinate system with the origin at the lower-left corner of the current page.
  316. * View space is a coordinate system with the origin at the upper-left corner of the current PDF view.
  317. */
  318. - (CGRect)convertRect:(CGRect)rect fromPage:(CPDFPage *)page;
  319. #pragma mark - Edit
  320. /**
  321. * This method is about configuring of editing content.
  322. */
  323. @property (nonatomic,retain) CPDFEditingConfig *editingConfig;
  324. /**
  325. * Begins editing content.
  326. */
  327. - (void)beginEditingLoadType:(CEditingLoadType)editingLoadType;
  328. /**
  329. * Change editing content.
  330. */
  331. - (void)changeEditingLoadType:(CEditingLoadType)editingLoadType;
  332. /**
  333. * Ends editing content.
  334. */
  335. - (void)endOfEditing;
  336. /**
  337. * Submits the edited content.
  338. */
  339. - (void)commitEditing;
  340. /**
  341. * Gets whether to enter the editing mode.
  342. */
  343. - (BOOL)isEditing;
  344. /**
  345. * Whether the content is modified.
  346. */
  347. - (BOOL)isEdited;
  348. /**
  349. * The selected block.
  350. */
  351. - (CPDFEditArea *)editingArea;
  352. /**
  353. * Clicks the context menu of block.
  354. */
  355. - (NSArray<UIMenuItem *> *)menuItemsEditingAtPoint:(CGPoint)point forPage:(CPDFPage *)page;
  356. /**
  357. * Gets the font size of a text block or a piece of text.
  358. */
  359. - (CGFloat)editingSelectionFontSize;
  360. /**
  361. * Sets the font size of a text block or a piece of text.
  362. */
  363. - (void)setEditingSelectionFontSize:(CGFloat)fontSize;
  364. /**
  365. * Gets the font color of a text block or a piece of text.
  366. */
  367. - (CPDFKitPlatformColor *)editingSelectionFontColor;
  368. /**
  369. * Sets the font color of a text block or a piece of text.
  370. */
  371. - (void)setEditingSelectionFontColor:(CPDFKitPlatformColor *)fontColor;
  372. /**
  373. * Gets the alignment of a text block or a piece of text.
  374. */
  375. - (NSTextAlignment)editingSelectionAlignment;
  376. /**
  377. * Sets the alignment of a text block or a piece of text.
  378. */
  379. - (void)setCurrentSelectionAlignment:(NSTextAlignment)alignment;
  380. /**
  381. * The statuses when editing.
  382. *
  383. * @see CEditingSelectState
  384. */
  385. - (CEditingSelectState )editStatus;
  386. /**
  387. * Whether to support undo on current page.
  388. */
  389. - (BOOL)canEditTextUndo;
  390. /**
  391. * Whether to support redo on current page.
  392. */
  393. - (BOOL)canEditTextRedo;
  394. /**
  395. * Undo on current page.
  396. */
  397. - (void)editTextUndo;
  398. /**
  399. * Redo on current page.
  400. */
  401. - (void)editTextRedo;
  402. /**
  403. * The font name of the currently selected text block.
  404. */
  405. - (NSString *)editingSelectionFontName;
  406. /**
  407. * Sets the font name of the selected text block. (Several standard fonts are currently supported)
  408. */
  409. - (void)setEditingSelectionFontName:(NSString *)fontName;
  410. /**
  411. * Sets the currently selected text is italic.
  412. */
  413. - (void)setCurrentSelectionIsItalic:(BOOL)isItalic;
  414. /**
  415. * Whether the font of the currently selected text block is italic.
  416. */
  417. - (BOOL)isItalicCurrentSelection;
  418. /**
  419. * Sets the currently selected text is bold.
  420. */
  421. - (void)setCurrentSelectionIsBold:(BOOL)isBold;
  422. /**
  423. * Whether the font of the currently selected text block is bold.
  424. */
  425. - (BOOL)isBoldCurrentSelection;
  426. /**
  427. * Create a blank text block.
  428. * @param rect The area of the text box.
  429. * @param attributes The text font properties.
  430. * @param page The created page number.
  431. * @return Returns whether the creation is successful.
  432. */
  433. - (BOOL)createEmptyStringBounds:(CGRect)rect withAttributes:(NSDictionary<NSAttributedStringKey, id> *)attributes page:(CPDFPage *)page;
  434. @end