Adding a PDFTron license key

In this document
chevron_rightOption 1
chevron_rightOption 2
chevron_rightOption 3
Warning
A demo license key or a commercial license key is required to proceed. If you have not yet received a license key, please obtain a license key here before continuing to read this documentation.

It is important that you initialize the PDFTron library with a valid license key before using any PDFTron classes. There are a few ways to include a license key in your application.

Option 1

Include the license key directly in your code. In your MainApplication.java or MainActivity.java file's onCreate method (before setContentView of your Activity), add:

If you are using a com.pdftron:demo dependency (i.e. using implementation "com.pdftron:demo:6.8.+" in your app/build.gradle file):

com.pdftron.demo.utils.AppUtils.initializePDFNetApplication(getApplicationContext(), "YOUR_PDFTRON_LICENSE_KEY_GOES_HERE");

Otherwise:

If you are only using a com.pdftron:tools dependency (i.e. using implementation "com.pdftron:tools:6.8.+" and not using implementation "com.pdftron:demo:6.8.+" in your app/build.gradle file):

com.pdftron.pdf.utils.AppUtils.initializePDFNetApplication(getApplicationContext(), "YOUR_PDFTRON_LICENSE_KEY_GOES_HERE");

Option 2

Define the license key in gradle.properties, where you can inject build variables into the manifest. First, add your PDFTron license key to your project's gradle.properties file:

PDFTRON_LICENSE_KEY=YOUR_PDFTRON_LICENSE_KEY_GOES_HERE

Then, in your module's Gradle file (usually app/build.gradle), add:

android {
    defaultConfig {
        ...
        manifestPlaceholders = [pdftronLicenseKey:PDFTRON_LICENSE_KEY]
    }
}

After that, add a placeholder for the license key to your AndroidManifest.xml file, inside the <application> tag:

<meta-data
    android:name="pdftron_license_key"
    android:value="${pdftronLicenseKey}"/>

Lastly, in your MainApplication.java or MainActivity.java file's onCreate method (before your Activity's setContentView), add one of the following depending on the dependency used by your project:

If you are using a com.pdftron:demo dependency (i.e. using implementation "com.pdftron:demo:6.8.+" in your app/build.gradle file):

com.pdftron.demo.utils.AppUtils.initializePDFNetApplication(getApplicationContext());

Otherwise:

If you are only using a com.pdftron:tools dependency (i.e. using implementation "com.pdftron:tools:6.8.+" and not using implementation "com.pdftron:demo:6.8.+" in your app/build.gradle file):

com.pdftron.pdf.utils.AppUtils.initializePDFNetApplication(getApplicationContext());

Option 3

Include the license key directly in your code, but in a way that offers greater flexibility than Options 1 and 2. In your MainApplication.java or MainActivity.java file's onCreate method (before your Activity's setContentView), add:

PDFNet.initialize(getApplicationContext(), R.raw.pdfnet, "YOUR_PDFTRON_LICENSE_KEY_GOES_HERE");

Please note that option 1 and 2 will set up various recommended presets for using PDFTron SDK. If you choose to go with option 3, you will have to setup the options manually (For more information see PDFTron class documentation).

You are set to go! Now, it is time to open a document in an Activity.