A convenience wrapper for building Flutter apps with PDFTron mobile SDK

PDFTron Flutter Wrapper


  • A valid evaluation or commercial license key. If you do not have a license key, please contact sales for a commercial license key or click here to get an evaluation key.
  • PDFTron gradle credentials that comes with your license key (Android)
  • PDFTron SDK >= 6.9.0
  • Flutter >= 1.0.0


Android iOS
demo demo


The complete installation and API guides can be found at https://www.pdftron.com/documentation/android/guides/flutter


  1. First follow the Flutter getting started guides to installset 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:
     sdk: flutter
+  pdftron_flutter:
+    git:
+      url: git://github.com/PDFTron/pdftron-flutter.git
+  permission: 0.1.0

3.Now add the following items in your myapp/android/app/build.gradle file:

android {
-   compileSdkVersion 27
+   compileSdkVersion 28

    lintOptions {
	disable 'InvalidPackage'

    defaultConfig {
	applicationId "com.example.myapp"
-       minSdkVersion 16
+       minSdkVersion 21
-       targetSdkVersion 27
+       targetSdkVersion 28
+       multiDexEnabled true
	versionCode flutterVersionCode.toInteger()
	versionName flutterVersionName
	testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

+   configurations.all {
+       resolutionStrategy.force "com.android.support:appcompat-v7:28.0.0"
+       resolutionStrategy.force "com.android.support:support-v4:28.0.0"
+       resolutionStrategy.force "android.arch.lifecycle:runtime:1.0.3"
+   }

4. In your myapp\android\app\src\main\AndroidManifest.xml file, add the following lines to the <application> tag:

+	android:largeHeap="true"
+	android:usesCleartextTraffic="true">

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

  1. 	...
    	<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 credentials in to the myapp/android/gradle.properties file.



6. Replace lib/main.dart with what is shown here

7. Check that your Android device is running by running the command flutter devices. If none are available, follow the device set up instructions in the Install guides for your platform.

8. Run the app with the command flutter run.


  1. First, follow the official getting started guide on installationsetting up an editor, and create a Flutter project, the following steps will assume your app is created through flutter create myapp
  2. Open myapp folder in a text editor. Then open myapp/pubspec.yaml file, add:
     sdk: flutter
+  pdftron_flutter:
+    git:
+      url: git://github.com/PDFTron/pdftron-flutter.git
+  permission: 0.1.0

3. Run flutter packages get
4. Open myapp/ios/Podfile, add:

 # Uncomment this line to define a global platform for your project
-# platform :ios, '9.0'
+platform :ios, '9.3'
 target 'Runner' do
+  # PDFTron Pods
+  use_frameworks!
+  pod 'PDFNet', podspec: 'POD_LINK_GOES_HERE'

5. Run flutter build ios –no-codesign to ensure integration process is sucessful

6. Replace lib/main.dart with what is shown here

7. Run flutter emulators –launch apple_ios_simulator

8. Run flutter run


Open lib/main.dart, replace the entire file with the following:

Replace your_pdftron_license_key string with your license key

import 'dart:async';
import 'dart:io' show Platform;

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:pdftron_flutter/pdftron_flutter.dart';
import 'package:permission/permission.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  _MyAppState createState() => _MyAppState();

class _MyAppState extends State<MyApp> {
  String _version = 'Unknown';
  String _document = "https://pdftron.s3.amazonaws.com/downloads/pdfref.pdf";

  void initState() {

    if (Platform.isIOS) {
      // Open the document for iOS, no need for permission
    } else {
      // Request for permissions for android before opening document

  Future<void> requestPermission() async {
    final res = await Permission.requestSinglePermission(PermissionName.Storage);
    if (granted(res)) {

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String version;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      version = await PdftronFlutter.version;
    } on PlatformException {
      version = 'Failed to get platform version.';

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _version = version;

  bool granted(PermissionStatus status) {
    return status == PermissionStatus.allow;

  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('PDFTron flutter app'),
        body: Center(
          child: Text('Running on: $_version\n'),



Obtain PDFTron SDK version


Initializes PDFTron SDK


Opens a document in the viewer

Source Github Url : https://github.com/PDFTron/pdftron-flutter

Next Article : https://flutterappdev.com/2019/04/17/a-calculator-app-developed-on-flutter-mobile-app-development/

Leave a Reply

Your email address will not be published.