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

Document Options & Listeners

Options

An application developer can register options for the following in the MuPDF SDK:

Property Capability
Editing Enable
Save As Enable
Open In Enable
Sharing Enable
External Clipboard In Enable
External Clipboard Out Enable
Printing Enable
Launch External Url Enable
Form Filling Enable
Form Signing Enable
Redactions Enable
Full Screen Enable
Invert Content In Dark Mode Enable

To do so a developer should instantiate ConfigOptions, set the required variables within that object, and then register it against the SODKLib object.

The following code example disables editing on a document:

Kotlin
import com.artifex.solib.ConfigOptions
import com.artifex.solib.SODKLib

fun setupConfigOptions() {
    var configOptions:ConfigOptions = ConfigOptions()
    configOptions.isEditingEnabled = false
    SODKLib.setAppConfigOptions(configOptions)
}
Java
import com.artifex.solib.ConfigOptions;
import com.artifex.solib.SODKLib;

public void setupConfigOptions() {
    ConfigOptions configOptions = new ConfigOptions();
    configOptions.setEditingEnabled(false);
    SODKLib.setAppConfigOptions(configOptions);
}

Listeners

Document listeners should only be required when using the Custom UI as the application developer is responsible for providing their own UI to manage relevant document events.

Available document listeners are as follows:

Page loaded

Called when pages are loaded.

Kotlin
mDocumentView.setDocumentListener(object : DocumentView.DocumentListener {
    override fun onPageLoaded(pagesLoaded: Int) {

    }
}
Java
mDocumentView.setDocumentListener(new DocumentView.DocumentListener() {
    @Override
    public void onPageLoaded(int pagesLoaded) {

    }
}

Document completed

Called when the document has completely loaded.

Kotlin
mDocumentView.setDocumentListener(object : DocumentView.DocumentListener {
    override fun onDocCompleted() {

    }
}
Java
mDocumentView.setDocumentListener(new DocumentView.DocumentListener() {
    @Override
    public void onDocCompleted() {

    }
}

Password required

Called when a password is required by the document.

Kotlin
mDocumentView.setDocumentListener(object : DocumentView.DocumentListener {
    override fun onPasswordRequired() {

    }
}
Java
mDocumentView.setDocumentListener(new DocumentView.DocumentListener() {
    @Override
    public void onPasswordRequired() {

    }
}

NOTE
To submit a password an application should call mDocumentView.providePassword(<String>).

Page change

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

Kotlin
mDocumentView.setPageChangeListener { pageNumber ->

}
Java
mDocumentView.setPageChangeListener(new DocumentView.ChangePageListener() {
    @Override
    public void onPage(int pageNumber) {

    }
})

Full screen mode

A DocumentView document has the ability to fill the screen and enter a uneditable mode for an optimal reading experience. It is the application developer's responsibility to turn off the UI that they do not wish to see when this mode is invoked and to ensure that their DocumentView instance fills the device screen. To turn desired UI back on again the DocumentView instance will invoke the application developer's closure method upon exiting full screen mode ( when the user taps the screen ).

Kotlin
findViewById<View>(R.id.button_full_screen).setOnClickListener {
    // hide this activity's UI
    findViewById<View>(R.id.custom_ui_layout).visibility = View.GONE

    // put DocumentView in full screen mode
    if (mDocumentView != null) {
        mDocumentView.enterFullScreen {
            // closure method to restore our UI upon exit
            findViewById<View>(R.id.ui_layout).visibility = View.VISIBLE
        }
    }
}
Java
findViewById(R.id.button_full_screen).setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        // hide this activity's UI
        findViewById(R.id.custom_ui_layout).setVisibility(View.GONE);

        // put DocumentView in full screen mode
        if (mDocumentView != null) {
            mDocumentView.enterFullScreen(new Runnable() {
                @Override
                public void run() {
                    // closure method to restore our UI upon exit
                    findViewById(R.id.ui_layout).setVisibility(View.VISIBLE);
                }
            });
        }
    }
});

Done

Called when the document is closed.

Kotlin
mDocumentView.setDocumentListener(object : DocumentView.DocumentListener {
    override fun onDone() {

    }
}
Java
mDocumentView.setDocumentListener(new DocumentView.DocumentListener() {
    @Override
    public void onDone() {

    }
}