iOS
ComPDFKit PDF SDK
Get Started

How to Make an iOS App in Objective-C with Default UI

 

"PDFViewer" for iOS sample projects comes with a default UI design, including the basic UI for the app and the feature modules UI, which are implemented using ComPDFKit PDF SDK and are shipped in the " PDFViewer / Source " folder. Also included is a PDFViewController view controller that contains ready-to-use UI module implementations.

 

Folder Description
PDFView PDFListView is a subclass of CPDFView that can add, drag and delete annotations, and perform custom drawing on top of the PDF page.
PDFViewerMode Allows user to pick display modes, switch between different themes and set crop mode.
PDFSlider Allows user to quickly skip through pages.
PDFBOTA The PDFBOTAViewController class is a container view controller that shows the bookmarks, outline, thumbtail and annotation list controls. A segmented control is used to select which child view controller to display.
PDFSearch Allows user to search, highlight all instances of a search term, and navigate among search results.
PDFToolbar PDFToolbar is a subclass of UIView that can configure the annotations toolbar.
PDFColor Allows user to customize color and opacity set.
PDFFreehand The PDFFreehandViewController class allows user to change the different properties of an ink annotation. Users can use it to customize selected annotations by changing their various appearance properties.
PDFShape The PDFShapeViewController class allows user to change the different properties of square, circle, and line annotation. Users can use it to customize selected annotations by changing their various appearance properties.
PDFLink The PDFLinkViewController class allows user to change the different properties of a link annotation. Users can use it to customize selected annotations by changing their various appearance properties.
PDFNote The PDFNoteViewController class allows user to read and edit content of note annotation.
PDFStamp Allows user to create standard stamp, and custom stamp to change text and image.
PDFSignature Allows user to add electronic drawn signatures to PDF documents.
PDFKeyboardToolbar The PDFKeyboardToolbar class shows freetext annotation properties in a top keyboard view, and users can change the color, font, and opacity with it.
PDFPageEdit Enables a whole host of document editing features, which includes new page creation, page reordering, rotation, extraction, and deletion.

 

1. Integrate Default UI into Your Apps

 

To add default UI into the "PDFViewer" project, please follows the steps below:

 

1.  Right-click the "PDFViewer" folder, select Add Files to "PDFViewer"... as shown in Figure 2-8.

 

Figure 2-8

 

2. Find and choose "PDFViewController.h""PDFViewController.m" and "Source" folder in the download package, and then click Add as shown in Figure 2-9.

 

Note: Make sure to check the "Copy items if needed" option.

 

Figure 2-9

3. Then, the "PDFViewer" project will look like the Figure 2-10.

 

Figure 2-10

 

To protect user privacy, an iOS app linked on or after iOS 10.0, and that accesses the device’s privacy-sensitive data, you need to do the following configuration in the “Info.plist“.

 

<key>NSCameraUsageDescription</key>
<string>Your consent is required before you could access the function.</string>

<key>NSMicrophoneUsageDescription</key>
<string>Your consent is required before you could access the function.</string>

<key>NSPhotoLibraryAddUsageDescription</key>
<string>Your consent is required before you could access the function.</string>

<key>NSPhotoLibraryUsageDescription</key>
<string>Your consent is required before you could access the function.</string>

 

2. How to Initialize the PDFViewController Class​

 

To initialize PDFViewController Class, refer to the following method in the PDFViewController class.

 

PDFViewController *vc = [[[PDFViewController alloc] initWithFilePath:filePath] autorelease];

 

3. How to Handle PDF Document Loading

 

To handle PDF document loading, refer to the following method in the "PDFViewController.m" file.

 

- (void)loadDocumentWithFilePath:(NSString *)filePath completion:(void (^)(BOOL result))completion;

 

4. How to Use the PDFListView Class

 

PDFListView is a subclass of CPDFView that contains operations for annotations.

 

1. Add support for Annotations

Set the annotationMode property to enter a different annotation mode, and click or drag to add a different annotation in the PDF view. Refer to the following method in the "PDFViewController.m" file.

 

- (PDFToolbar *)annotationToolbar;

 

2. Implementing delegate method

About Implementing delegate method, refer to the following method in the "PDFViewController.m" file.

 

