Some test text!


Quick start: viewing a document in Xamarin.Android

This tutorial only applies to Xamarin.Android.

Supporting Sdk versions:

  • Minimum: API 16 (Using Android Support Libraries)
  • Recommended target: API 29

This guide demonstrates how to display a PDF. To begin working with PDFTron SDK, you must have first added it to your project, and initialized the library.

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

    <activity android:name="com.pdftron.pdf.controls.DocumentActivity"
If your app is targeting Android SDK version 28 or higher, you will need to add the android:usesCleartextTraffic="true" attribute in your application tag.

Next, add permissions to AndroidManifest.xml file in the <manifest> tag (outside the <application> tag):

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
android.permission.WRITE_EXTERNAL_STORAGEStorage permission for accessing local documents
android.permission.INTERNETInternet permission for downloading online documents
android.permission.RECORD_AUDIOAudio recording permission for creating sound annotations

Add license key and activity declarations to AndroidManifest.xml file inside the <application> tag:

<!-- Add license key in meta-data tag here. This should be inside the application tag. -->
<activity android:name="com.pdftron.pdf.controls.DocumentActivity"

Finally, if you would like to customize the appearance of the viewer activity, define PDFTronAppTheme in Resources/values/styles.xml:

    <style name="PDFTronAppTheme" parent="PDFTronAppThemeBase">
        <item name="colorPrimary">@color/app_color_primary_day</item>
        <item name="colorPrimaryDark">@color/app_color_primary_dark_day</item>
        <item name="colorAccent">@color/app_color_accent</item>
        <!-- Drawer -->
        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
        <!-- Action bar -->
        <item name="actionModeBackground">?attr/colorPrimary</item>
        <item name="windowActionModeOverlay">true</item>
If you are using your own theme, please don't forget to add/change the theme tag of your AndroidManifest file's corresponding activity declaration.

To open a PDF file:

// Open our sample document in the 'Resources/raw' resource folder

You will see:

SimpleReader image

Please note that changes for files opened from res will not be saved on disk.

To open your own file in DocumentActivity, use:

// from internal storage
var localFile = Android.Net.Uri.FromFile(new Java.IO.File("myLocalFilePath"));
pdftron.PDF.Controls.DocumentActivity.OpenDocument(this, localFile);

// from content uri
var contentUri = Android.Net.Uri.Parse("myContentUri");
pdftron.PDF.Controls.DocumentActivity.OpenDocument(this, contentUri);

// from http/https
var fileLink = Android.Net.Uri.Parse("myFileLink");
pdftron.PDF.Controls.DocumentActivity.OpenDocument(this, fileLink);

// from res
pdftron.PDF.Controls.DocumentActivity.OpenDocument(this, Resource.Raw.my_file_res_id);

Get the answers you need: Support


Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.