Guides
Quick Start
After completing integration, you can launch a complete PDF document interface via CPDFDocumentActivity or CPDFDocumentFragment. UI and feature behavior are controlled through CPDFConfiguration, with the default configuration file being tools_default_configuration.json.
Storage Access Notes (Android 10/11+)
- It is recommended to use
Uri(SAF / MediaStore) to open and save documents.- Using file paths directly may be restricted by Scoped Storage on newer systems.
tools_default_configuration.jsonis packaged in the Tools moduleassetsby default and can be used directly or copied to your app'sassetsdirectory to override.
Using CPDFDocumentActivity
CPDFDocumentActivity is a ready-to-use full-screen PDF document Activity.
Open via Uri
java
Intent intent = new Intent(context, CPDFDocumentActivity.class);
intent.setData(uri); // Uri returned from SAF picker
intent.putExtra(CPDFDocumentActivity.EXTRA_FILE_PASSWORD, password); // Can be null
CPDFConfiguration configuration = CPDFConfigurationUtils.normalConfig(
context, "tools_default_configuration.json");
intent.putExtra(CPDFDocumentActivity.EXTRA_CONFIGURATION, configuration);
intent.putExtra(CPDFDocumentActivity.EXTRA_PAGE_INDEX, 0); // Default page index
context.startActivity(intent);kotlin
val intent = Intent(context, CPDFDocumentActivity::class.java).apply {
data = uri
putExtra(CPDFDocumentActivity.EXTRA_FILE_PASSWORD, password)
val configuration = CPDFConfigurationUtils.normalConfig(
context, "tools_default_configuration.json")
putExtra(CPDFDocumentActivity.EXTRA_CONFIGURATION, configuration)
putExtra(CPDFDocumentActivity.EXTRA_PAGE_INDEX, 0)
}
context.startActivity(intent)Open via File Path
java
Intent intent = new Intent(context, CPDFDocumentActivity.class);
intent.putExtra(CPDFDocumentActivity.EXTRA_FILE_PATH, filePath);
intent.putExtra(CPDFDocumentActivity.EXTRA_FILE_PASSWORD, password);
CPDFConfiguration configuration = CPDFConfigurationUtils.normalConfig(
context, "tools_default_configuration.json");
intent.putExtra(CPDFDocumentActivity.EXTRA_CONFIGURATION, configuration);
intent.putExtra(CPDFDocumentActivity.EXTRA_PAGE_INDEX, 0);
context.startActivity(intent);kotlin
val intent = Intent(context, CPDFDocumentActivity::class.java).apply {
putExtra(CPDFDocumentActivity.EXTRA_FILE_PATH, filePath)
putExtra(CPDFDocumentActivity.EXTRA_FILE_PASSWORD, password)
val configuration = CPDFConfigurationUtils.normalConfig(
context, "tools_default_configuration.json")
putExtra(CPDFDocumentActivity.EXTRA_CONFIGURATION, configuration)
putExtra(CPDFDocumentActivity.EXTRA_PAGE_INDEX, 0)
}
context.startActivity(intent)Supported Intent Parameters
| Extra Constant | Type | Description |
|---|---|---|
EXTRA_FILE_PATH | String | Absolute path to the PDF file |
EXTRA_FILE_URI | Uri (via setData()) | SAF / MediaStore Uri |
EXTRA_FILE_PASSWORD | String | Document password, can be null |
EXTRA_CONFIGURATION | CPDFConfiguration | UI and feature configuration object |
EXTRA_PAGE_INDEX | int | Default page index to display on open (0-based) |
Using CPDFDocumentFragment
CPDFDocumentFragment can be embedded in any Activity for more flexible interface customization.
Basic Usage
java
CPDFConfiguration configuration = CPDFConfigurationUtils.normalConfig(
context, "tools_default_configuration.json");
CPDFDocumentFragment documentFragment = CPDFDocumentFragment.newInstance(
uri, "password", configuration);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container_view, documentFragment, "documentFragment")
.commit();kotlin
val configuration = CPDFConfigurationUtils.normalConfig(
context, "tools_default_configuration.json")
val documentFragment = CPDFDocumentFragment.newInstance(
uri, "password", configuration)
supportFragmentManager
.beginTransaction()
.replace(R.id.fragment_container_view, documentFragment, "documentFragment")
.commit()Factory Methods
CPDFDocumentFragment provides the following static methods for creating instances:
| Method | Description |
|---|---|
newInstance(String filePath, String password, CPDFConfiguration config) | Create via file path |
newInstance(Uri uri, String password, CPDFConfiguration config) | Create via Uri |
newInstance(Bundle bundle) | Create via Bundle (advanced usage) |
Initialization Callback
Use setInitListener() to listen for the Fragment initialization completion event and obtain the CPDFViewCtrl instance:
java
documentFragment.setInitListener(pdfView -> {
// pdfView is ready, perform further operations
// e.g.: pdfView.getCPdfReaderView().setDisplayMode(...)
});kotlin
documentFragment.setInitListener { pdfView ->
// pdfView is ready
}Result
