On this page
Guides
Creating a New Project
Android
- Create a Flutter project called
example
with theflutter
CLI:
bash
flutter create --org com.compdfkit.flutter example
- In the terminal app, change the location of the current working directory to your project:
bash
cd example
- open
example/android/app/src/main/AndroidManifest.xml
, addInternet Permission
andStorage Permission
:
diff
<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
:
bash
open android/app/build.gradle
- Modify the minimum SDK version, All this is done inside the
android
section:
diff
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 baseActivity
to extendFlutterFragmentActivity
:
diff
- 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 the AndroidManifest.xml
file to use FlutterFragmentActivity
as the launcher activity:
diff
<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:
FlutterFragmentActivity
is not an official part of the Flutter SDK. If you need to useCPDFReaderWidget
in 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
diff
dependencies:
flutter:
sdk: flutter
+ compdfkit_flutter: ^2.2.0
- From the terminal app, run the following command to get all the packages:
bash
flutter pub get
iOS
- Create a Flutter project called
example
with theflutter
CLI:
bash
flutter create --org com.compdfkit.flutter example
- In the terminal app, change the location of the current working directory to your project:
bash
cd example
- Add the ComPDFKit dependency in
pubspec.yaml
diff
dependencies:
flutter:
sdk: flutter
+ compdfkit_flutter: ^2.2.0
- From the terminal app, run the following command to get all the packages:
bash
flutter pub get
- Open your project's Podfile in a text editor:
bash
open ios/Podfile
- Update the platform to iOS 12 and add the ComPDFKit Podspec:
diff
- 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_Tools', podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit_tools/2.2.0.podspec'
+ pod 'ComPDFKit', podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/2.2.0.podspec'
end
- Go to the
example/ios
folder and run thepod install
command:
bash
pod install
Note: If SSL network requests fail to download the ComPDFKit
library when you run pod install
, you can see the processing method in Troubleshooting.
- To protect user privacy,
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.
objective-c
<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>