Some test text!

keyboard_arrow_down

Get started

Download PDFTron SDKIntegrate with NuGetIntegrate manuallyRun samplesAdd license keyQuick start - view a documentUpdate to latest version
keyboard_arrow_down

Xamarin.Forms

Basic viewer
keyboard_arrow_down

Fundamentals

Java binding (Android)Objective-C binding (iOS)Code sharing
keyboard_arrow_down

Document Viewer (Android)

OverviewShow a document in an ActivityShow a document in a FragmentViewer configurationDay and Night themesOpen from online URL
keyboard_arrow_down

Document Viewer (iOS)

Show a document in a ViewControllerShow documents in a tabbed ViewController
keyboard_arrow_down

Document Viewer components

PDFViewCtrl (Android)PDFViewCtrl (iOS)ReflowAnnotation toolbarAnnotation style editorPage sliderAnnotation listDocument outlineUser bookmark listList containerThumbnail browserAdd pages dialogRotate pages dialogView mode dialogCrop pages dialog
keyboard_arrow_down

Annotation and collaboration

ToolManager setupDisable annotation creation/editingOverride annotation handling
keyboard_arrow_down

Advanced customization

Add a custom view to a pageCreate a custom toolPage coloring modePage fit modePage layout modeRealtime collaboration
keyboard_arrow_down

Conversion

Convert documents to PDFConvert HTML to PDF
keyboard_arrow_down

Search

Inline text search
keyboard_arrow_down

Advanced topics

Document savingDocument locking
keyboard_arrow_down

FAQ

System RequirementsPDFTron full vs. standardBuild split APKsLocalizationIcon cheat sheet
keyboard_arrow_down

PDF Processing API

What is PDFNet?Opening a documentSerializing (saving) a documentWorking with pagesWorking with Page ContentWorking with BookmarksWorking with Interactive Forms (AcroForms)PDF SecurityLow-level PDF APIError handling
Show a document in a Fragmentkeyboard_arrow_down

Show a document in a Fragment

In this document
chevron_rightToolbar menu
chevron_rightCustomize toolbar menu
chevron_rightCustomize navigation icon
chevron_rightInteract with fragment
This article only applies to Xamarin.Android.
PdfViewCtrlTabHostFragment requires the full version of PDFTron library. See PDFTron full or standard?

All actions related to the PDF viewer are handled through the PdfViewCtrlTabHostFragment fragment. This fragment extends android.support.v4.app.Fragment and is responsible for showing document in tabs.

Please note that PdfViewCtrlTabHostFragment requires the com.pdftron:tools package.

First declare your Activity to extend AppCompatActivity and use AppCompat theme:

[Activity(Label = "MyReaderActivity",
    ConfigurationChanges = Android.Content.PM.ConfigChanges.ScreenSize | Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.KeyboardHidden,
    Theme = "@style/CustomAppTheme", 
    WindowSoftInputMode = SoftInput.AdjustPan)]
public class MyReaderActivity : Android.Support.V7.App.AppCompatActivity
{
  ...
}
PdfViewCtrlTabHostFragment uses the AppCompat theme for material colors. Make sure that the value of android:theme in your activity tag also extends the AppCompat theme.

Displaying the PdfViewCtrlTabHostFragment in an activity is straightforward. Like any other fragment you should make an instance of the class and attach it to the activity. To create an instance of the host fragment you need to pass in a bundle that can be created using createBasicPdfViewCtrlTabBundle. The bundle specifies the document that should be shown when the host fragment is visible. For example, to open a document in the host fragment when you know the URI of the file (and its password if the file is password protected) you can call:




You can simply convert a file to a URI by:




Note that since we use the support version of android fragment, your activity must extend FragmentActivity and call getSupportFragmentManager() to get the FragmentManager.

If you would like to customize the UI of PdfViewCtrlTabHostFragment, you can use ViewerConfig.Builder builder. For example:





For details on customizing the UI interface and sample usage of ViewerConfig builder, check out the configuration tutorial.

linkToolbar menu

The default toolbar menu consists of menu items for

  • searching text in the current document
  • sharing the current document
  • setting up viewing mode
  • showing/hiding annotation toolbar
  • overflow menu

However, you can fully customize and control the toolbar menu as well as the navigation icon.

linkCustomize toolbar menu

In order to change the default toolbar menu items you need to create your own menu in menu resource folder and pass it to the host fragment through bundle:




linkCustomize navigation icon

To change the navigation icon, similar to the toolbar menu, you need to pass the desired icon to the host fragment through the bundle:




linkInteract with fragment

If you want to interact with the host fragment you can override the methods that you are interested in through events. For example, you may want to override ToolbarOptionsItemSelected when you add a new menu item, so when the item is clicked you can get a callback. As another example, you can get the callback when the navigation icon is clicked if you override NavButtonPressed.

Here's an example that replaces the default navigation icon, and only keeps the annotation toolbar icon in the toolbar menu while adding a new menu item to show a toast when selected:




The fragment_viewer_simple.xml should be placed in menu resource folder and contain:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_annotation_toolbar"
        android:icon="@drawable/ic_mode_edit_white"
        android:title="@string/action_annotation_toolbar"
        app:showAsAction="ifRoom"/>
    <item
        android:id="@+id/action_show_toast"
        android:title="Show toast"
        app:showAsAction="never" />
</menu>

With this complete, you will see: