flutter_cached_pdfview
一个显示 iOS 和 Android 原生 PDF 视图的包,支持从 Path、Asset 或 Url 等不同资源打开并进行缓存。
- 支持从路径打开PDF
- 支持从资源文件打开PDF
- 支持从URL打开PDF并缓存
设置
iOS
通过向应用的 Info.plist 文件添加一个布尔属性来选择加入嵌入式视图预览
键为 io.flutter.embedded_views_preview,值为 YES。
iOS (仅支持> 11.0) 您需要在您的 ios/Podfile 中添加此行
platform :ios, '11.0'
在 示例 中已准备好
导入它
现在,在您的 Dart 代码中,您可以使用
import 'package:flutter_cached_pdfview/flutter_cached_pdfview.dart';
选项
| 名称 | Android | iOS | 默认值 |
|---|---|---|---|
| defaultPage | ✅ | ✅ | 0 |
| onViewCreated | ✅ | ✅ | 空 |
| onRender | ✅ | ✅ | 空 |
| onPageChanged | ✅ | ✅ | 空 |
| onError | ✅ | ✅ | 空 |
| onPageError | ✅ | ❌ | 空 |
| gestureRecognizers | ✅ | ✅ | 空 |
| 文件路径 | ✅ | ✅ | |
| fitPolicy | ✅ | ❌ | FitPolicy.WIDTH |
| enableSwipe | ✅ | ✅ | 真 |
| swipeHorizontal | ✅ | ✅ | 假 |
| password | ✅ | ✅ | 空 |
| nightMode | ✅ | ❌ | 假 |
| password | ✅ | ✅ | 空 |
| autoSpacing | ✅ | ✅ | 真 |
| pageFling | ✅ | ✅ | 真 |
| pageSnap | ✅ | ❌ | 真 |
控制器选项
| 名称 | 描述 | 参数 | 返回 |
|---|---|---|---|
| getPageCount | 获取总页数 | - | Future<int> |
| getCurrentPage | 获取当前页 | - | Future<int> |
| setPage | 跳转/设置页面 | int page |
Future<bool> |
示例
从资源文件
PDF(
enableSwipe: true,
swipeHorizontal: true,
autoSpacing: false,
pageFling: false,
onError: (error) {
print(error.toString());
},
onPageError: (page, error) {
print('$page: ${error.toString()}');
},
onPageChanged: (int page, int total) {
print('page change: $page/$total');
},
).fromAsset('assets/pdf/file-example.pdf'),
从URL缓存
PDF(
swipeHorizontal: true,
).cachedFromUrl('http://africau.edu/images/default/sample.pdf'),
用于生产环境
如果您使用proguard,您应该包含此行 [在 示例 中已准备好]。
-keep class com.shockwave.**
依赖项
Flutter
Android
iOS (仅支持> 11.0)
视频
