|
@@ -151,119 +151,10 @@ Alternatively you can update the `AndroidManifest.xml` file to use `FlutterFragm
|
|
|
dependencies:
|
|
|
flutter:
|
|
|
sdk: flutter
|
|
|
-+ compdfkit_flutter: ^2.0.2
|
|
|
++ compdfkit_flutter: ^2.1.0
|
|
|
```
|
|
|
|
|
|
-8. From the terminal app, run the following command to get all the packages:
|
|
|
-
|
|
|
-```bash
|
|
|
-flutter pub get
|
|
|
-```
|
|
|
-
|
|
|
-9. Open `lib/main.dart` and replace the entire content with the following code. And fill in the license provided to you in the `ComPDFKit.init` method, this simple example will load a PDF document from the local device file system.
|
|
|
-
|
|
|
-```dart
|
|
|
-import 'dart:io';
|
|
|
-
|
|
|
-import 'package:compdfkit_flutter/compdfkit.dart';
|
|
|
-import 'package:compdfkit_flutter/cpdf_configuration.dart';
|
|
|
-
|
|
|
-import 'package:flutter/material.dart';
|
|
|
-
|
|
|
-const String _documentPath = 'pdfs/PDF_Document.pdf';
|
|
|
-
|
|
|
-void main() {
|
|
|
- runApp(const MyApp());
|
|
|
-}
|
|
|
-
|
|
|
-class MyApp extends StatefulWidget {
|
|
|
- const MyApp({super.key});
|
|
|
-
|
|
|
- @override
|
|
|
- State<MyApp> createState() => _MyAppState();
|
|
|
-}
|
|
|
-
|
|
|
-class _MyAppState extends State<MyApp> {
|
|
|
- @override
|
|
|
- void initState() {
|
|
|
- super.initState();
|
|
|
- _init();
|
|
|
- }
|
|
|
-
|
|
|
- void _init() async {
|
|
|
- /// Please replace it with your ComPDFKit license
|
|
|
- ComPDFKit.initialize(androidOnlineLicense : 'your compdfkit key', iosOnlineLicense : 'your compdfkit key');
|
|
|
-
|
|
|
- /// If you are using an offline certified license, please use init() method
|
|
|
- /// ComPDFKit.init('your compdfkit key')
|
|
|
- }
|
|
|
-
|
|
|
- @override
|
|
|
- Widget build(BuildContext context) {
|
|
|
- return MaterialApp(
|
|
|
- home: Scaffold(
|
|
|
- body: SafeArea(
|
|
|
- child: Center(
|
|
|
- child: ElevatedButton(
|
|
|
- onPressed: () async {
|
|
|
- showDocument(context);
|
|
|
- },
|
|
|
- child: const Text(
|
|
|
- 'Open Document',
|
|
|
- style: TextStyle(color: Colors.white),
|
|
|
- )),
|
|
|
- ))),
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- void showDocument(BuildContext context) async {
|
|
|
- final bytes = await DefaultAssetBundle.of(context).load(_documentPath);
|
|
|
- final list = bytes.buffer.asUint8List();
|
|
|
- final tempDir = await ComPDFKit.getTemporaryDirectory();
|
|
|
- var pdfsDir = Directory('${tempDir.path}/pdfs');
|
|
|
- pdfsDir.createSync(recursive: true);
|
|
|
-
|
|
|
- final tempDocumentPath = '${tempDir.path}/$_documentPath';
|
|
|
- final file = File(tempDocumentPath);
|
|
|
- if (!file.existsSync()) {
|
|
|
- file.create(recursive: true);
|
|
|
- file.writeAsBytesSync(list);
|
|
|
- }
|
|
|
- var configuration = CPDFConfiguration();
|
|
|
- // How to disable functionality:
|
|
|
- // setting the default display mode when opening
|
|
|
- // configuration.modeConfig = const ModeConfig(initialViewMode: CPreviewMode.annotations);
|
|
|
- // top toolbar configuration:
|
|
|
- // android:
|
|
|
- // configuration.toolbarConfig = const ToolbarConfig(androidAvailableActions: [
|
|
|
- // ToolbarAction.thumbnail, ToolbarAction.bota,
|
|
|
- // ToolbarAction.search, ToolbarAction.menu
|
|
|
- // ],
|
|
|
- // availableMenus: [
|
|
|
- // ToolbarMenuAction.viewSettings, ToolbarMenuAction.documentInfo, ToolbarMenuAction.security,
|
|
|
- // ]);
|
|
|
- // iOS:
|
|
|
- // configuration.toolbarConfig = const ToolbarConfig(
|
|
|
- // // ios top toolbar left buttons
|
|
|
- // iosLeftBarAvailableActions: [
|
|
|
- // ToolbarAction.back, ToolbarAction.thumbnail
|
|
|
- // ],
|
|
|
- // // ios top toolbar right buttons
|
|
|
- // iosRightBarAvailableActions: [
|
|
|
- // ToolbarAction.bota, ToolbarAction.search, ToolbarAction.menu
|
|
|
- // ],
|
|
|
- // availableMenus: [
|
|
|
- // ToolbarMenuAction.viewSettings, ToolbarMenuAction.documentInfo, ToolbarMenuAction.security,
|
|
|
- // ]);
|
|
|
- // readerview configuration
|
|
|
- // configuration.readerViewConfig = const ReaderViewConfig(linkHighlight: true, formFieldHighlight: true);
|
|
|
- ComPDFKit.openDocument(tempDocumentPath,
|
|
|
- password: '', configuration: configuration);
|
|
|
- }
|
|
|
-}
|
|
|
-```
|
|
|
-
|
|
|
-9. Add the PDF documents you want to display in the project
|
|
|
+8. Add the PDF documents you want to display in the project
|
|
|
|
|
|
* create a `pdf` directory
|
|
|
|
|
@@ -272,7 +163,7 @@ class _MyAppState extends State<MyApp> {
|
|
|
```
|
|
|
* Copy your example document into the newly created `pdfs` directory and name it `PDF_Document.pdf`
|
|
|
|
|
|
-10. Specify the `assets` directory in `pubspec.yaml`
|
|
|
+9. Specify the `assets` directory in `pubspec.yaml`
|
|
|
|
|
|
```diff
|
|
|
flutter:
|
|
@@ -280,11 +171,10 @@ class _MyAppState extends State<MyApp> {
|
|
|
+ - pdfs/
|
|
|
```
|
|
|
|
|
|
-11. Start your Android emulator, or connect a device.
|
|
|
-12. Run the app with:
|
|
|
+10. From the terminal app, run the following command to get all the packages:
|
|
|
|
|
|
```bash
|
|
|
-flutter run
|
|
|
+flutter pub get
|
|
|
```
|
|
|
|
|
|
#### iOS
|
|
@@ -307,16 +197,10 @@ cd example
|
|
|
dependencies:
|
|
|
flutter:
|
|
|
sdk: flutter
|
|
|
-+ compdfkit_flutter: ^2.0.2
|
|
|
++ compdfkit_flutter: ^2.1.0
|
|
|
```
|
|
|
|
|
|
-4. From the terminal app, run the following command to get all the packages:
|
|
|
-
|
|
|
-```bash
|
|
|
-flutter pub get
|
|
|
-```
|
|
|
-
|
|
|
-5. Open your project's Podfile in a text editor:
|
|
|
+4. Open your project's Podfile in a text editor:
|
|
|
|
|
|
```bash
|
|
|
open ios/Podfile
|
|
@@ -336,8 +220,8 @@ open ios/Podfile
|
|
|
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.0.2.podspec'
|
|
|
-+ pod 'ComPDFKit', podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/2.0.2.podspec'
|
|
|
++ pod 'ComPDFKit_Tools', podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit_tools/2.1.0.podspec'
|
|
|
++ pod 'ComPDFKit', podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/2.1.0.podspec'
|
|
|
|
|
|
end
|
|
|
```
|
|
@@ -348,7 +232,129 @@ open ios/Podfile
|
|
|
pod install
|
|
|
```
|
|
|
|
|
|
-8. Open `lib/main.dart` and replace the entire content with the following code. And fill in the license provided to you in the `ComPDFKit.init` method, this simple example will load a PDF document from the local device file system.
|
|
|
+8. Add the PDF documents you want to display in the project
|
|
|
+
|
|
|
+* create a `pdf` directory
|
|
|
+
|
|
|
+ ```bash
|
|
|
+ mkdir pdfs
|
|
|
+ ```
|
|
|
+* Copy your example document into the newly created `pdfs` directory and name it `PDF_Document.pdf`
|
|
|
+
|
|
|
+9. Specify the `assets` directory in `pubspec.yaml`
|
|
|
+
|
|
|
+```diff
|
|
|
+ flutter:
|
|
|
++ assets:
|
|
|
++ - pdfs/
|
|
|
+```
|
|
|
+
|
|
|
+10. 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>
|
|
|
+```
|
|
|
+
|
|
|
+11. From the terminal app, run the following command to get all the packages:
|
|
|
+
|
|
|
+```bash
|
|
|
+flutter pub get
|
|
|
+```
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+#### Apply the License Key
|
|
|
+
|
|
|
+ComPDFKit PDF SDK is a commercial SDK, which requires a license to grant developer permission to release their apps. Each license is only valid for one `bundle ID` or `applicationId` in development mode. Other flexible licensing options are also supported, please contact [our marketing team](mailto:support@compdf.com) to know more.
|
|
|
+
|
|
|
+To initialize ComPDFKit using a license key, call either of the following before using any other ComPDFKit APIs or features:
|
|
|
+
|
|
|
+* **Online license:**
|
|
|
+
|
|
|
+```dart
|
|
|
+ComPDFKit.initialize(androidOnlineLicense : 'your compdfkit key', iosOnlineLicense : 'your compdfkit key');
|
|
|
+```
|
|
|
+
|
|
|
+* **Offline license:**
|
|
|
+
|
|
|
+```dart
|
|
|
+ComPDFKit.init('your compdfkit key');
|
|
|
+```
|
|
|
+
|
|
|
+**Example:**
|
|
|
+
|
|
|
+```diff
|
|
|
+import 'dart:io';
|
|
|
+
|
|
|
+import 'package:compdfkit_flutter/compdfkit.dart';
|
|
|
+import 'package:compdfkit_flutter/cpdf_configuration.dart';
|
|
|
+
|
|
|
+import 'package:flutter/material.dart';
|
|
|
+
|
|
|
+const String _documentPath = 'pdfs/PDF_Document.pdf';
|
|
|
+
|
|
|
+void main() {
|
|
|
+ runApp(const MyApp());
|
|
|
+}
|
|
|
+
|
|
|
+class MyApp extends StatefulWidget {
|
|
|
+ const MyApp({super.key});
|
|
|
+
|
|
|
+ @override
|
|
|
+ State<MyApp> createState() => _MyAppState();
|
|
|
+}
|
|
|
+
|
|
|
+class _MyAppState extends State<MyApp> {
|
|
|
+
|
|
|
+ @override
|
|
|
+ void initState() {
|
|
|
+ super.initState();
|
|
|
+ _init();
|
|
|
+ }
|
|
|
+
|
|
|
+ void _init() async {
|
|
|
+ /// Please replace it with your ComPDFKit license
|
|
|
++ ComPDFKit.initialize(androidOnlineLicense : 'your compdfkit key', iosOnlineLicense : 'your compdfkit key');
|
|
|
+
|
|
|
+ /// If you are using an offline certified license, please use init() method
|
|
|
++ /// ComPDFKit.init('your compdfkit key')
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ Widget build(BuildContext context) {
|
|
|
+ return MaterialApp();
|
|
|
+ }
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+#### Usage
|
|
|
+
|
|
|
+There are 2 different ways to use ComPDFKit Flutter API:
|
|
|
+
|
|
|
+* Present a document via a plugin.
|
|
|
+* Show a ComPDFKit document view via a Widget.
|
|
|
+
|
|
|
+##### Usage Plugin
|
|
|
+
|
|
|
+Open `lib/main.dart`,replace the entire file with the following:
|
|
|
|
|
|
```dart
|
|
|
import 'dart:io';
|
|
@@ -418,106 +424,104 @@ class _MyAppState extends State<MyApp> {
|
|
|
file.writeAsBytesSync(list);
|
|
|
}
|
|
|
var configuration = CPDFConfiguration();
|
|
|
- // How to disable functionality:
|
|
|
- // setting the default display mode when opening
|
|
|
- // configuration.modeConfig = const ModeConfig(initialViewMode: CPreviewMode.annotations);
|
|
|
- // top toolbar configuration:
|
|
|
- // android:
|
|
|
- // configuration.toolbarConfig = const ToolbarConfig(androidAvailableActions: [
|
|
|
- // ToolbarAction.thumbnail, ToolbarAction.bota,
|
|
|
- // ToolbarAction.search, ToolbarAction.menu
|
|
|
- // ],
|
|
|
- // availableMenus: [
|
|
|
- // ToolbarMenuAction.viewSettings, ToolbarMenuAction.documentInfo, ToolbarMenuAction.security,
|
|
|
- // ]);
|
|
|
- // iOS:
|
|
|
- // configuration.toolbarConfig = const ToolbarConfig(iosLeftBarAvailableActions: [
|
|
|
- // ToolbarAction.back, ToolbarAction.thumbnail
|
|
|
- // ],
|
|
|
- // iosRightBarAvailableActions: [
|
|
|
- // ToolbarAction.bota, ToolbarAction.search, ToolbarAction.menu
|
|
|
- // ],
|
|
|
- // availableMenus: [
|
|
|
- // ToolbarMenuAction.viewSettings, ToolbarMenuAction.documentInfo, ToolbarMenuAction.security,
|
|
|
- // ]);
|
|
|
- // readerview configuration:
|
|
|
- // configuration.readerViewConfig = const ReaderViewConfig(linkHighlight: true, formFieldHighlight: true);
|
|
|
+ // Present a document via a plugin.
|
|
|
ComPDFKit.openDocument(tempDocumentPath,
|
|
|
password: '', configuration: configuration);
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
-9. Add the PDF documents you want to display in the project
|
|
|
-
|
|
|
-* create a `pdf` directory
|
|
|
-
|
|
|
- ```bash
|
|
|
- mkdir pdfs
|
|
|
- ```
|
|
|
-* Copy your example document into the newly created `pdfs` directory and name it `PDF_Document.pdf`
|
|
|
+##### Usage Widget
|
|
|
|
|
|
-10. Specify the `assets` directory in `pubspec.yaml`
|
|
|
+Open `lib/main.dart`,replace the entire file with the following:
|
|
|
|
|
|
-```diff
|
|
|
- flutter:
|
|
|
-+ assets:
|
|
|
-+ - pdfs/
|
|
|
-```
|
|
|
+```dart
|
|
|
+import 'dart:io';
|
|
|
|
|
|
-11. 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.
|
|
|
+import 'package:compdfkit_flutter/compdfkit.dart';
|
|
|
+import 'package:compdfkit_flutter/cpdf_configuration.dart';
|
|
|
+import 'package:compdfkit_flutter/widgets/cpdf_reader_widget.dart';
|
|
|
|
|
|
-
|
|
|
+import 'package:flutter/material.dart';
|
|
|
|
|
|
-```objective-c
|
|
|
-<key>NSCameraUsageDescription</key>
|
|
|
-<string>Your consent is required before you could access the function.</string>
|
|
|
+const String _documentPath = 'pdfs/PDF_Document.pdf';
|
|
|
|
|
|
-<key>NSMicrophoneUsageDescription</key>
|
|
|
-<string>Your consent is required before you could access the function.</string>
|
|
|
+void main() {
|
|
|
+ runApp(const MyApp());
|
|
|
+}
|
|
|
|
|
|
-<key>NSPhotoLibraryAddUsageDescription</key>
|
|
|
-<string>Your consent is required before you could access the function.</string>
|
|
|
+class MyApp extends StatefulWidget {
|
|
|
+ const MyApp({super.key});
|
|
|
|
|
|
-<key>NSPhotoLibraryUsageDescription</key>
|
|
|
-<string>Your consent is required before you could access the function.</string>
|
|
|
-
|
|
|
-<key>NSAppTransportSecurity</key>
|
|
|
- <dict>
|
|
|
- <key>NSAllowsArbitraryLoads</key>
|
|
|
- <true/>
|
|
|
- </dict>
|
|
|
-```
|
|
|
+ @override
|
|
|
+ State<MyApp> createState() => _MyAppState();
|
|
|
+}
|
|
|
|
|
|
-12. Start your Android emulator, or connect a device.
|
|
|
+class _MyAppState extends State<MyApp> {
|
|
|
+ String? _document;
|
|
|
|
|
|
-```bash
|
|
|
-flutter emulators --launch apple_ios_simulator
|
|
|
-```
|
|
|
+ @override
|
|
|
+ void initState() {
|
|
|
+ super.initState();
|
|
|
+ _init();
|
|
|
+ _getDocumentPath(context).then((value) {
|
|
|
+ setState(() {
|
|
|
+ _document = value;
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
-13. Run the app with:
|
|
|
+ void _init() async {
|
|
|
+ /// Please replace it with your ComPDFKit license
|
|
|
+ ComPDFKit.initialize(
|
|
|
+ androidOnlineLicense: 'your compdfkit key',
|
|
|
+ iosOnlineLicense: 'your compdfkit key');
|
|
|
|
|
|
-```bash
|
|
|
-flutter run
|
|
|
-```
|
|
|
+ /// If you are using an offline certified license, please use init() method
|
|
|
+ /// ComPDFKit.init('your compdfkit key')
|
|
|
+ }
|
|
|
|
|
|
-#### Apply the License Key
|
|
|
+ @override
|
|
|
+ Widget build(BuildContext context) {
|
|
|
+ return MaterialApp(
|
|
|
+ home: Scaffold(
|
|
|
+ resizeToAvoidBottomInset: false,
|
|
|
+ appBar: AppBar(
|
|
|
+ title: const Text('Dark Theme Example'),
|
|
|
+ ),
|
|
|
+ body: _document == null
|
|
|
+ ? Container()
|
|
|
+ : CPDFReaderWidget(
|
|
|
+ document: _document!,
|
|
|
+ configuration: CPDFConfiguration(),
|
|
|
+ onCreated: (_create) => {})));
|
|
|
+ }
|
|
|
|
|
|
-ComPDFKit PDF SDK is a commercial SDK, which requires a license to grant developer permission to release their apps. Each license is only valid for one `bundle ID` or `applicationId` in development mode. Other flexible licensing options are also supported, please contact [our marketing team](mailto:support@compdf.com) to know more.
|
|
|
+ Future<String> _getDocumentPath(BuildContext context) async {
|
|
|
+ final bytes = await DefaultAssetBundle.of(context).load(_documentPath);
|
|
|
+ final list = bytes.buffer.asUint8List();
|
|
|
+ final tempDir = await ComPDFKit.getTemporaryDirectory();
|
|
|
+ var pdfsDir = Directory('${tempDir.path}/pdfs');
|
|
|
+ pdfsDir.createSync(recursive: true);
|
|
|
|
|
|
-To initialize ComPDFKit using a license key, call either of the following before using any other ComPDFKit APIs or features:
|
|
|
+ final tempDocumentPath = '${tempDir.path}/$_documentPath';
|
|
|
+ final file = File(tempDocumentPath);
|
|
|
+ if (!file.existsSync()) {
|
|
|
+ file.create(recursive: true);
|
|
|
+ file.writeAsBytesSync(list);
|
|
|
+ }
|
|
|
+ return tempDocumentPath;
|
|
|
+ }
|
|
|
+}
|
|
|
+```
|
|
|
|
|
|
-* **Online license:**
|
|
|
+Start your Android emulator, or connect a device, Run the app with:
|
|
|
|
|
|
-```dart
|
|
|
-ComPDFKit.initialize(androidOnlineLicense : 'your compdfkit key', iosOnlineLicense : 'your compdfkit key');
|
|
|
+```bash
|
|
|
+flutter run
|
|
|
```
|
|
|
|
|
|
-* **Offline license:**
|
|
|
|
|
|
-```dart
|
|
|
-ComPDFKit.init('your compdfkit key');
|
|
|
-```
|
|
|
|
|
|
#### Troubleshooting
|
|
|
|
|
@@ -553,8 +557,8 @@ target 'PDFView_RN' do
|
|
|
# Pods for testing
|
|
|
end
|
|
|
|
|
|
-+ pod 'ComPDFKit', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.0.2'
|
|
|
-+ pod 'ComPDFKit_Tools', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.0.2'
|
|
|
++ pod 'ComPDFKit', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.1.0'
|
|
|
++ pod 'ComPDFKit_Tools', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.1.0'
|
|
|
|
|
|
# Enables Flipper.
|
|
|
#
|