Getting Started on Flutter

Requirements

Install the following required packages:

Creating a New Project

  1. Create a Flutter project called pspdfkit_demo with the flutter CLI:

flutter create --org com.example.pspdfkit_demo pspdfkit_demo

Installing the PSPDFKit Dependency

  1. In the terminal app, change the location of the current working directory to your project:

cd <project-root>
  1. Open the project’s Gradle build file, android/build.gradle:

open android/build.gradle
  1. Modify the Kotlin version inside the buildscript section:

buildscript {
-   ext.kotlin_version = '1.3.50'
+   ext.kotlin_version = '1.8.10'
        repositories {
            google()
            mavenCentral()
    }
...
}
  1. Open the app’s Gradle build file, android/app/build.gradle:

open android/app/build.gradle
  1. Modify the compile SDK version and the minimum SDK version:

android {
-   compileSdkVersion flutter.compileSdkVersion
+   compileSdkVersion 33
...
    defaultConfig {
-        minSdkVersion flutter.minSdkVersion
+        minSdkVersion 21
...
    }
}
  1. Change the base Activity to extend FlutterFragmentActivity:

- import io.flutter.embedding.android.FlutterActivity;
+ import io.flutter.embedding.android.FlutterFragmentActivity;

- public class MainActivity extends FlutterActivity {
+ public class MainActivity extends FlutterFragmentActivity {
}
  1. Open Runner.xcworkspace from the ios folder in Xcode:

open ios/Runner.xcworkspace
  1. Make sure the iOS deployment target is set to 15.0 or higher.

iOS Deployment Target

  1. For PSPDFKit iOS SDK version 12.1.0 and above, it’s necessary to set the license key in the AppDelegate object before initializing PSPDFKit for the first time. If you’re using a trial version, set it as an empty string:

#import <PSPDFKit/PSPDFKit.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [PSPDFKitGlobal setLicenseKey:@"YOUR_LICENSE_KEY" options:@{PSPDFSettingKeyHybridEnvironment: @"Flutter"}];
    ...
    // Override point for customization after application launch.
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
...
  1. Open pubspec.yaml:

open pubspec.yaml
  1. Add the PSPDFKit dependency in pubspec.yaml:

dependencies:
  flutter:
     sdk: flutter
+ pspdfkit_flutter:
  1. From the terminal app, run the following command to get all the packages:

flutter pub get
  1. Then run the command below to upgrade the dependencies:

flutter pub upgrade
  1. Open your project’s Podfile in a text editor:

open ios/Podfile
  1. Update the platform to iOS 15 and add the PSPDFKit Podspec:

-# platform :ios, '9.0'
+ platform :ios, '15.0'
...
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
+  pod 'PSPDFKit', podspec:'https://my.pspdfkit.com/pspdfkit-ios/latest.podspec'
+  pod 'Instant', podspec: 'https://my.pspdfkit.com/instant/latest.podspec'

Displaying a PDF

  1. Open the lib/main.dart file:

open lib/main.dart
  1. Replace the contents of lib/main.dart with the following code snippet that loads a document from the assets path:

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:pspdfkit_flutter/pspdfkit.dart';

const String DOCUMENT_PATH = 'PDFs/Document.pdf';

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

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

class _MyAppState extends State<MyApp> {
void showDocument(BuildContext context) async {
	final bytes = await DefaultAssetBundle.of(context).load(DOCUMENT_PATH);
	final list = bytes.buffer.asUint8List();

	final tempDir = await Pspdfkit.getTemporaryDirectory();
	final tempDocumentPath = '${tempDir.path}/$DOCUMENT_PATH';

	final file = await File(tempDocumentPath).create(recursive: true);
	file.writeAsBytesSync(list);

	await Pspdfkit.present(tempDocumentPath);
}

@override
Widget build(BuildContext context) {
	final themeData = Theme.of(context);
	return MaterialApp(
		home: Scaffold(
		body: Builder(
			builder: (BuildContext context) {
				return Center(
				child: Column(
					mainAxisAlignment: MainAxisAlignment.spaceEvenly,
					children: [
						ElevatedButton(
						child: Text('Tap to Open Document',
							style: themeData.textTheme.headline4?.copyWith(fontSize: 21.0)),
							onPressed: () => showDocument(context))
					]));
			},
		)),
	);
}
}
  1. Add the PDF document you want to display in your project’s assets directory. You can use this Quickstart Guide PDF as an example.

  2. Create a PDFs directory:

mkdir PDFs
  1. Copy the sample document into the newly created PDFs directory:

cp ~/Downloads/Document.pdf PDFs/Document.pdf
  1. Specify the assets directory in pubspec.yaml:

# The following section is specific to Flutter.
flutter:
+  assets:
+    - PDFs/
...
  1. Start your Android emulator or iOS simulator, or connect a device.

  2. Run the app with:

flutter run

Next Steps

To learn more about Flutter, make sure to check out the following blog posts:

You can find our Flutter library on pub.dev and GitHub.

Requirements

Install the following required packages:

Installing the PSPDFKit Dependency

  1. In the terminal app, change the location of the current working directory to your project:

cd <project-root>
  1. Open the project’s Gradle build file, android/build.gradle:

open android/build.gradle
  1. Modify the Kotlin version inside the buildscript section:

buildscript {
-   ext.kotlin_version = '1.3.50'
+   ext.kotlin_version = '1.8.10'
        repositories {
            google()
            mavenCentral()
    }
...
}
  1. Open the app’s Gradle build file, android/app/build.gradle:

open android/app/build.gradle
  1. Modify the compile SDK version and the minimum SDK version:

android {
-   compileSdkVersion flutter.compileSdkVersion
+   compileSdkVersion 33
...
    defaultConfig {
-        minSdkVersion flutter.minSdkVersion
+        minSdkVersion 21
...
    }
}
  1. Change the base Activity to extend FlutterFragmentActivity:

- import io.flutter.embedding.android.FlutterActivity;
+ import io.flutter.embedding.android.FlutterFragmentActivity;

- public class MainActivity extends FlutterActivity {
+ public class MainActivity extends FlutterFragmentActivity {
}
  1. Open Runner.xcworkspace from the ios folder in Xcode:

open ios/Runner.xcworkspace
  1. Make sure the iOS deployment target is set to 15.0 or higher.

iOS Deployment Target

  1. For PSPDFKit iOS SDK version 12.1.0 and above, it’s necessary to set the license key in the AppDelegate object before initializing PSPDFKit for the first time. If you’re using a trial version, set it as an empty string:

#import <PSPDFKit/PSPDFKit.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [PSPDFKitGlobal setLicenseKey:@"YOUR_LICENSE_KEY" options:@{PSPDFSettingKeyHybridEnvironment: @"Flutter"}];
    ...
    // Override point for customization after application launch.
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
...
  1. Open pubspec.yaml:

open pubspec.yaml
  1. Add the PSPDFKit dependency in pubspec.yaml:

dependencies:
  flutter:
     sdk: flutter
+ pspdfkit_flutter:
  1. From the terminal app, run the following command to get all the packages:

flutter pub get
  1. Then run the command below to upgrade the dependencies:

flutter pub upgrade
  1. Open your project’s Podfile in a text editor:

open ios/Podfile
  1. Update the platform to iOS 15 and add the PSPDFKit Podspec:

-# platform :ios, '9.0'
+ platform :ios, '15.0'
...
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
+  pod 'PSPDFKit', podspec:'https://my.pspdfkit.com/pspdfkit-ios/latest.podspec'
+  pod 'Instant', podspec: 'https://my.pspdfkit.com/instant/latest.podspec'

Displaying a PDF

Integrating into an existing project consists of initializing the PSPDFKit SDK and presenting it with a document.

  1. Import the PSPDFKit package:

import 'package:pspdfkit_flutter/pspdfkit.dart';
  1. Showing a PDF document inside your Flutter app is as simple as this:

Pspdfkit.present('file:///path/to/Document.pdf');

If you’re having trouble with integration, go through the New Project guide to see if there’s anything missing in your setup.

  1. Add the PDF document you want to display in your project’s assets directory. You can use this Quickstart Guide PDF as an example.

  2. Create a PDFs directory:

mkdir PDFs
  1. Copy the sample document into the newly created PDFs directory:

cp ~/Downloads/Document.pdf PDFs/Document.pdf
  1. Specify the assets directory in pubspec.yaml:

# The following section is specific to Flutter.
flutter:
+  assets:
+    - PDFs/
...
  1. Start your Android emulator or iOS simulator, or connect a device.

  2. Run the app with:

flutter run

Next Steps

To learn more about Flutter, make sure to check out the following blog posts:

You can find our Flutter library on pub.dev and GitHub.

Requirements

Install the following required packages:

Cloning the Flutter Sample Project

  1. Open the terminal app and clone the GitHub repository:

git clone https://github.com/PSPDFKit/pspdfkit-flutter.git
  1. Enter the example project directory:

cd pspdfkit-flutter/example
  1. Start your Android emulator or iOS simulator, or connect a device.

  2. Launch the Catalog application:

flutter run

Next Steps

To learn more about Flutter, make sure to check out the following blog posts:

You can find our Flutter library on pub.dev and GitHub.

Requirements

Install the following required packages:

Creating a New Project

  1. Create a Flutter project called pspdfkit_demo with the flutter CLI:

flutter create --org com.example.pspdfkit_demo pspdfkit_demo

Installing the PSPDFKit Dependency

  1. In the terminal app, change the location of the current working directory to your project:

cd <project-root>
  1. Open the project’s Gradle build file, android/build.gradle:

open android/build.gradle
  1. Modify the Kotlin version inside the buildscript section:

buildscript {
-   ext.kotlin_version = '1.3.50'
+   ext.kotlin_version = '1.8.10'
        repositories {
            google()
            mavenCentral()
    }
...
}
  1. Open the app’s Gradle build file, android/app/build.gradle:

open android/app/build.gradle
  1. Modify the compile SDK version and the minimum SDK version:

android {
-   compileSdkVersion flutter.compileSdkVersion
+   compileSdkVersion 33
...
    defaultConfig {
-        minSdkVersion flutter.minSdkVersion
+        minSdkVersion 21
...
    }
}
  1. Change the base Activity to extend FlutterFragmentActivity:

- import io.flutter.embedding.android.FlutterActivity;
+ import io.flutter.embedding.android.FlutterFragmentActivity;

- public class MainActivity extends FlutterActivity {
+ public class MainActivity extends FlutterFragmentActivity {
}
  1. Open pubspec.yaml:

open pubspec.yaml
  1. Add the PSPDFKit dependency in pubspec.yaml:

dependencies:
  flutter:
     sdk: flutter
+ pspdfkit_flutter:
  1. From the terminal app, run the following command to get all the packages:

flutter pub get
  1. Then run the command below to upgrade the dependencies:

flutter pub upgrade

Displaying a PDF

  1. Open the lib/main.dart file:

open lib/main.dart
  1. Replace the contents of lib/main.dart with the following code snippet that loads a document from the assets path:

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:pspdfkit_flutter/pspdfkit.dart';

const String DOCUMENT_PATH = 'PDFs/Document.pdf';

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

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

class _MyAppState extends State<MyApp> {
void showDocument(BuildContext context) async {
	final bytes = await DefaultAssetBundle.of(context).load(DOCUMENT_PATH);
	final list = bytes.buffer.asUint8List();

	final tempDir = await Pspdfkit.getTemporaryDirectory();
	final tempDocumentPath = '${tempDir.path}/$DOCUMENT_PATH';

	final file = await File(tempDocumentPath).create(recursive: true);
	file.writeAsBytesSync(list);

	await Pspdfkit.present(tempDocumentPath);
}

@override
Widget build(BuildContext context) {
	final themeData = Theme.of(context);
	return MaterialApp(
		home: Scaffold(
		body: Builder(
			builder: (BuildContext context) {
				return Center(
				child: Column(
					mainAxisAlignment: MainAxisAlignment.spaceEvenly,
					children: [
						ElevatedButton(
						child: Text('Tap to Open Document',
							style: themeData.textTheme.headline4?.copyWith(fontSize: 21.0)),
							onPressed: () => showDocument(context))
					]));
			},
		)),
	);
}
}
  1. Add the PDF document you want to display in your project’s assets directory. You can use this Quickstart Guide PDF as an example.

  2. Create a PDFs directory:

mkdir PDFs
  1. Copy the sample document into the newly created PDFs directory:

cp ~/Downloads/Document.pdf PDFs/Document.pdf
  1. Specify the assets directory in pubspec.yaml:

# The following section is specific to Flutter.
flutter:
+  assets:
+    - PDFs/
...
  1. Start your Android emulator or connect a device.

  2. Run the app with:

flutter run

Next Steps

To learn more about Flutter, make sure to check out the following blog posts:

You can find our Flutter library on pub.dev and GitHub.

Requirements

Install the following required packages:

Installing the PSPDFKit Dependency

  1. In the terminal app, change the location of the current working directory to your project:

cd <project-root>
  1. Open the project’s Gradle build file, android/build.gradle:

open android/build.gradle
  1. Modify the Kotlin version inside the buildscript section:

buildscript {
-   ext.kotlin_version = '1.3.50'
+   ext.kotlin_version = '1.8.10'
        repositories {
            google()
            mavenCentral()
    }
...
}
  1. Open the app’s Gradle build file, android/app/build.gradle:

open android/app/build.gradle
  1. Modify the compile SDK version and the minimum SDK version:

android {
-   compileSdkVersion flutter.compileSdkVersion
+   compileSdkVersion 33
...
    defaultConfig {
-        minSdkVersion flutter.minSdkVersion
+        minSdkVersion 21
...
    }
}
  1. Change the base Activity to extend FlutterFragmentActivity:

- import io.flutter.embedding.android.FlutterActivity;
+ import io.flutter.embedding.android.FlutterFragmentActivity;

- public class MainActivity extends FlutterActivity {
+ public class MainActivity extends FlutterFragmentActivity {
}
  1. Open pubspec.yaml:

open pubspec.yaml
  1. Add the PSPDFKit dependency in pubspec.yaml:

dependencies:
  flutter:
     sdk: flutter
+ pspdfkit_flutter:
  1. From the terminal app, run the following command to get all the packages:

flutter pub get
  1. Then run the command below to upgrade the dependencies:

flutter pub upgrade

Displaying a PDF

Integrating into an existing project consists of initializing the PSPDFKit SDK and presenting it with a document.

  1. Import the PSPDFKit package:

import 'package:pspdfkit_flutter/pspdfkit.dart';
  1. Showing a PDF document inside your Flutter app is as simple as this:

Pspdfkit.present('file:///path/to/Document.pdf');

If you’re having trouble with integration, go through the New Project guide to see if there’s anything missing in your setup.

  1. Add the PDF document you want to display in your project’s assets directory. You can use this Quickstart Guide PDF as an example.

  2. Create a PDFs directory:

mkdir PDFs
  1. Copy the sample document into the newly created PDFs directory:

cp ~/Downloads/Document.pdf PDFs/Document.pdf
  1. Specify the assets directory in pubspec.yaml:

# The following section is specific to Flutter.
flutter:
+  assets:
+    - PDFs/
...
  1. Start your Android emulator or connect a device.

  2. Run the app with:

flutter run

Next Steps

To learn more about Flutter, make sure to check out the following blog posts:

You can find our Flutter library on pub.dev and GitHub.

Requirements

Install the following required packages:

Cloning the Flutter Sample Project

  1. Open the terminal app and clone the GitHub repository:

git clone https://github.com/PSPDFKit/pspdfkit-flutter.git
  1. Enter the example project directory:

cd pspdfkit-flutter/example
  1. Start your Android emulator or connect a device.

  2. Launch the Catalog application:

flutter run

Next Steps

To learn more about Flutter, make sure to check out the following blog posts:

You can find our Flutter library on pub.dev and GitHub.

Requirements

Install the following required packages:

Creating a New Project

  1. Create a Flutter project called pspdfkit_demo with the flutter CLI:

flutter create --org com.example.pspdfkit_demo pspdfkit_demo

Installing the PSPDFKit Dependency

  1. In the terminal app, change the location of the current working directory to your project:

cd <project-root>
  1. Open Runner.xcworkspace from the ios folder in Xcode:

open ios/Runner.xcworkspace
  1. Make sure the iOS deployment target is set to 15.0 or higher.

iOS Deployment Target

  1. For PSPDFKit iOS SDK version 12.1.0 and above, it’s necessary to set the license key in the AppDelegate object before initializing PSPDFKit for the first time. If you’re using a trial version, set it as an empty string:

#import <PSPDFKit/PSPDFKit.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [PSPDFKitGlobal setLicenseKey:@"YOUR_LICENSE_KEY" options:@{PSPDFSettingKeyHybridEnvironment: @"Flutter"}];
    ...
    // Override point for customization after application launch.
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
...
  1. Open pubspec.yaml:

open pubspec.yaml
  1. Add the PSPDFKit dependency in pubspec.yaml:

dependencies:
  flutter:
     sdk: flutter
+ pspdfkit_flutter:
  1. From the terminal app, run the following command to get all the packages:

flutter pub get
  1. Then run the command below to upgrade the dependencies:

flutter pub upgrade
  1. Open your project’s Podfile in a text editor:

open ios/Podfile
  1. Update the platform to iOS 15 and add the PSPDFKit Podspec:

-# platform :ios, '9.0'
+ platform :ios, '15.0'
...
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
+  pod 'PSPDFKit', podspec:'https://my.pspdfkit.com/pspdfkit-ios/latest.podspec'
+  pod 'Instant', podspec: 'https://my.pspdfkit.com/instant/latest.podspec'

Displaying a PDF

  1. Open the lib/main.dart file:

open lib/main.dart
  1. Replace the contents of lib/main.dart with the following code snippet that loads a document from the assets path:

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:pspdfkit_flutter/pspdfkit.dart';

const String DOCUMENT_PATH = 'PDFs/Document.pdf';

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

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

class _MyAppState extends State<MyApp> {
void showDocument(BuildContext context) async {
	final bytes = await DefaultAssetBundle.of(context).load(DOCUMENT_PATH);
	final list = bytes.buffer.asUint8List();

	final tempDir = await Pspdfkit.getTemporaryDirectory();
	final tempDocumentPath = '${tempDir.path}/$DOCUMENT_PATH';

	final file = await File(tempDocumentPath).create(recursive: true);
	file.writeAsBytesSync(list);

	await Pspdfkit.present(tempDocumentPath);
}

@override
Widget build(BuildContext context) {
	final themeData = Theme.of(context);
	return MaterialApp(
		home: Scaffold(
		body: Builder(
			builder: (BuildContext context) {
				return Center(
				child: Column(
					mainAxisAlignment: MainAxisAlignment.spaceEvenly,
					children: [
						ElevatedButton(
						child: Text('Tap to Open Document',
							style: themeData.textTheme.headline4?.copyWith(fontSize: 21.0)),
							onPressed: () => showDocument(context))
					]));
			},
		)),
	);
}
}
  1. Add the PDF document you want to display in your project’s assets directory. You can use this Quickstart Guide PDF as an example.

  2. Create a PDFs directory:

mkdir PDFs
  1. Copy the sample document into the newly created PDFs directory:

cp ~/Downloads/Document.pdf PDFs/Document.pdf
  1. Specify the assets directory in pubspec.yaml:

# The following section is specific to Flutter.
flutter:
+  assets:
+    - PDFs/
...
  1. Start your iOS simulator.

  2. Run the app with:

flutter run

Next Steps

To learn more about Flutter, make sure to check out the following blog posts:

You can find our Flutter library on pub.dev and GitHub.

Requirements

Install the following required packages:

Installing the PSPDFKit Dependency

  1. In the terminal app, change the location of the current working directory to your project:

cd <project-root>
  1. Open Runner.xcworkspace from the ios folder in Xcode:

open ios/Runner.xcworkspace
  1. Make sure the iOS deployment target is set to 15.0 or higher.

iOS Deployment Target

  1. For PSPDFKit iOS SDK version 12.1.0 and above, it’s necessary to set the license key in the AppDelegate object before initializing PSPDFKit for the first time. If you’re using a trial version, set it as an empty string:

#import <PSPDFKit/PSPDFKit.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [PSPDFKitGlobal setLicenseKey:@"YOUR_LICENSE_KEY" options:@{PSPDFSettingKeyHybridEnvironment: @"Flutter"}];
    ...
    // Override point for customization after application launch.
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
...
  1. Open pubspec.yaml:

open pubspec.yaml
  1. Add the PSPDFKit dependency in pubspec.yaml:

dependencies:
  flutter:
     sdk: flutter
+ pspdfkit_flutter:
  1. From the terminal app, run the following command to get all the packages:

flutter pub get
  1. Then run the command below to upgrade the dependencies:

flutter pub upgrade
  1. Open your project’s Podfile in a text editor:

open ios/Podfile
  1. Update the platform to iOS 15 and add the PSPDFKit Podspec:

-# platform :ios, '9.0'
+ platform :ios, '15.0'
...
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
+  pod 'PSPDFKit', podspec:'https://my.pspdfkit.com/pspdfkit-ios/latest.podspec'
+  pod 'Instant', podspec: 'https://my.pspdfkit.com/instant/latest.podspec'

Displaying a PDF

Integrating into an existing project consists of initializing the PSPDFKit SDK and presenting it with a document.

  1. Import the PSPDFKit package:

import 'package:pspdfkit_flutter/pspdfkit.dart';
  1. Showing a PDF document inside your Flutter app is as simple as this:

Pspdfkit.present('file:///path/to/Document.pdf');

If you’re having trouble with integration, go through the New Project guide to see if there’s anything missing in your setup.

  1. Add the PDF document you want to display in your project’s assets directory. You can use this Quickstart Guide PDF as an example.

  2. Create a PDFs directory:

mkdir PDFs
  1. Copy the sample document into the newly created PDFs directory:

cp ~/Downloads/Document.pdf PDFs/Document.pdf
  1. Specify the assets directory in pubspec.yaml:

# The following section is specific to Flutter.
flutter:
+  assets:
+    - PDFs/
...
  1. Start your iOS simulator.

  2. Run the app with:

flutter run

Next Steps

To learn more about Flutter, make sure to check out the following blog posts:

You can find our Flutter library on pub.dev and GitHub.

Requirements

Install the following required packages:

Cloning the Flutter Sample Project

  1. Open the terminal app and clone the GitHub repository:

git clone https://github.com/PSPDFKit/pspdfkit-flutter.git
  1. Enter the example project directory:

cd pspdfkit-flutter/example
  1. Start your iOS simulator.

  2. Launch the Catalog application:

flutter run

Next Steps

To learn more about Flutter, make sure to check out the following blog posts:

You can find our Flutter library on pub.dev and GitHub.