Introduction
MuPDF Android App Kit
MuPDF iOS App Kit
Download App Kit

Document Listeners

When developing your own custom UI, your application's ViewController should implement the ARDKBasicDocViewDelegate and ARDKDocumentEventTarget protocols to intercept events.

Additionally, you can listen for basic success or error for a document load.

ARDKBasicDocViewDelegate

Document completed

Called when the document has completely loaded.

Swift
/// Inform the UI that both the loading of the document
/// and the initial rendering have completed. An app might
/// display a busy indicator while a document is initially
/// loading, and use this delegate method to dismiss the
/// indicator.
func loadingAndFirstRenderComplete() {

}
Objective C
/// Inform the UI that both the loading of the document
/// and the initial rendering have completed. An app might
/// display a busy indicator while a document is initially
/// loading, and use this delegate method to dismiss the
/// indicator.
- (void)loadingAndFirstRenderComplete {

}

UI update

Called when the document changes selection state and the UI should update appropriately.

Swift
/// Tell the UI to update according to changes in the
/// selection state of the document. This allows an app
/// to refresh any currently displayed state information.
/// E.g., a button used to toggle whether the currently
/// selected text is bold, may show a highlight to indicate
/// bold or not. This call would be the appropriate place to
/// ensure that highlight reflects the current state.
func updateUI {

}
Objective C
/// Tell the UI to update according to changes in the
/// selection state of the document. This allows an app
/// to refresh any currently displayed state information.
/// E.g., a button used to toggle whether the currently
/// selected text is bold, may show a highlight to indicate
/// bold or not. This call would be the appropriate place to
/// ensure that highlight reflects the current state.
- (void)updateUI {

}

Page change

Called on a page change event - i.e. when the document has scrolled or jumped to another page.

Swift
/// Tell the UI that the document has scrolled to a new page.
/// An app may use this to update a label showing the current
/// displayed page number or to scroll a view of thumbnails
/// to the correct page.
func viewDidScroll(toPage page: Int) {

}
Objective C
/// Tell the UI that the document has scrolled to a new page.
/// An app may use this to update a label showing the current
/// displayed page number or to scroll a view of thumbnails
/// to the correct page.
- (void)viewDidScrollToPage:(NSInteger)page {

}

Scrolling completed

Called when a user scrolling event has concluded it's animation.

Swift
/// Tell the delegate when a scrolling animation concludes.
/// This can be used like viewDidScrollToPage, but for more
/// intensive tasks that one wouldn't want to run repeatedly
/// during scrolling.
func scrollViewDidEndScrollingAnimation {

}
Objective C
/// Tell the delegate when a scrolling animation concludes.
/// This can be used like viewDidScrollToPage, but for more
/// intensive tasks that one wouldn't want to run repeatedly
/// during scrolling.
- (void)scrollViewDidEndScrollingAnimation {

}

Swallowing tap selections

An application developer has the ability to intercept tap events on the document to prevent a default selection from occurring. To do this the following delegate methods need to return false. Essentially a document is in a read only state in this mode.

Swift
/// Offer the UI the opportunity to swallow a tap that
/// may have otherwise caused selection. Return YES
/// to swallow the event. This is not called for taps
/// over links or form fields. An app might use this to
/// provide a way out of a special mode (full-screen for
/// example). In that case, if the app is using the tap to
/// provoke exit from full-screen mode, then it would return
/// YES from this method to avoid the tap being interpreted
/// also by the main document view.
func swallowSelectionTap() -> Bool {
    return false
}

/// Offer the UI the opportunity to swallow a double tap that
/// may have otherwise caused selection. Return YES to swallow
/// the event. This is not called for double taps over links
/// or form fields. An app might use this in a way similar to
/// that appropriate to swallowSelectionTap.
func swallowSelectionDoubleTap() -> Bool {
    return false
}
Objective C
/// Offer the UI the opportunity to swallow a tap that
/// may have otherwise caused selection. Return YES
/// to swallow the event. This is not called for taps
/// over links or form fields. An app might use this to
/// provide a way out of a special mode (full-screen for
/// example). In that case, if the app is using the tap to
/// provoke exit from full-screen mode, then it would return
/// YES from this method to avoid the tap being interpreted
/// also by the main document view.
- (BOOL)swallowSelectionTap {
    return NO;
}

