pspdfkit_flutter 2.1.0 copy "pspdfkit_flutter: ^2.1.0" to clipboard
pspdfkit_flutter: ^2.1.0 copied to clipboard

outdated

A Flutter plugin providing a feature-rich PDF viewing and editing experience to your users with the powerful PSPDFKit PDF SDK.

PSPDFKit Flutter #

PSPDFKit wrapper for Flutter. Available at pub.dev and GitHub.

If you are new to Flutter, make sure to check our blog:

For our quick-start guides, check out our website.

Platform specific README exists for Android and iOS.

Setup #

Integration into a New Flutter App #

Android #

Requirements

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

    flutter create --org com.example.pspdfkit_demo pspdfkit_demo
    
  2. In the terminal app, change the location of the current working directory to your project:

    cd pspdfkit_demo
    
  3. Open the app’s Gradle build file, android/app/build.gradle:

    open android/app/build.gradle
    
  4. Modify the minimum SDK version, enable multidex, and set the Java compatibility to Java 8 to enable desugaring. All this is done inside the android section:

    android {
        defaultConfig {
    -        minSdkVersion 16
    +        minSdkVersion 21
    ...
    +        multiDexEnabled true
    ...
    +    compileOptions {
    +        sourceCompatibility 1.8
    +        targetCompatibility 1.8
    +    }
    ...
    }
    
  5. Open pubspec.yaml:

    open pubspec.yaml
    
  6. Add the PSPDFKit and path_provider dependencies in pubspec.yaml:

    dependencies:
    flutter:
        sdk: flutter
    +  pspdfkit_flutter:
    +  path_provider: ^0.4.1
    
  7. From the terminal app, run the following command to get all the packages:

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

    flutter pub upgrade
    
  9. 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.

  10. In lib/main.dart replace YOUR_LICENSE_KEY_GOES_HERE with your PSPDFKit license key.

  11. Add the PDF document you want to display in your project’s assets directory.

    • First create a PDFs directory:

      mkdir PDFs
      
    • Add a sample document into the newly created PDFs directory called Document.pdf:

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

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

  14. Run the app with:

    flutter run
    

iOS #

Requirements

Getting Started

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

    flutter create --org com.example.pspdfkit_demo pspdfkit_demo
    
  2. In the terminal app, change the location of the current working directory to your project:

    cd pspdfkit_demo
    
  3. Open Runner.xcworkspace from the ios folder in Xcode:

    open ios/Runner.xcworkspace
    
  4. Make sure the iOS Deployment Target is set to 12.0 or higher.

    iOS Deployment Target

  5. Change "View controller-based status bar appearance" to YES in Info.plist.

    iOS View controller-based status bar appearance

  6. Add the PSPDFKit and path_provider dependencies in pubspec.yaml:

    dependencies:
    flutter:
        sdk: flutter
    +  pspdfkit_flutter:
    +  path_provider: ^0.4.1
    
  7. From the terminal app, run the following command to get all the packages:

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

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

    open ios/Podfile
    
  10. Update the platform to iOS 12 and add the PSPDFKit Podspec:

    -# platform :ios, '9.0'
    +platform :ios, '12.0'
    ...
    flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
    +  pod 'PSPDFKit', podspec:'https://customers.pspdfkit.com/pspdfkit-ios/latest.podspec'
    end
    
  11. Open lib/main.dart and replace the entire content with the contents of demo_project_main.dart. This simple example will load a PDF document from local device filesystem.

  12. In lib/main.dart replace YOUR_LICENSE_KEY_GOES_HERE with your PSPDFKit license key.

  13. Add the PDF document you want to display in your project’s assets directory.

    • First create a PDFs directory:

      mkdir PDFs
      
    • Add a sample document into the newly created PDFs directory called Document.pdf:

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

    # The following section is specific to Flutter.
    flutter:
    +  assets:
    +    - PDFs/
    ...
    
  15. Run flutter emulators --launch apple_ios_simulator to launch the iOS Simulator.

  16. Run the app with:

    flutter run
    

Example #

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');
```

Contributing #

Please ensure you signed our CLA so we can accept your contributions.

Migrating from Version 1.10.3 #

Q: I updated the Flutter plugin and I am getting the following error:

lib/main.dart:8:8: Error: Error when reading '../../.pub-cache/git/pspdfkit-flutter-b6241555b1ee3e816a0dce65145991c1a4477d94/lib/pspdfkit.dart': No such file or directory
import 'package:pspdfkit_flutter/pspdfkit.dart';
       ^
lib/main.dart:37:7: Error: The getter 'Pspdfkit' isn't defined for the class '_MyAppState'.
 - '_MyAppState' is from 'package:myapp/main.dart' ('lib/main.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'Pspdfkit'.
      Pspdfkit.present(tempDocumentPath);
      ^^^^^^^^
lib/main.dart:58:32: Error: The getter 'Pspdfkit' isn't defined for the class '_MyAppState'.
 - '_MyAppState' is from 'package:myapp/main.dart' ('lib/main.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'Pspdfkit'.
      frameworkVersion = await Pspdfkit.frameworkVersion;
                               ^^^^^^^^
lib/main.dart:73:5: Error: The getter 'Pspdfkit' isn't defined for the class '_MyAppState'.
 - '_MyAppState' is from 'package:myapp/main.dart' ('lib/main.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'Pspdfkit'.
    Pspdfkit.setLicenseKey("YOUR_LICENSE_KEY_GOES_HERE");
    ^^^^^^^^


FAILURE: Build failed with an exception.

A: If you were using version 1.10.3 or earlier, you will need to update the imports in your Dart files like so:

- import 'package:pspdfkit_flutter/pspdfkit.dart';
+ import 'package:pspdfkit_flutter/src/main.dart';

Troubleshooting #

Flutter Updates #

To update Flutter to the latest version, all you have to do is run flutter upgrade.

Flutter Configuration Problems #

Among the tools provided by Flutter, there is flutter doctor, a very handy program that checks your system configuration for you and provides step-by-step actions to take in case of problems.

Flutter doctor example

The verbose mode of flutter doctor is even more helpful; it prints out extensive information about the nature of an issue and how to fix it. To run the verbose mode, all you have to do is type flutter doctor -d.

CocoaPods Conflicts With Asdf #

If asdf is installed in your machine it might create problems when running Cocoapods, and Flutter will erroneusly suggest to install CocoaPods via brew with brew install cocoapods. This won't work because for this specific configuration CocoaPods needs to be installed via RubyGems. To fix this configuration issue just type gem install cocoapods && pod setup.

54
likes
0
pub points
87%
popularity

Publisher

verified publisherpspdfkit.com

A Flutter plugin providing a feature-rich PDF viewing and editing experience to your users with the powerful PSPDFKit PDF SDK.

Homepage
Repository (GitHub)
View/report issues

Documentation

Documentation

License

unknown (LICENSE)

Dependencies

flutter, pedantic

More

Packages that depend on pspdfkit_flutter