You have a few options to open a document such as with an activity, fragment, or view. A diagram of the overall view hierarchy can be found here: View hierarchy.
Apryse's Android SDK ships with DocumentActivity
, an all-in-one document reader and PDF editor. In addition to PDF files, it also supports viewing other file formats such as .docx
, .doc
, .pptx
, .xlsx
, .md
, .cbz
and various image formats. In this activity you can also read, annotate, sign, fill in PDF forms and more.
DocumentActivity
extends Android's AppCompatActivity
and follows Material design guidelines.
PDFTron.Android.Tools
NuGet package into your project.The trial of Apryse SDK requires a trial license key, which is provided in the box titled "License Key". A commercial license key is required for use in a production environment. Please contact sales to purchase a commercial key or if you need any other license key assistance.
License keys are uniquely generated. Please make sure that it is not publicly available (e.g. in your public GitHub).
DocumentActivity
, we will need to add the Android permissions listed in this table. However if you would like to disable certain features and customize your document viewer, you should leave out unnecessary permissions.Please note that from Android 6.0 (API 23) and up, applications need to request storage permission at runtime before accessing any files on device.
largeHeap
:AndroidManifest.xml
file, and also declare DocumentActivity
in the manifest file. The final AndroidManifest.xml
file should look something like this:Launch DocumentActivity
by specifiying a local file path, an HTTP/HTTPS url, or a Content Uri:
PDFTronAppTheme
in res/values/styles.xml
:You can learn more about this in the customize the viewer's theme guide .DocumentActivity
uses the AppCompat
theme for material colors. Make sure that the value of android:theme
in your activity
tag also extends the AppCompat
theme.
DocumentActivity
, you can use ViewerConfig.Builder
. For example:For details on customizing the UI and using ViewerConfig.Builder
, check out the configuration tutorial .All actions related to the PDF viewer are handled through the PdfViewCtrlTabHostFragment2
. This fragment extends androidx.fragment.app.Fragment
and is responsible for showing documents in tabs.
PDFTron.Android.Tools
NuGet package into your project.The trial of Apryse SDK requires a trial license key, which is provided in the box titled "License Key". A commercial license key is required for use in a production environment. Please contact sales to purchase a commercial key or if you need any other license key assistance.
License keys are uniquely generated. Please make sure that it is not publicly available (e.g. in your public GitHub).
PdfViewCtrlTabHostFragment2
, we will need to add the Android permissions listed in this table. However if you would like to disable certain features and customize your document viewer, you should leave out unnecessary permissions.Please note that from Android 6.0 (API 23) and up, applications need to request storage permission at runtime before accessing any files on device.
largeHeap
and usesClearTextTraffic
:AppCompatActivity
and use an AppCompat theme:AndroidManifest.xml
file. The final AndroidManifest.xml
file should look something like this:Use ViewerBuilder2
to create an instance of PdfViewCtrlTabHostFragment2
, and add it to your activity layout. To add a document viewer fragment for a given password-protected file, call the following method in your activity:
where fragmentContainer
is the resource id of a layout in your activity that will contain your fragment:
For example:
Alternatively if you have extended PdfViewCtrlTabFragment2
or PdfViewCtrlTabHostFragment2
, you can specify your custom classes using the ViewerBuilder2.usingTabClass()
method and the ViewerBuilder2.build()
method as follows:
Since Apryse uses the Fragment class from the Support Library, your activity must extend AppCompatActivity
and call getSupportFragmentManager()
to get the FragmentManager
.
PDFTronAppTheme
in styles.xml
:You can learn more about this in the customize the viewer's theme guide .PdfViewCtrlTabHostFragment2
uses the AppCompat
theme for material colors. Make sure that the value of android:theme
in your activity
tag also extends the AppCompat
theme.
PdfViewCtrlTabHostFragment2
, you can use ViewerConfig.Builder
. For example:For details on customizing the UI and using ViewerConfig.Builder
, check out the configuration tutorial .
The default toolbar menu consists of the following buttons on phones:
The default toolbar menu consists of the following buttons on tablets:
You can fully customize the toolbar menu and the navigation icon by calling the following in ViewerBuilder2
, with custom menu resource and drawable resource files:
To change the icon color and overflow icon color, in styles.xml
:
To change the navigation icon color, in styles.xml
(assume MyTheme
is used as the app theme):
If you would like 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 uses a custom toolbar:
where ic_arrow_back_white_24dp.xml
is a drawable resource file for a back arrow icon, and my_custom_toolbar.xml
is a menu resource file that contains:
This sample replaces the navigation icon, removes all toolbar buttons except the annotation toolbar button, and adds a new Show Toast
button:
If you are looking for a quick start on displaying documents in your application, please first take a look at Show a document in an Activity or Show a document in 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 to embed PDFViewCtrl
in your own layout.
PDFViewCtrl
is a ViewGroup
that can be embedded in any layout. It encapsulates a rich set of functionalities for interactive viewing of PDF documents, including multi-threaded rendering, PDF rendering settings, scrolling, zooming, page navigation, different page viewing modes, coordinates conversion, text selection, text search, etc.
In this tutorial you will display a PDF file in your activity by using PDFViewCtrl
.
AndroidManifest.xml
, make sure you enable largeHeap
in the <application>
tag. Also, add a custom theme and set the android:windowSoftInputMode:"adjustPan"
attribute in the <activity>
tag as follow:PDFTronAppTheme
for your activity in res/values/styles.xml
:You can learn more about this in the customize the viewer's theme guide.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.
PDFViewCtrl
to your activity's XML layout. For example:PDFViewCtrl
after inflating the layout and call AppUtils.SetupPDFViewCtrl
.src/main/res/raw
folder, then call:Please follow the latest Android best practices and guidelines outlined here
It is extremely important that you follow the Android activity/fragment lifecycle and clean up PDFViewCtrl
and PDFDoc
properly. Make sure you have the following in lifecycle callbacks:
PDFViewCtrl
? Check out the Setup ToolManager guide.PDFViewCtrl
? Check out the viewing other document types guide.Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales