- Notifications
You must be signed in to change notification settings - Fork5
ComPDFKit for Flutter is a full-featured PDF SDK that enables you to quickly integrate PDF features into your Flutter applications for both Android and iOS.
License
ComPDFKit/compdfkit-pdf-sdk-flutter
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
ComPDFKit for Flutter, developed and managed byComPDF, is a powerful PDF library that enables developers to seamlessly integrate PDF viewing, a nnotation, editing, form filling, redaction, and signing into any iOS or Android application. It is available atpub.dev andGitHub.
For more information, please check ourdeveloper guides.
- Requirements
- Steps to Build the Flutter PDF Editor by Integrating ComPDFKit PDF SDK
- Example App
- Support
Before starting, please make sure that you have already met the following prerequisites:
ComPDF offers two types of license keys: a free 30-day trial license and a commercial license.
- Trial License – You can request a30-day free trial online.
- Commercial License – For advanced features, custom requirements, or quote inquiries, feel free tocontact our sales.
For the Flutter PDF SDK, the commercial license must be bound to your application’s ApplicationId and iOS BundleId.
Android
Please install the following required packages:
- Thelatest stable version of Flutter
- Thelatest stable version of Android Studio
- TheAndroid NDK
- AnAndroid Virtual Device
Operating Environment Requirements:
- A minSdkVersion of
21or higher. - A
compileSdkVersionof34or higher. - A
targetSdkVersionof34or higher. - Android ABI(s): x86, x86_64, armeabi-v7a, arm64-v8a.
iOS
Please install the following required packages:
- Thelatest stable version of Flutter
- Thelatest stable version of Xcode
- Thelatest stable version of CocoaPods. Follow theCocoaPods installation guide to install it.
Operating Environment Requirements:
- The iOS 12.0 or higher.
- The Xcode 12.0 or newer for Objective-C or Swift.
- Create a Flutter project called
examplewith theflutterCLI:
flutter create --org com.compdfkit.flutter example
- In the terminal app, change the location of the current working directory to your project:
cd example- open
example/android/app/src/main/AndroidManifest.xml, addInternet PermissionandStorage Permission:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.compdfkit.flutter.example">+ <uses-permission android:name="android.permission.INTERNET"/> <!-- Required to read and write documents from device storage -->+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <!-- Optional settings -->+ <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/> <application+ android:requestLegacyExternalStorage="true"> </application> </manifest>
- Open the app's Gradle build file,
android/app/build.gradle:
open android/app/build.gradle
- Modify the minimum SDK version, All this is done inside the
androidsection:
android { defaultConfig {- minSdkVersion flutter.minSdkVersion+ minSdkVersion 21 ... } }- Open the project’s main activity class,
android/app/src/main/java/com/example/compdfkit/flutter/example/MainActivity.java, Change the baseActivityto extendFlutterFragmentActivity:
- import io.flutter.embedding.android.FlutterActivity;+ import io.flutter.embedding.android.FlutterFragmentActivity;- public class MainActivity extends FlutterActivity {+ public class MainActivity extends FlutterFragmentActivity {}
Alternatively you can update theAndroidManifest.xml file to useFlutterFragmentActivity as the launcher activity:
<activity- android:name=".MainActivity"+ android:name="io.flutter.embedding.android.FlutterFragmentActivity" android:exported="true" android:hardwareAccelerated="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:windowSoftInputMode="adjustPan">
Note:
FlutterFragmentActivityis not an official part of the Flutter SDK. If you need to useCPDFReaderWidgetin ComPDFKit for Flutter, you need to use this part of the code. You can skip this step if you don't need to use.
- Add the ComPDFKit dependency in
pubspec.yaml
dependencies: flutter: sdk: flutter+ compdfkit_flutter: ^2.5.1+1- Add the PDF documents you want to display in the project
create a
pdfdirectorymkdir pdfs
Copy your example document into the newly created
pdfsdirectory and name itPDF_Document.pdf
- Specify the
assetsdirectory inpubspec.yaml
flutter:+ assets:+ - pdfs/
- From the terminal app, run the following command to get all the packages:
flutter pub get
- Create a Flutter project called
examplewith theflutterCLI:
flutter create --org com.compdfkit.flutter example
- In the terminal app, change the location of the current working directory to your project:
cd example- Add the ComPDFKit dependency in
pubspec.yaml
dependencies: flutter: sdk: flutter+ compdfkit_flutter: ^2.5.1+1- Open your project's Podfile in a text editor:
open ios/Podfile
Note: If SSL network requests fail to download theComPDFKit library when you runpod install, you can see the processing method inTroubleshooting).
- Update the platform to iOS 12 and add the ComPDFKit Podspec:
- platform :ios, '9.0'+ platform :ios, '12.0' ... target 'Runner' do use_frameworks! use_modular_headers!` flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))+ pod 'ComPDFKit', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.5.1'+ pod 'ComPDFKit_Tools', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.5.1' end
- Go to the
example/iosfolder and run thepod installcommand:
pod install
- Add the PDF documents you want to display in the project
create a
pdfdirectorymkdir pdfs
Copy your example document into the newly created
pdfsdirectory and name itPDF_Document.pdf
- Specify the
assetsdirectory inpubspec.yaml
flutter:+ assets:+ - pdfs/
- To protect user privacy, before accessing the sensitive privacy data, you need to find the "*Info*" configuration in your iOS 10.0 or higher iOS project and configure the relevant privacy terms as shown in the following picture.
<key>NSCameraUsageDescription</key><string>Your consent is required before you could access the function.</string><key>NSMicrophoneUsageDescription</key><string>Your consent is required before you could access the function.</string><key>NSPhotoLibraryAddUsageDescription</key><string>Your consent is required before you could access the function.</string><key>NSPhotoLibraryUsageDescription</key><string>Your consent is required before you could access the function.</string> <key>NSAppTransportSecurity</key><dict><key>NSAllowsArbitraryLoads</key><true/></dict>- From the terminal app, run the following command to get all the packages:
flutter pub get
ComPDFKit PDF SDK currently supports two authentication methods to verify license keys: online authentication and offline authentication.
Learn about:
What is the authentication mechanism of ComPDFKit's license?
What are the differences between Online Authentication and Offline Authentication?
Accurately obtaining the license key is crucial for the application of the license.
- In the email you received, locate the
XMLfile containing the license key. - Copy the License.xml file into theassets directory of your Flutter project.
- Open the pubspec.yaml file of your project and configure the flutter: section to enable the assets directory.
- Initialize the SDK:
// Include the license in Flutter assets and copy to device storage// Add `license_key_flutter.xml` to your Flutter project’s assets directory;File licenseFile=awaitCPDFFileUtil.extractAsset(context,'assets/license_key_flutter.xml');ComPDFKit.initWithPath(licenseFile.path);
Alternative methods (optional)
// Android// Copy the license_key_flutter.xml file into the `android/app/src/main/assets` directory of your Android project:ComPDFKit.initWithPath('assets://license_key_flutter.xml');// iOS// Copy the license_key_flutter.xml file into your iOS project directory (or a readable location):ComPDFKit.initWithPath('license_key_flutter.xml');
There are 2 different ways to use ComPDFKit Flutter API:
- Present a document via a plugin.
- Show a ComPDFKit document view via a Widget.
Openlib/main.dart,replace the entire file with the following:
import'dart:io';import'package:compdfkit_flutter/compdfkit.dart';import'package:compdfkit_flutter/configuration/cpdf_configuration.dart';import'package:compdfkit_flutter/util/cpdf_file_util.dart';import'package:flutter/material.dart';constString _documentPath='pdfs/PDF_Document.pdf';voidmain() {runApp(constMyApp());}classMyAppextendsStatefulWidget {constMyApp({super.key});@overrideState<MyApp>createState()=>_MyAppState();}class_MyAppStateextendsState<MyApp> {@overridevoidinitState() {super.initState();_init(); }void_init()async {File licenseFile=awaitCPDFFileUtil.extractAsset(context,'assets/license_key_flutter.xml');ComPDFKit.initWithPath(licenseFile.path); }@overrideWidgetbuild(BuildContext context) {returnMaterialApp( home:Scaffold( body:SafeArea( child:Center( child:ElevatedButton( onPressed: ()async {showDocument(context); }, child:constText('Open Document', )), ))), ); }voidshowDocument(BuildContext context)async {var pdfFile=awaitCPDFFileUtil.extractAsset(_documentPath);var configuration=CPDFConfiguration();// Present a document via a plugin.ComPDFKit.openDocument(pdfFile.path, password:'', configuration: configuration); }}
Openlib/main.dart,replace the entire file with the following:
import'dart:io';import'package:compdfkit_flutter/compdfkit.dart';import'package:compdfkit_flutter/configuration/cpdf_configuration.dart';import'package:compdfkit_flutter/widgets/cpdf_reader_widget.dart';import'package:compdfkit_flutter/util/cpdf_file_util.dart';import'package:flutter/material.dart';constString _documentPath='pdfs/PDF_Document.pdf';voidmain() {runApp(constMyApp());}classMyAppextendsStatefulWidget {constMyApp({super.key});@overrideState<MyApp>createState()=>_MyAppState();}class_MyAppStateextendsState<MyApp> {String? _document;@overridevoidinitState() {super.initState();_init();_getDocumentPath().then((value) {setState(() { _document= value; }); }); }void_init()async {/// Please replace it with your ComPDFKit licenseFile licenseFile=awaitCPDFFileUtil.extractAsset(context,'assets/license_key_flutter.xml');ComPDFKit.initWithPath(licenseFile.path); }Future<String>_getDocumentPath()async {var file=awaitCPDFFileUtil.extractAsset('pdfs/PDF_Document.pdf');return file.path; }@overrideWidgetbuild(BuildContext context) {returnMaterialApp( home:Scaffold( resizeToAvoidBottomInset:false, appBar:AppBar( title:constText('CPDFReaderWidget Example'), ), body: _document==null?Container():CPDFReaderWidget( document: _document!, configuration:CPDFConfiguration(), onCreated: (_create)=> {}))); }}
Start your Android emulator, or connect a device, Run the app with:
flutter run
To seeComPDFKit for Flutter in action, check out ourFlutter example app andAPI reference
Showing a PDF document inside your Flutter app is as simple as this:
/// First. Please replace it with your ComPDFKit license// Include the license in Flutter assets and copy to device storage// Add `license_key_flutter.xml` to your Flutter project’s assets directory;File licenseFile=awaitCPDFFileUtil.extractAsset('assets/license_key_flutter.xml');ComPDFKit.initWithPath(licenseFile.path);/// open pdf documentComPDFKit.openDocument(tempDocumentPath, password:'', configuration:CPDFConfiguration());/// Here’s how you can open a PDF document using CPDFReaderWidget:Scaffold( resizeToAvoidBottomInset:false, appBar:AppBar(title:constText('CPDFReaderWidget Example'),), body:CPDFReaderWidget( document: widget.documentPath, configuration:CPDFConfiguration() ));
ComPDF has a professional R&D team that produces comprehensive technical documentation and guides to help developers. Also, you can get an immediate response when reporting your problems to our support team.
- For detailed information, please visit ourGuides page.
- Stay updated with the latest improvements through ourChangelog.
- For technical assistance, please reach out to ourTechnical Support.
- To get more details and an accurate quote, pleasecontact our Sales Team.
Thanks for reading,TheComPDF Team
About
ComPDFKit for Flutter is a full-featured PDF SDK that enables you to quickly integrate PDF features into your Flutter applications for both Android and iOS.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.



