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 |
---|---|
installation a convenience wrapper
the complete installation and api guides can be found at https://www.pdftron.com/documentation/android/guides/flutter
android
- 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
. - 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
- 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" + } ... }
- 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" /> ...
- 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
- replace
lib/main.dart
with what is shown here - 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. - run the app with the command convenience wrapper
flutter run
ios
- 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
- open
myapp
folder in a text editor. then openmyapp/pubspec.yaml
file, add:dependencies: flutter: sdk: flutter + pdftron_flutter: + git: + url: git://github.com/pdftron/pdftron-flutter.git + permission: 0.1.0
- run
flutter packages get
- 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
- run
flutter build ios --no-codesign
to ensure integration process is sucessful - replace
lib/main.dart
with what is shown here - run
flutter emulators --launch apple_ios_simulator
- 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
Comments are closed.