Some test text!

Search
Hamburger Icon

Android / Guides / Configuration

Customize the document viewer in Android

DocumentActivity and PdfViewCtrlTabHostFragment2 are highly configurable and can be easily customized using our document viewer configuration classes. UI components can be hidden and functionality can be disabled by initializing the document viewer using ViewerConfig.Builder.

For further customization, PDFViewCtrlConfig allows you to initialize PDFViewCtrl with low-level viewer settings, and ToolManagerBuilder allows you to customize annotation functionality in ToolManager.

Configure Document Viewer

DocumentActivity and PdfViewCtrlTabHostFragment2 can be initialized using ViewerConfig, which can be created with a ViewerConfig.Builder object.

For example:

// Customize settings in ViewerConfig
ViewerConfig config = new ViewerConfig.Builder()
    .fullscreenModeEnabled(true)
    .multiTabEnabled(true)
    .documentEditingEnabled(true)
    .longPressQuickMenuEnabled(true)
    .showPageNumberIndicator(true)
    .showBottomNavBar(true)
    .showThumbnailView(true)
    .showBookmarksView(true)
    .toolbarTitle("My Reader")
    .showSearchView(true)
    .showShareOption(true)
    .showDocumentSettingsOption(true)
    .showAnnotationToolbarOption(true)
    .showOpenFileOption(true)
    .showOpenUrlOption(true)
    .showEditPagesOption(true)
    .showPrintOption(true)
    .showCloseTabOption(true)
    .showAnnotationsList(true)
    .showOutlineList(true)
    .showUserBookmarksList(true)
    .build();

// Initialize your document viewer with a 
// a ViewerConfig when you open a document
DocumentActivity.openDocument(context, localFilePath, config);

A full list of settings for ViewerConfig.Builder can be found in the API documentation.

Configure PDFViewCtrl

PDFViewCtrl specific functionality can be configured using PDFViewCtrlConfig. You can then pass the configuration to ViewerConfig to initialize PDFViewCtrl in your document viewer with your specific settings.

For example:

// Customize settings in PDFViewCtrlConfig
PDFViewCtrlConfig pdfViewCtrlConfig = PDFViewCtrlConfig.getDefaultConfig(this)
    .setClientBackgroundColor(Color.YELLOW)
    .setClientBackgroundColorDark(Color.BLUE)
    .setHighlightFields(true)
    .setImageSmoothing(true)
    .setUrlExtraction(true)
    .setMaintainZoomEnabled(true);

// Pass the PDFViewCtrlConfig into your ViewerConfig
// so that it can be used to initialize PDFViewCtrl 
// in your document viewer
ViewerConfig.Builder builder = new ViewerConfig.Builder();
ViewerConfig config = builder
    .pdfViewCtrlConfig(pdfViewCtrlConfig)
    // ...
    .build();

A full list of settings for PDFViewCtrlConfig can be found in the API documentation.

Configure ToolManager

Annotation tool functionality can be configured using ToolManagerBuilder, such as hiding/disabling specific annotation creation tools or disabling the quick menu. You can then pass the configuration to ViewerConfig to initialize ToolManager in your document viewer with your specific settings. Alternatively, you can also modify the style resource for ToolManager directly, and pass it to ViewerConfig.

  • Configure ToolManager by setting ToolManagerBuilder to an instance of ViewerConfig:

    // Customize settings in ToolManagerBuilder
    ToolManagerBuilder toolManagerBuilder = ToolManagerBuilder.from()
        .setEditFreeTextOnTap(false)
        .setDisableQuickMenu(true);
    
    // Pass the ToolManagerBuilder into your ViewerConfig
    // so that it can be used to initialize ToolManager
    // in your document viewer
    ViewerConfig.Builder builder = new ViewerConfig.Builder();
    ViewerConfig config = builder
        .toolManagerBuilder(toolManagerBuilder)
        // ...
        .build();

    A full list of settings for ToolManagerBuilder can be found in the API documentation.

  • Configure ToolManager by setting an XML style resource:

    ViewerConfig.Builder builder = new ViewerConfig.Builder();
    // Pass the XML style resource R.style.MyToolManager to ViewerConfig
    ViewerConfig config = builder
        .toolManagerBuilderStyleRes(R.style.MyToolManager)
        // ...
        .build();

    Defining a style for ToolManager is explained in detail in the ToolManager configuration guide .

Get the answers you need: Chat with us