Customize the document viewer

Document viewers can be configured to suit your needs with ease.

Customize document viewer in Xamarin.Android

This tutorial only applies to Xamarin.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:

C#

1// Customize settings in ViewerConfig
2var config = new ViewerConfig.Builder()
3 .FullscreenModeEnabled(true)
4 .MultiTabEnabled(true)
5 .DocumentEditingEnabled(true)
6 .LongPressQuickMenuEnabled(true)
7 .ShowPageNumberIndicator(true)
8 .ShowBottomNavBar(true)
9 .ShowThumbnailView(true)
10 .ShowBookmarksView(true)
11 .ToolbarTitle("My Reader")
12 .ShowSearchView(true)
13 .ShowShareOption(true)
14 .ShowDocumentSettingsOption(true)
15 .ShowAnnotationToolbarOption(true)
16 .ShowOpenFileOption(true)
17 .ShowOpenUrlOption(true)
18 .ShowEditPagesOption(true)
19 .ShowPrintOption(true)
20 .ShowCloseTabOption(true)
21 .ShowAnnotationsList(true)
22 .ShowOutlineList(true)
23 .ShowUserBookmarksList(true)
24 .Build();
25
26// Initialize your document viewer with a
27// a ViewerConfig when you open a document
28DocumentActivity.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:

C#

1// Customize settings in PDFViewCtrlConfig
2var pdfViewCtrlConfig = PDFViewCtrlConfig.GetDefaultConfig(this)
3 .SetClientBackgroundColor(Android.Graphics.Color.Yellow)
4 .SetClientBackgroundColorDark(Android.Graphics.Color.Blue)
5 .SetHighlightFields(true)
6 .SetImageSmoothing(true)
7 .SetUrlExtraction(true)
8 .SetMaintainZoomEnabled(true);
9
10// Pass the PDFViewCtrlConfig into your ViewerConfig
11// so that it can be used to initialize PDFViewCtrl
12// in your document viewer
13var builder = new ViewerConfig.Builder();
14var config = builder
15 .PdfViewCtrlConfig(pdfViewCtrlConfig)
16 // ...
17 .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:A full list of settings for ToolManagerBuilder can be found in the API documentation.

C#

1// Customize settings in ToolManagerBuilder
2var toolManagerBuilder = ToolManagerBuilder.From()
3 .SetEditFreeTextOnTap(false)
4 .SetDisableQuickMenu(true);
5
6// Pass the ToolManagerBuilder into your ViewerConfig
7// so that it can be used to initialize ToolManager
8// in your document viewer
9var builder = new ViewerConfig.Builder();
10var config = builder
11 .ToolManagerBuilder(toolManagerBuilder)
12 // ...
13 .Build();

C#

1// Pass the XML style resource R.style.MyToolManager to ViewerConfig
2var builder = new ViewerConfig.Builder();
3var config = builder
4 .ToolManagerBuilderStyleRes(Resource.Style.MyToolManager)
5 // ...
6 .Build();

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales