A new flutter for using Foxit PDF SDK to open a pdf document.
-
Foxit PDF SDK >= 6.2.1
For Android >= 6.2.1, After v7.2 only support AndroidX versions. For IOS >= 7.1
-
Flutter >= 1.0.0
-
Follow the Flutter getting started guides to install, set up an editor, and create a Flutter Project. , assume you create
testflutter
as your project. -
Download Foxit PDF SDK for Android package, extract it, and copy the following files (libraries and licenses) in the "libs" folder of the extracted package to
testflutter\android\libs
directory:FoxitRDK.aar FoxitRDKUIExtensions.aar RMSSDK-4.2-release.aar rms-sdk-ui.aar FoxitMobileScanningRDK.aar FoxitPDFScan-UI.aar rdk_key.txt rdk_sn.txt
-
Add dependency to your Flutter project in
testflutter/pubspec.yaml
.
dependencies:
flutter:
sdk: flutter
+ flutter_foxitpdf:
+ git:
+ url: https://github.com/foxitsoftware/flutter-foxitpdf.git
-
Run
flutter packages get
-
Adjust
testflutter/android/build.gradle
file.
allprojects {
repositories {
google()
jcenter()
+ flatDir {
+ dirs project(':flutter_foxitpdf').file("$rootDir/libs")
+ }
}
}
- Adjust
testflutter/android/app/src/main/AndroidManifest.xml
file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
package="com.foxitreact">
<application
android:name="io.flutter.app.FlutterApplication"
android:label="testflutter"
android:icon="@mipmap/ic_launcher"
+ tools:replace="android:label">
-
Replace
lib/main.dart
, see Usage -
Run, You can run this prject in
Android Studio
or by usingflutter run
-
You may also clone the plugin and run
example
in the project. You need to copy thelibs
toexample/libs
directory.
-
Follow the Flutter getting started guides to install, set up an editor, and create a Flutter Project. , assume you create
testflutter
as your project. -
Download Foxit PDF SDK for IOS package, extract it, and copy the following files (libraries and licenses) in the "libs" folder of the extracted package to
testflutter\ios\libs
directory:FoxitRDK.framework uiextensionsDynamic.framework FoxitPDFScanUI.framework (v8.0) rdk_key.txt rdk_sn.txt
-
Add dependency to your Flutter project in
testflutter/pubspec.yaml
.
dependencies:
flutter:
sdk: flutter
+ flutter_foxitpdf:
+ git:
+ url: https://github.com/foxitsoftware/flutter-foxitpdf.git
-
Run
flutter pub get
. -
Adjust
testflutter/ios/Podfile
file
# Uncomment this line to define a global platform for your project
+ platform :ios, '11.0'
......
target 'Runner' do
......
+ #Foxit pods
+ use_frameworks!
+ pod 'FoxitPDF', :path=>'./libs/FoxitPDF.podspec'
-
Run
flutter build ios --no-codesign
. -
Replace
lib/main.dart
, see Usage -
Run, You can run this prject in
Xcode
or by usingflutter run
-
You may also clone the plugin and run
example
in the project. You need to copy thelibs
toexample/ios/libs
directory.
Replace YOUR_RDK_SN
and YOUR_RDK_KEY
with your own license (rdk_key.txt, rdk_sn.txt
)
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_foxitpdf/flutter_foxitpdf.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
int _error = -1;
String _sn = 'YOUR_RDK_SN';
String _key = 'YOUR_RDK_KEY';
String _path = 'YOUR_PDF_FILE or YOUR_URL';
@override
void initState() {
super.initState();
initPlatformState();
init(_sn, _key);
openDocument(_path, ''); //1. open doc from local path
//openDocFromUrl(_path, ''); //2. open doc from url.
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion = await FlutterFoxitpdf.platformVersion;
} on PlatformException {
platformVersion = '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(() {
_platformVersion = platformVersion;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text('Running on: $_platformVersion\n'),
),
),
);
}
Future<void> init(String sn, String key) async {
int error;
try {
error = await FlutterFoxitpdf.initialize(sn, key);
} on PlatformException {
error = -1;
}
setState(() {
_error = error;
});
}
Future<void> openDocument(String path, String password) async {
await FlutterFoxitpdf.openDocument(path, password);
}
Future<void> openDocFromUrl(String url, String password) async {
await FlutterFoxitpdf.openDocFromUrl(url, password);
}
}
Initialize Foxit PDF SDK
FlutterFoxitpdf.initialize(String, String);
Open a pdf document from local path
FlutterFoxitpdf.openDocument(String, String)
Open a pdf document from url
FlutterFoxitpdf.openDocFromUrl(String, String)
1: uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:flutter_foxitpdf]
Suggestion:Increase your project's android/app/build.gradle
minSdk version to at least 19.
Suggestion: Add tools:replace="android:label"
to element at AndroidManifest.xml to override.
3:com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:The number of method references in a .dex file cannot exceed 64K.
Suggestion: Add multiDexEnabled true
to android#defaultConfig
at android/app/build.gradle
.
Suggestion: Add org.gradle.jvmargs=-Xmx2048M
to android/gradle.properties