Some test text!

Loading...
Guides
Integrate

Integrate Android PDF Library using Flutter

See here for the get started guide for using the PDFTron Flutter SDK on iOS.

This guide will help you integrate a free trial of the PDFTron SDK into your Android applications using Flutter. Your free trial includes unlimited trial usage and support from solution engineers.

Get the Flutter source code

Prerequisites

  • PDFTron SDK >= 6.9.0
  • Flutter >= 1.0.0
No trial license key required.
The trial of PDFTron SDK works without a license key. A commercial license key is required for use in a production environment. Please fill out our licensing form if you do not have a valid license key.
Keep your commercial license key confidential.
License keys are uniquely generated. Please make sure that it is not publicly available (e.g. in your public GitHub).

Integrate

For simplicity the following guide is based on a boilerplate flutter app of flutter create myapp with git diff syntax for adding and removing lines from the boilerplate app.

  1. First follow the Flutter get started guides to install, set up an editor, and create a Flutter Project. The rest of this guide assumes your project is created by running flutter create myapp.

  2. Add the following dependency to your Flutter project in myapp/pubspec.yaml:

    dependencies:
       flutter:
         sdk: flutter
    +  pdftron_flutter:
    +   git:
    +	  url: git://github.com/PDFTron/pdftron-flutter.git
  3. Now add the following items in your myapp/android/app/build.gradle file:

    android {
    -   compileSdkVersion 27
    +   compileSdkVersion 30
    
        lintOptions {
            disable 'InvalidPackage'
        }
    
        defaultConfig {
            applicationId "com.example.myapp"
    -       minSdkVersion 16
    +       minSdkVersion 21
    -       targetSdkVersion 27
    +       targetSdkVersion 30
    +       multiDexEnabled true
    +       manifestPlaceholders = [pdftronLicenseKey:PDFTRON_LICENSE_KEY]
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
    	...
    }
  4. In your myapp/android/app/src/main/AndroidManifest.xml file, add the following lines to the <application> tag:

    <!-- Enable usesCleartextTraffic in application attributes if you are 
    working with HTTP files. If you are only working with HTTPS files, this is not required.-->
    <application
    	android:name="io.flutter.app.FlutterApplication"
    	android:label="myapp"
    	android:icon="@mipmap/ic_launcher"
    +	android:largeHeap="true"
    +	android:usesCleartextTraffic="true">

    Additionally, add the required permissions for your app in the <manifest> tag:

    <uses-permission android:name="android.permission.INTERNET" />
      <!-- Required to read and write documents from device storage -->
    +   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
      <!-- Required if you want to record audio annotations -->
    +   <uses-permission android:name="android.permission.RECORD_AUDIO" />
  5. Add your PDFTron license key to the myapp/android/gradle.properties file.

    PDFTRON_LICENSE_KEY=INSERT_COMMERCIAL_LICENSE_KEY_HERE_AFTER_PURCHASE

    Key can be left empty for a trial

  6. If you are using the DocumentView widget, change the parent class of your MainActivity file (either Kotlin or Java) to FlutterFragmentActivity.

    import androidx.annotation.NonNull
    	import io.flutter.embedding.android.FlutterFragmentActivity
    	import io.flutter.embedding.engine.FlutterEngine
    	import io.flutter.plugins.GeneratedPluginRegistrant
    
    	class MainActivity : FlutterFragmentActivity() {
    		override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
    			GeneratedPluginRegistrant.registerWith(flutterEngine);
    		}
    	}

Next step

View a document

Get the answers you need: Support