Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

pdftron flutter convenience wrapper

convenience 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

preview

android ios
flutter-pdftron-demo-android convenience wrapper

installation a convenience wrapper

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

android

  1. first follow the flutter getting 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
    +  permission: 0.1.0
    convenience wrapper
    
  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 myappandroidappsrcmainandroidmanifest.xml file, add the following lines to the <application> tag:
    ...
    <application
    	android:name="io.flutter.app.flutterapplication"
    	android:label="myapp"
    	android:icon="@mipmap/ic_launcher"
    +	android:largeheap="true"
    +	android:usescleartexttraffic="true">
      ...
    convenience wrapper
    

    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 credentials in to the myapp/android/gradle.properties file.
    org.gradle.jvmargs=-xmx1536m
    
    aws_access_key=your_access_key_goes_here
    aws_secret_key=your_secret_key_goes_here
    
  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 convenience wrapper flutter run 

ios

  1. first, follow the official getting started guide on installation, setting 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:
    dependencies:
       flutter:
         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'
     end
    
  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

usage for convenience wrapper

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 {
  @override
  _myappstate createstate() => _myappstate();
}

class _myappstate extends state<myapp> {
  string _version = 'unknown';
  string _document = "https://pdftron.s3.amazonaws.com/downloads/pdfref.pdf";

  @override
  void initstate() {
    super.initstate();
    initplatformstate();

    if (platform.isios) {
      // open the document for ios, no need for permission
      pdftronflutter.opendocument(_document);
    } else {
      // request for permissions for android before opening document
      requestpermission();
    }
  }

  future<void> requestpermission() async {
    final res = await permission.requestsinglepermission(permissionname.storage);
    if (granted(res)) {
      pdftronflutter.opendocument(_document);
    }
  }

  // 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 {
      pdftronflutter.initialize("your_pdftron_license_key");
      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;
  }

  @override
  widget build(buildcontext context) {
    return materialapp(
      home: scaffold(
        appbar: appbar(
          title: const text('pdftron flutter app'),
        ),
        body: center(
          child: text('running on: $_versionn'),
        ),
      ),
    );
  }
}

apis

  • pdftronflutter.version

obtain pdftron sdk version

  • pdftronflutter.initialize(string)

initializes pdftron sdk

  • pdftronflutter.opendocument(string)

opens a document in the viewer


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.