Some test text!

keyboard_arrow_down

Get started

Download PDFTron SDKIntegrate with GradleIntegrate manuallyRun samplesAdd license keyQuick start - view a documentProGuardUpdate to latest versionTroubleshooting
keyboard_arrow_down

Document Viewer

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

Document Viewer components

PDFViewCtrlReflowFloating context menuCustomize floating context menuAnnotation toolbarAnnotation style editorCustomize annotation style editorPage sliderAnnotation listDocument outlineUser bookmark listList containerThumbnail browserAdd pages dialogRotate pages dialogView mode dialogCrop pages dialog
keyboard_arrow_down

Annotation and collaboration

Read only modeDisable annotation creation/editingDefault annotation propertiesAnnotation propertiesEventsOverride annotation handlingShow and hide existing annotationsUndo and redoRealtime collaboration
keyboard_arrow_down

Advanced customization

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

Conversion

Convert documents to PDFConvert HTML to PDF
keyboard_arrow_down

Search

Text search
keyboard_arrow_down

Other Frameworks

XamarinReact Native
keyboard_arrow_down

Advanced topics

Understand coordinatesDocument savingDocument lockingGenerate page thumbnailsTool class hierarchy
keyboard_arrow_down

FAQ

System RequirementsRun project in Android StudioRun project with source codePDFTron full vs. standardLocalizationIcon cheat sheetReduce size of APKEnable multidexOut of memory when rotating device multiple timesReduce memory consumptionDetachCurrentThread warning
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
PDFViewCtrlkeyboard_arrow_down

PDFViewCtrl

In this document
chevron_rightOption 1: from resource
chevron_rightOption 2: from local device storage
chevron_rightOption 3: from content uri
chevron_rightOption 4: from HTTP/HTTPS
chevron_rightManaging lifecycle
If you are looking for a quick start on displaying documents in your application, please first take a look at Using an Activity or Using a Fragment as they are easier to setup and ready to launch from any Activity or Fragment. Continue reading this article if you are looking for embedding PDFViewCtrl in your own layout.

PDFViewCtrl extends Android's ViewGroup and can be embedded in any layout. It is the core functionality for displaying documents.

In this tutorial you will be able to display a PDF file in PDFViewCtrl.

Before beginning, make sure the PDFTron library is initialized prior to inflating the layout or calling setContentView of your Activity.

First, make sure the following is in your <application> tag in AndroidManifest.xml.

<application
    android:largeHeap="true"
    ...>
    
    <activity
        android:windowSoftInputMode="adjustPan"
        android:theme="@style/CustomAppTheme"
        .../>
</application>

Then, add a theme to res/values/styles.xml:

<resources>
  <style name="CustomAppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
    <item name="colorPrimary">#3F51B5</item>
    <item name="colorPrimaryDark">#303F9F</item>
    <item name="colorAccent">#FF4081</item>
    <!-- Action bar -->
    <item name="actionModeBackground">?attr/colorPrimary</item>
    <item name="windowActionModeOverlay">true</item>
  </style>
</resources>
PDFViewCtrl uses the AppCompat theme for material colors. Make sure that the value of android:theme in your activity tag also extends the AppCompat theme.

Now, add PDFViewCtrl to your XML layout.

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.myapplication.MainActivity">

    <com.pdftron.pdf.PDFViewCtrl
        android:id="@+id/pdfviewctrl"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical|horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

Please note that you need to change com.myapplication.MainActivity to your own Activity path.

Then, get a reference to PDFViewCtrl in code after inflating the layout.



Next, choose a document to display:

linkOption 1: from resource

Add a sample PDF to src/main/res/raw folder.



linkOption 2: from local device storage

To access device storage, add the following permissions to AndroidManifest.xml file outside of the <application> tag:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Then:



linkOption 3: from content uri



linkOption 4: from HTTP/HTTPS

To access via the internet, add the following permissions to AndroidManifest.xml file outside of the <application> tag:

<uses-permission android:name="android.permission.INTERNET"/>

Then:



linkManaging lifecycle

It is extremely important that you follow Android Activity/Fragment lifecycle and cleanup properly. Make sure you have the following:



Want to annotate on PDF files in PDFViewCtrl? Check out the Setup ToolManager guide.
Want to display non-PDF files in PDFViewCtrl? Check out the viewing other document types guide.