Nutrient Flutter 是一个强大的插件,可将 Nutrient PDF SDK 集成到 Flutter 应用程序中,从而实现丰富的 PDF 查看和编辑功能。它支持在 Android 和 iOS 平台上高性能地渲染、注释、签名和操作 PDF 文件。专为寻求无缝、功能完整的 PDF 体验的开发者设计,该插件提供原生界面风格,具备可自定义工具和强大的文档处理能力。该插件简化了复杂的 PDF 工作流程,非常适合需要高级文档交互功能的应用。
适合场景
文档管理应用
电子签名工作流程
教育平台
PDF注释工具
协作编辑环境
主要特点
高性能PDF渲染
交互式注释
数字签名支持
可自定义的 UI 组件
跨平台兼容性
适合对象
开发以文档为中心的应用程序的开发者
需要安全PDF处理的团队
需要用户协作处理文档的应用程序
企业级PDF集成
使用建议
需要从 nutrient.io 获取许可
由于包含 SDK,可能会增加应用大小
有限的自定义选项,需高级配置
依赖外部 SDK 更新
新用户可能需要一定的学习曲线
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
Flutter Document SDK by Nutrient
Add powerful PDF functionality to your Flutter apps with the Nutrient Flutter SDK. View, annotate, and edit PDFs seamlessly across Android, iOS, and Web platforms.
Requirements
Flutter SDK (latest stable version)
For Android:
Android Studio (latest stable version)
Android NDK
Android Virtual Device or physical device
For iOS:
Xcode 16 or later
iOS 17.0 or later
For Web:
Modern web browser with WebAssembly support
Installation
Add the Nutrient Flutter SDK to your pubspec.yaml:
dependencies:nutrient_flutter:any
Run the following command:
flutter pub get
Platform Setup
Android Setup
Update your Android configuration in android/app/build.gradle:
Note: Replace 1.13.0 with the latest version of Nutrient Web SDK. Check the latest releases for the current version.
Option 2: Local Installation
Download Nutrient Web SDK. The download will start immediately and save a .tar.gz archive like PSPDFKit-Web-binary-<version>.tar.gz to your computer.
Once downloaded, extract the archive and copy the entire contents of its dist folder to your project's web/assets folder.
Verify your assets folder contains:
nutrient-viewer.js file
nutrient-viewer-lib directory with library assets
Add the Nutrient library to your web/index.html:
<scriptsrc="assets/nutrient-viewer.js"></script>
Note: Your server must have the Content-Type: application/wasm MIME type configured for WebAssembly files.
Sample Document Setup
Create a PDFs directory in your project root:
mkdir PDFs
Download our sample PDF document and save it as Document.pdf in the PDFs directory.
Add the assets directory to your pubspec.yaml:
flutter:assets:-PDFs/
Usage
Create a new file lib/main.dart with the following content:
import'package:flutter/material.dart';
import'package:nutrient_flutter/nutrient_flutter.dart';
import'dart:io';
import'package:flutter/foundation.dart';
constString documentPath = 'PDFs/Document.pdf';
voidmain() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize the Nutrient SDK with your license keyawaitNutrient.initialize(
androidLicenseKey: 'YOUR_ANDROID_LICENSE_KEY',
iosLicenseKey: 'YOUR_IOS_LICENSE_KEY',
webLicenseKey: 'YOUR_WEB_LICENSE_KEY',
);
runApp(constMaterialApp(
home: MyApp(),
));
}
classMyAppextendsStatelessWidget{
constMyApp({super.key});
Future<String> extractAsset(BuildContext context, String assetPath) async {
if (kIsWeb) {
return assetPath;
}
final bytes = awaitDefaultAssetBundle.of(context).load(assetPath);
final list = bytes.buffer.asUint8List();
final tempDir = awaitNutrient.getTemporaryDirectory();
final tempDocumentPath = '${tempDir.path}/$assetPath';
final file = File(tempDocumentPath);
await file.create(recursive: true);
file.writeAsBytesSync(list);
return file.path;
}
@overrideWidgetbuild(BuildContext context) {
returnScaffold(
body: FutureBuilder<String>(
future: extractAsset(context, documentPath),
builder: (context, snapshot) {
if (snapshot.hasData) {
/// NutrientView is a widget that displays a PDF document.returnNutrientView(
documentPath: snapshot.data!,
);
} elseif (snapshot.hasError) {
returnCenter(
child: Text('${snapshot.error}'),
);
} else {
returnconstCenter(
child: CircularProgressIndicator(),
);
}
}),
);
}
}
Note: Replace 'YOUR_ANDROID_LICENSE_KEY', 'YOUR_IOS_LICENSE_KEY', and 'YOUR_WEB_LICENSE_KEY' with your actual license keys. Do not pass any license keys if you want to run the SDK in demo mode, the SDK will run in demo mode with a watermark.