Android
ComPDFKit PDF SDK
Get Started

How to Integrate ComPDFKit PDF SDK Using UI Extensions Component

 

ComPDFKit PDF SDK for Android provides the source code of the UI Extensions Component that contains ready-to-use UI module implementations, which lets the developers have full control of styling the appearance as desired.

- Copy "ComPDFKit.aar", "ComPDFKit-UI.aar" and "ComPDFKit-Utils.aar" to the "libs" directory of the app.

 

Find build.gradle in the "ComPDFKit_Demo" module, and add the following configuration into build.gradle file:

 

android{
repositories {
       flatDir {
       /* Folder path where aar is located */
           dirs '../AAR Directory folder/libs'  
      }
}
compileOptions {
       sourceCompatibility JavaVersion.VERSION_1_8
       targetCompatibility JavaVersion.VERSION_1_8
  }
...
}
dependencies {
...
/*ComPDFKit_demo_utils*/
implementation(name: 'ComPDFKit-Utils', ext: 'aar')
 /*ComPDFKit SDK*/
implementation(name: 'ComPDFKit' ext: 'aar')
implementation(name: 'ComPDFKit-UI', ext: 'aar')
}

 

- Create an activity or fragment to implement ReaderActivity or ReaderFragment.

 

public class PDFReaderActivity extends ReaderActivity {
 //Do something...
}
​
public class PDFReaderFragment extends ReaderFragment {
 //Do something...
}

 

- Configure Document Viewer. ReaderActivity and ReaderFragment can be initialized using ViewerConfig, which can be created with a ViewerConfig.Builder object.

 

// Customize settings in ViewerConfig
static ViewerConfig getDefaultViewerConfig() {
   ViewerConfig.Builder builder = new ViewerConfig.Builder();
   builder.showSDKIndicator(true)
          .fullscreenModeEnabled(true)
          .showAddBookmarkOption(true)
          .showAnnotationToolbarOption(true)
          .showCleanSignatureOption(true)
          .showDeleteAllAnnotOption(true)
          .showDocumentInfoOption(true)
          .showEditPagesOption(true)
          .showFormEditor(true)
          .showHighlightLinkOption(true)
          .showImportAndExportAnnotOption(true)
          .showMoreSettingsOption(true)
          .showPageNumberIndicator(true)
          .showPageShareOption(true)
          .showPageTurningToolOption(true)
          .showPreviousPageIndicator(true)
          .showSearchToolView(true)
          .showThemeOption(true)
          .showTopToolBar(true)
          .showUserBookmarksListOption(true)
          .showWatermarkToolOption(true)
          .showCompress(true)
          .showRemoveAllFormAnnotationOption(true)
          .showGetAllAnnotationOption(true);
   return builder.build();
}

 

- Start customizable activity.

 

public static void open(Context context, String filePath, ViewerConfig viewerConfig) {
   try {
       Intent intent = new Intent(context, PDFReaderActivity.class);
       intent.putExtra(FILE_PATH, filePath);
       intent.putExtra(VIEWER_CONFIG, viewerConfig);
       intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
       context.startActivity(intent);
  } catch (Exception e) {
       e.printStackTrace();
  }
}
​
public static void open(Context context, Uri absolutePathUri, ViewerConfig viewerConfig) {
   try {
       Intent intent = new Intent(context, PDFReaderActivity.class);
       intent.putExtra(FILE_PATH_URI, absolutePathUri);
       intent.putExtra(VIEWER_CONFIG, viewerConfig);
       intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
       context.startActivity(intent);
  } catch (Exception e) {
       e.printStackTrace();
  }
}