liuxiaolong f06e15292b ComPDFKit(flutter) - v1.10.1 android 更新 | il y a 11 mois | |
---|---|---|
android | il y a 11 mois | |
example | il y a 11 mois | |
ios | il y a 11 mois | |
lib | il y a 11 mois | |
screenshots | il y a 1 an | |
.gitignore | il y a 1 an | |
.metadata | il y a 1 an | |
CHANGELOG.md | il y a 1 an | |
LICENSE | il y a 1 an | |
README.md | il y a 1 an | |
analysis_options.yaml | il y a 1 an | |
pubspec.lock | il y a 1 an | |
pubspec.yaml | il y a 11 mois |
ComPDFKit for Flutter is a comprehensive SDK that allows you to quickly add PDF fuctions to any Flutter application, such as viewer, annotations, editing PDFs, forms and signatures.
More information can be found at https://www.compdf.com/
Viewer component offers:
Annotations component offers:
Forms component offers:
Document Editor component offers:
Content Editor component offers:
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 to know more. However, any documents, sample code, or source code distribution from the released package of ComPDFKit to any third party is prohibited.
It's easy to embed ComPDFKit into Flutter applications with a few lines of code. Let's take a few minutes to get started.
The following sections describe the optimal systems and environments to support, as well as quick integration steps
Android
Please install the following required packages:
The Android NDK
Operating Environment Requirements:
19
or higher.compileSdkVersion
of 30
or higher.targetSdkVersion
of 30
or higher.iOS
Please install the following required packages:
The latest stable version of CocoaPods. Follow the CocoaPods installation guide to install it.
Operating Environment Requirements:
example
with the flutter
CLI:flutter create --org com.compdfkit.flutter example
cd example
example/android/app/src/main/AndroidManifest.xml
, add Storage Permission
:<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.compdfkit.flutter.example">
<!-- 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"/>
</application>
</manifest>
android/app/build.gradle
:open android/app/build.gradle
android
section: android {
defaultConfig {
- minSdkVersion flutter.minSdkVersion
+ minSdkVersion 21
...
}
}
pubspec.yaml
dependencies:
flutter:
sdk: flutter
+ compdfkit_flutter: ^1.11.0
flutter pub get
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.import 'dart:io';
import 'package:compdfkit_flutter/compdfkit.dart';
import 'package:compdfkit_flutter/cpdf_configuration.dart';
import 'package:flutter/material.dart';
const String DOCUMENT_PATH = '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 {
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(DOCUMENT_PATH);
final list = bytes.buffer.asUint8List();
final tempDir = await ComPDFKit.getTemporaryDirectory();
var pdfsDir = Directory('${tempDir.path}/pdfs');
pdfsDir.createSync(recursive: true);
final tempDocumentPath = '${tempDir.path}/$DOCUMENT_PATH';
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(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);
ComPDFKit.openDocument(tempDocumentPath,
password: '', configuration: configuration);
}
}
pdf
directory mkdir pdfs
pdfs
directory and name it PDF_Document.pdf
assets
directory in pubspec.yaml
flutter:
+ assets:
+ - pdfs/
Start your Android emulator, or connect a device.
Run the app with:
flutter run
example
with the flutter
CLI:flutter create --org com.compdfkit.flutter example
cd example
pubspec.yaml
dependencies:
flutter:
sdk: flutter
+ compdfkit_flutter: ^1.11.0
flutter pub get
open ios/Podfile
- platform :ios, '9.0'
+ platform :ios, '11.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/1.11.0.podspec'
+ pod 'ComPDFKit', podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/1.11.0.podspec'
end
example/ios
folder and run the pod install
command:pod install
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.import 'dart:io';
import 'package:compdfkit_flutter/compdfkit.dart';
import 'package:compdfkit_flutter/cpdf_configuration.dart';
import 'package:flutter/material.dart';
const String DOCUMENT_PATH = '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.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(DOCUMENT_PATH);
final list = bytes.buffer.asUint8List();
final tempDir = await ComPDFKit.getTemporaryDirectory();
var pdfsDir = Directory('${tempDir.path}/pdfs');
pdfsDir.createSync(recursive: true);
final tempDocumentPath = '${tempDir.path}/$DOCUMENT_PATH';
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(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);
ComPDFKit.openDocument(tempDocumentPath,
password: '', configuration: configuration);
}
}
pdf
directory mkdir pdfs
pdfs
directory and name it PDF_Document.pdf
assets
directory in pubspec.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>
flutter emulators --launch apple_ios_simulator
flutter run
Thank you for your interest in ComPDFKit, the only easy-to-use but powerful development solution to integrate high quality PDF rendering capabilities to your applications. If you encounter any technical questions or bug issues when using ComPDFKit Flutter PDF Library, please submit the problem report to the ComPDFKit team. More information as follows would help us to solve your problem:
Home Link:
Support & General Contact:
Email: support@compdf.com
Thanks, The ComPDFKit Team