PSPDFKit for Flutter is available at pub.dev and GitHub.
If you are new to Flutter, make sure to check our Flutter blog posts:
- How I Got Started With Flutter.
- Getting Started with PSPDFKit Flutter.
- Opening a PDF in Flutter.
- How to Bridge Native iOS Code to Flutter.
- How to Customize Our Flutter PDF SDK for Android.
- Advances in Hybrid Technologies.
- How We Maintain Our Public Flutter Project Using a Private Monorepo.
- How to Download and Display a PDF Document in Flutter with PSPDFKit.
For our quick-start guides, check out our website.
Platform specific README exists for Android and iOS.
- The latest stable version of Flutter
- The latest stable version of Android Studio
- The Android NDK
- An Android Virtual Device or a hardware device
-
Create a Flutter project called
pspdfkit_demo
with theflutter
CLI:flutter create --org com.example.pspdfkit_demo pspdfkit_demo
-
In the terminal app, change the location of the current working directory to your project:
cd pspdfkit_demo
-
Open the project’s main activity class,
android/app/src/main/kotlin/com/example/pspdfkit_demo/pspdfkit_demo/MainActivity.kt
:open android/app/src/main/kotlin/com/example/pspdfkit_demo/pspdfkit_demo/MainActivity.kt
-
Modify the base from
FlutterActivity
toFlutterFragmentActivity
:package com.example.pspdfkit_demo.pspdfkit_demo -import io.flutter.embedding.android.FlutterActivity +import io.flutter.embedding.android.FlutterFragmentActivity -class MainActivity: FlutterActivity() { +class MainActivity: FlutterFragmentActivity() { }
-
Open the project’s Gradle build file,
android/build.gradle
:open android/build.gradle
-
Modify the Kotlin version inside the
buildscript
section:buildscript { - ext.kotlin_version = '1.3.50' + ext.kotlin_version = '1.5.31' repositories { google() mavenCentral() } ...
-
Open the app’s Gradle build file,
android/app/build.gradle
:open android/app/build.gradle
-
Modify the minimum SDK version, and enable
multidex
. All this is done inside theandroid
section:android { defaultConfig { - minSdkVersion flutter.minSdkVersion + minSdkVersion 21 ... + multiDexEnabled true } }
-
Open
pubspec.yaml
:open pubspec.yaml
-
Add the PSPDFKit dependency in
pubspec.yaml
:dependencies: flutter: sdk: flutter + pspdfkit_flutter: any
-
From the terminal app, run the following command to get all the packages:
```bash
flutter pub get
```
-
Then run the command below to upgrade the dependencies:
flutter pub upgrade
-
Open
lib/main.dart
and replace the entire content with the contents of demo_project_main.dart.txt. This simple example will load a PDF document from local device filesystem. -
Add the PDF document you want to display in your project’s
assets
directory.-
First create a
PDFs
directory:mkdir PDFs
-
Move a sample document into the newly created
PDFs
directory, and rename it asDocument.pdf
:cp ~/Downloads/PSPDFKit.pdf PDFs/Document.pdf
-
-
Specify the
assets
directory inpubspec.yaml
:# The following section is specific to Flutter. flutter: + assets: + - PDFs/ ...
-
Start your Android emulator, or connect a device.
-
Run the app with:
flutter run
- The latest stable version of Flutter
- The latest stable version of Xcode
- The latest stable version of CocoaPods
-
Create a Flutter project called
pspdfkit_demo
with theflutter
CLI:flutter create --org com.example.pspdfkit_demo pspdfkit_demo
-
In the terminal app, change the location of the current working directory to your project:
cd pspdfkit_demo
-
Open
Runner.xcworkspace
from theios
folder in Xcode:open ios/Runner.xcworkspace
-
Make sure the
iOS Deployment Target
is set to 13.0 or higher. -
Change "View controller-based status bar appearance" to YES in
Info.plist
. -
Add the PSPDFKit dependency in
pubspec.yaml
:dependencies: flutter: sdk: flutter + pspdfkit_flutter:
-
From the terminal app, run the following command to get all the packages:
flutter pub get
-
Then run the command below to upgrade the dependencies:
flutter pub upgrade
-
Open your project’s Podfile in a text editor:
open ios/Podfile
-
Update the platform to iOS 13 and add the PSPDFKit Podspec:
-# platform :ios, '9.0' + platform :ios, '13.0' ... target 'Runner' do use_frameworks! use_modular_headers!` flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) + pod 'PSPDFKit', podspec:'https://customers.pspdfkit.com/pspdfkit-ios/latest.podspec' end
-
Open
lib/main.dart
and replace the entire content with the contents of demo_project_main.dart.txt. This simple example will load a PDF document from local device filesystem. -
Add the PDF document you want to display in your project’s
assets
directory.-
First create a
PDFs
directory:mkdir PDFs
-
Move a sample document into the newly created
PDFs
directory, and rename it asDocument.pdf
:cp ~/Downloads/PSPDFKit.pdf PDFs/Document.pdf
-
-
Specify the
assets
directory inpubspec.yaml
:# The following section is specific to Flutter. flutter: + assets: + - PDFs/ ...
-
Run
flutter emulators --launch apple_ios_simulator
to launch the iOS Simulator. -
Run the app with:
flutter run
To see PSPDFKit Flutter in action check out our Flutter example app.
Showing a PDF document inside your Flutter app is as simple as this:
```dart
Pspdfkit.present('file:///path/to/Document.pdf');
```
PSPDFKit is a commercial product and requires the purchase of a license key when used in production. By default, this library will initialize in demo mode, placing a watermark on each PDF and limiting usage to 60 minutes.
To purchase a license for production use, please reach out to us via https://pspdfkit.com/sales/form/.
To initialize PSPDFKit using a license key, call either of the following before using any other PSPDFKit APIs or features:
To set the license key for both Android and iOS, use:
await Pspdfkit.setLicenseKeys("YOUR_FLUTTER_ANDROID_LICENSE_KEY_GOES_HERE", "YOUR_FLUTTER_IOS_LICENSE_KEY_GOES_HERE");
To set the license key for the currently running platform, use:
await Pspdfkit.setLicenseKey("YOUR_FLUTTER_LICENSE_KEY_GOES_HERE");
To upgrade PSPDFKit for Flutter in your app, please refer to the Upgrade and Migration Guides section.
For Troubleshooting common issues you might encounter when setting up PSPDFKit for Flutter, please refer to the Troubleshooting section.