CPDFView.h 17 KB

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