/// Offer the UI the opportunity to swallow a double tap that
/// may have otherwise caused selection. Return YES to swallow
/// the event. This is not called for double taps over links
/// or form fields. An app might use this in a way similar to
/// that appropriate to swallowSelectionTap.
- (BOOL)swallowSelectionDoubleTap {
    return NO;
}

NOTE
It is important that these delegate methods return true by default for expected text and annotation selection behaviour to occur.

Inhibiting the keyboard

If required an application developer can prevent the keyboard from appearing.

Swift
/// Called to allow the delegate to inhibit the keyboard. An app
/// might use this in special modes where there is limited
/// vertical space, so as to avoid the keyboard appearing.
func inhibitKeyBoard -> Bool {
    return false
}
Objective C
/// Called to allow the delegate to inhibit the keyboard. An app
/// might use this in special modes where there is limited
/// vertical space, so as to avoid the keyboard appearing.
- (BOOL)inhibitKeyBoard {
    return NO;
}

Opening a URL

This method is called when the document interaction invokes a URL to open.

Swift
/// The document view calls this when
/// a link to an external document is tapped.
func callOpenUrlHandler(_ url: URL!, fromVC presentingView: UIViewController!) {

}
Objective C
- (void)callOpenUrlHandler:(NSURL *)url fromVC:(UIViewController *)presentingView {

}

ARDKDocumentEventTarget

Page load events and loading complete

Called as pages are loaded from the document.

Swift
/// Called as pages are loaded from the document.
/// There may be further calls, e.g., if pages
/// are added or deleted from the document.
func updatePageCount(_ pageCount: Int, andLoadingComplete complete: Bool) {

}
Objective C
/// Called as pages are loaded from the document.
/// There may be further calls, e.g., if pages
/// are added or deleted from the document.
- (void)updatePageCount:(NSInteger)pageCount andLoadingComplete:(BOOL)complete {

}

Selection changes

Called when a selection is made within the document, moved or removed.

Swift
func selectionHasChanged {

}

// there is also a function method which can be
// associated against the instance of `MuPDFDKDoc` as follows
doc.onSelectionChanged = {

}
Objective C
- (void)selectionHasChanged {

}

// there is also a function method which can be
// associated against the instance of `MuPDFDKDoc` as follows
doc.onSelectionChanged = ^() {

};

Selection types

Once a selection has been made on a document it might be necessary to understand what type of selection it is and if there is any further data. For example, is the user's selection a redaction annotation or is it a note annotation? Does the selected annotation have a date associated with it?

To determine this information, the following type of query against the document instance (MuPDFDKDoc) can be made:

Swift
let selectionIsRedaction:Bool = doc.selectionIsRedaction
let selectionIsNote:Bool = doc.selectionIsAnnotationWithText
let selectedAnnotationsDate:Date? = doc.selectedAnnotationsDate
Objective C
BOOL selectionIsRedaction = doc.selectionIsRedaction;
BOOL selectionIsNote = doc.selectionIsAnnotationWithText;
NSDate* selectedAnnotationsDate = doc.selectedAnnotationsDate;

The following table defines the full set of available selections:

variable name type description return type
selectionIsWidget form widget Whether a form widget is currently selected Bool
selectedAnnotationsText text The text string associated with the selected annotation String or nil
selectedAnnotationsDate date The date associated with the selected annotation Date or nil
selectedAnnotationsAuthor author The author of the selected annotation String or nil
selectionIsRedaction redaction Whether a redaction annotation is selected Bool
selectionIsTextHighlight highlight Whether a text highlight annotation is selected Bool
selectionIsAnnotationWithText note Whether an annotation that has text is selected Bool
haveTextSelection text Whether text is currently selected Bool
haveAnnotationSelection any Whether an annotation is currently selected Bool

Document load listeners

When a document load is requested, the following function blocks can be defined for the document (i.e. the instance of MuPDFDKDoc).

Swift
doc.successBlock = {

}

doc.errorBlock = {(error:ARDKDocErrorType?) in

}
Objective C
doc.successBlock = ^() {

};

doc.errorBlock = ^(ARDKDocErrorType error) {

};