Skip to content
Guides

Creating a New Project

Android

  1. Create a Flutter project called example with the flutter CLI:
bash
flutter create --org com.compdfkit.flutter example
  1. In the terminal app, change the location of the current working directory to your project:
bash
cd example
  1. open example/android/app/src/main/AndroidManifest.xml , add Internet Permission and Storage 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>
  1. Open the app's Gradle build file, android/app/build.gradle:
bash
open android/app/build.gradle
  1. Modify the minimum SDK version, All this is done inside the android section:
diff
 android {
     defaultConfig {
-        minSdkVersion flutter.minSdkVersion
+        minSdkVersion 21
         ...
     }
 }
  1. Open the project’s main activity class, android/app/src/main/java/com/example/compdfkit/flutter/example/MainActivity.java, Change the base Activity to extend FlutterFragmentActivity:
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 use CPDFReaderWidget 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.

  1. Add the ComPDFKit dependency in pubspec.yaml
diff
 dependencies:
   flutter:
     sdk: flutter
+  compdfkit_flutter: ^2.2.0
  1. From the terminal app, run the following command to get all the packages:
bash
flutter pub get

iOS

  1. Create a Flutter project called example with the flutter CLI:
bash
flutter create --org com.compdfkit.flutter example
  1. In the terminal app, change the location of the current working directory to your project:
bash
cd example
  1. Add the ComPDFKit dependency in pubspec.yaml
diff
 dependencies:
   flutter:
     sdk: flutter
+  compdfkit_flutter: ^2.2.0
  1. From the terminal app, run the following command to get all the packages:
bash
flutter pub get
  1. Open your project's Podfile in a text editor:
bash
open ios/Podfile
  1. 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
  1. Go to the example/ios folder and run the pod 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.

  1. 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.

create a pdf viewer with flutter

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>