// Add and modify text annotation
- (void)PDFViewPerformOpenNote:(PDFListView *)pdfView forAnnotation:(CPDFAnnotation *)annotation;

// Modify annotation color
- (void)PDFViewPerformChangeColor:(PDFListView *)pdfView forAnnotation:(CPDFAnnotation *)annotation;

// Share markup annotation
- (void)PDFViewPerformShare:(PDFListView *)pdfView forAnnotation:(CPDFMarkupAnnotation *)annotation;

// Save stamp image
- (void)PDFViewPerformSave:(PDFListView *)pdfView forAnnotation:(CPDFStampAnnotation *)annotation;

// Add popup for markup annotation
- (void)PDFViewPerformPopup:(PDFListView *)pdfView forAnnotation:(CPDFMarkupAnnotation *)annotation;

// Add and modify link annotation
- (void)PDFViewPerformEditLink:(PDFListView *)pdfView forAnnotation:(CPDFLinkAnnotation *)annotation;

// Signature widget add signature
- (void)PDFViewPerformSignatureWidget:(PDFListView *)pdfView forAnnotation:(CPDFSignatureWidgetAnnotation *)annotation;

// Share selection text
- (void)PDFViewPerformShare:(PDFListView *)pdfView forSelection:(CPDFSelection *)selection;

- (void)PDFViewPerformDefine:(PDFListView *)pdfView forSelection:(CPDFSelection *)selection;

// Search selection text for Google
- (void)PDFViewPerformGoogleSearch:(PDFListView *)pdfView forSelection:(CPDFSelection *)selection;

// Search selection text for Wiki
- (void)PDFViewPerformWikiSearch:(PDFListView *)pdfView forSelection:(CPDFSelection *)selection;

// Add Signture annotation
- (void)PDFViewPerformAddSignture:(PDFListView *)pdfView atPoint:(CGPoint)point forPage:(CPDFPage *)page;

// Add Stamp annotation
- (void)PDFViewPerformAddStamp:(PDFListView *)pdfView atPoint:(CGPoint)point forPage:(CPDFPage *)page;

// Add Image annotation
- (void)PDFViewPerformAddImage:(PDFListView *)pdfView atPoint:(CGPoint)point forPage:(CPDFPage *)page;

- (void)PDFViewPerformTouchEnded:(PDFListView *)pdfView;

// Page jump
- (void)PDFViewPerformWillGoTo:(PDFListView *)pdfView pageIndex:(NSInteger)pageIndex;

 

5. How to Use the PDFKeyboardToolbar Class

 

PDFKeyboardToolbar is the keyboard toolbar of the Freetext annotation input box.

 

- Initialize the PDFKeyboardToolbar class

Initialize the PDFKeyboardToolbar in the CPDFView delegate method, and refer to the following method in the "PDFViewController.m" file.

 

- (void)PDFViewShouldBeginEditing:(CPDFView *)pdfView textView:(UITextView *)textView forAnnotation:(CPDFFreeTextAnnotation *)annotation {
    self.annotationFreeText = annotation;
    PDFKeyboardToolbar *keyboardToolbar = [[[PDFKeyboardToolbar alloc] initWithFontName:annotation.font.fontName fontSize:annotation.font.pointSize] autorelease];
    keyboardToolbar.delegate = self;
    [keyboardToolbar refreshFontName:annotation.font.fontName fontSize:annotation.font.pointSize opacity:annotation.opacity];
    [keyboardToolbar bindToTextView:textView];
}

 

- Implementing delegate method

About Implementing delegate method, refer to the following method in the "PDFViewController.m" file.

 

// keyboard should dissmiss
- (void)keyboardShouldDissmiss:(PDFKeyboardToolbar *)toolbar;

// Modify font name of freetext annotation
- (void)keyboard:(PDFKeyboardToolbar *)toolbar updateFontName:(NSString *)fontName;

// Modify font size of freetext annotation
- (void)keyboard:(PDFKeyboardToolbar *)toolbar updateFontSize:(CGFloat)fontSize;

// Modify text color of freetext annotation
- (void)keyboard:(PDFKeyboardToolbar *)toolbar updateTextColor:(UIColor *)textColor;

// Modify text opacity of freetext annotation
- (void)keyboard:(PDFKeyboardToolbar *)toolbar updateOpacity:(CGFloat)opacity;