Browse Source

PDFView Flutter - 文档更新

liuxiaolong 1 year ago
parent
commit
60c8badae5
1 changed files with 91 additions and 38 deletions
  1. 91 38
      README.md

+ 91 - 38
README.md

@@ -52,15 +52,18 @@ MethodChannel--> setIsContinueMode:get continue mode
   * [isCoverPageMode](#2.4)
   * [isCropMode](#2.5)
   * [readerBackgroundColor](#2.6)
+  * [getDocumentPageInfo](#2.7)
 * [注释设置](#3)
   * [annotAttribute](#3.1)
   * [currentFocusedType](#3.2)
   * [setAnnotAttribute](#3.3)
   * [CPDFContextMenuShowHelper](#3.4)
+  * [CPDFReaderView.focusedChangeListener](#3.5)
 
 <div id="0"></div>
+
 #### Flutter接入CPDFReaderView
-* viewType : com.compdfkit.pdf.flutter
+* viewType : com.compdfkit.pdf.flutter.pdfview
 * [教程](https://flutter.cn/docs/development/platform-integration/ios/platform-views)
 
 #### 初始化参数
@@ -164,7 +167,7 @@ MethodChannel--> setIsContinueMode:get continue mode
 **1.** Flutter中创建EventChannel对象
 ```dart
 const _readerViewCallBackEventChannel =
-    EventChannel('event_reader_view_call_back');
+    EventChannel('com.compdfkit.pdf.flutter.pdfview.view.call.back');
 ```
 **2.** 定义一个方法例如**setReaderViewCallbackListener**
 ```dart
@@ -203,12 +206,14 @@ CancelListener setReaderViewCallbackListener() {
 ```
 **3.** 在混合集成模式Widget创建完成的回调中调用setReaderViewCallbackListener
 * PlatformViewLink
+
 ```dart
 ..addOnPlatformViewCreatedListener((id) {
     setReaderViewCallbackListener();
 })
 ```
 * UIKitView
+
 ```dart
 onPlatformViewCreated: (id){
     setReaderViewCallbackListener();      
@@ -219,8 +224,10 @@ onPlatformViewCreated: (id){
 在**IReaderViewCallback**中通过**EventChannel.EventSink.success**返回结果
 > Android
 * 注册EventChannel
+
+
 ```kotlin
-        val readerViewCallbackEventChannel = EventChannel(messenger, EVENT_CHANNEL_READER_VIEW_CALL_BACK)
+        val readerViewCallbackEventChannel = EventChannel(messenger, 'com.compdfkit.pdf.flutter.pdfview.view.call.back')
         readerViewCallbackEventChannel.setStreamHandler(object : EventChannel.StreamHandler {
             override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {
                 readerView.setReaderViewCallbackEventEmitter1(events)
@@ -284,9 +291,10 @@ onPlatformViewCreated: (id){
 
 **示例**
 > Flutter获取滚动方向
+
 ```dart
 ///这里可以定义一个共用的MethodChannel
-const _methodChannel = MethodChannel('com.compdfkit.pdf.flutter');
+const _methodChannel = MethodChannel('com.compdfkit.pdf.flutter.pdfview.settings');
 
 //获取滚动方向
 Future<bool> scrollDirectionIsVerticalMode() async {
@@ -298,7 +306,7 @@ Future<bool> scrollDirectionIsVerticalMode() async {
 > Android 返回当前滚动方向
 ```kotlin
 //定义MethodChannel对象
-val methodChannel = MethodChannel(messenger, "com.compdfkit.pdf.flutter")
+val methodChannel = MethodChannel(messenger, "com.compdfkit.pdf.flutter.pdfview.settings")
 methodChannel.setMethodCallHandler(this)
 
 //在onMethodCall方法中返回结果
@@ -319,7 +327,7 @@ override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
     didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
     FlutterViewController* controller = (FlutterViewController*)self.window.rootViewController;
     FlutterMethodChannel* methodChannel = [FlutterMethodChannel
-                                              methodChannelWithName:@"com.compdfkit.pdf.flutter"
+                                              methodChannelWithName:@"com.compdfkit.pdf.flutter.pdfview.settings"
                                               binaryMessenger:controller.binaryMessenger];
     [methodChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
         if([@"getScrollDirection" isEqualToString:call.method]) {
@@ -337,7 +345,7 @@ override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
 ```swift
 class ComPDFKitPlugin {
     init(messenger : FlutterBinaryMessenger){
-        let channel = FlutterMethodChannel(name: "com.compdfkit.pdf.flutter", binaryMessenger: messenger)
+        let channel = FlutterMethodChannel(name: "com.compdfkit.pdf.flutter.pdfview.settings", binaryMessenger: messenger)
         channel.setMethodCallHandler{(call : FlutterMethodCall, result : @escaping FlutterResult) in
             if (call.method == "getScrollDirection"){
                 result("vertical")//此处仅示例作为参考,请从CPDFReaderView中获取滚动方向
@@ -379,6 +387,7 @@ class ComPDFKitPlugin {
 
 **示例**
 > Flutter 设置CPDFReaderView滚动方向
+
 ```dart
 ///direction : vertical or horizontal
 Future<bool> setScrollDirection(String direction) async {
@@ -408,6 +417,7 @@ override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
 }
 ```
 > **iOS**
+
 * Objective-C
 ```objc
 @implementation AppDelegate
@@ -416,7 +426,7 @@ override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
     didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
     FlutterViewController* controller = (FlutterViewController*)self.window.rootViewController;
     FlutterMethodChannel* methodChannel = [FlutterMethodChannel
-                                              methodChannelWithName:@"com.compdfkit.pdf.flutter"
+                                              methodChannelWithName:@"com.compdfkit.pdf.flutter.pdfview.settings"
                                               binaryMessenger:controller.binaryMessenger];
     [methodChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
         if([@"setScrollDirection" isEqualToString:call.method]) {
@@ -434,6 +444,7 @@ override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
 ```
 
 * Swift
+
 ```swift
 channel.setMethodCallHandler{(call : FlutterMethodCall, result : @escaping FlutterResult) in
    if (call.method == "setScrollDirection"){
@@ -447,6 +458,7 @@ channel.setMethodCallHandler{(call : FlutterMethodCall, result : @escaping Flutt
 
 
 <div id="2.2"></div>
+
 #### 设置获取滚动方式(isContinueMode)
 
 ##### **1. 获取滚动模式**
@@ -489,6 +501,7 @@ channel.setMethodCallHandler{(call : FlutterMethodCall, result : @escaping Flutt
 * * *
 
 <div id="2.3"></div>
+
 #### 显示模式(isDoublePage)
 
 ##### **1. 获取显示模式**
@@ -556,7 +569,6 @@ channel.setMethodCallHandler{(call : FlutterMethodCall, result : @escaping Flutt
 >示例:请参考[isVerticalMode](#2.1)
 
 
-
 ##### **2. 设置为封面显示模式**
 
 **请求**
@@ -579,6 +591,7 @@ channel.setMethodCallHandler{(call : FlutterMethodCall, result : @escaping Flutt
 * * *
 
 <div id="2.5"></div>
+
 #### 裁剪显示(isCropPageMode)
 ##### **1. 获取当前是否为裁剪模式**
 
@@ -659,6 +672,34 @@ channel.setMethodCallHandler{(call : FlutterMethodCall, result : @escaping Flutt
 
 * * *
 
+<div id="2.7"></div>
+
+#### 获取文档页码信息(getDocumentPageInfo)
+##### **1. 获取当前文档页数信息**
+
+| 方法名 | 通讯方式 | 参数 | 说明 |
+| --- | --- | --- | --- |
+| getDocumentPageInfo | MethodChannel | 无 |获取页码信息 |
+
+**响应**
+* 响应数据类型:**Map<String, Any>**
+* 响应数据:
+
+|Key| Value  | 类型 | 说明 |
+| --- | --- | --- | --- |
+| documentPageCount | 30 | int | 文档页数 |
+| documentCurrentPageIndex | 10 | int | 当前显示的页码 |
+
+
+>示例:请参考[isVerticalMode](#2.1)
+
+
+
+* * *
+
+
+
+
 <div id="3"></div>
 
 #### 注释设置
@@ -681,6 +722,8 @@ channel.setMethodCallHandler{(call : FlutterMethodCall, result : @escaping Flutt
 | freetext | 自由文本 |
 | signature | 签名注释,本质还是图章注释 |
 | stamp | 图章注释 |
+| link | 超链接注释 |
+| redact | 密文注释 |
 
 <div id="3.1"></div>
 
@@ -726,6 +769,8 @@ channel.setMethodCallHandler{(call : FlutterMethodCall, result : @escaping Flutt
 |  | fontType | courier,helvetica,times_roman | String | 字体类型,仅支持三种字体 |
 | signature |  |  |  |  |
 | stamp |  |  |  |  |
+| link |  |  |  |  |
+| redact |  |  |  |  |
 
 > signature、stamp由于是图片,无属性数据
 
@@ -767,7 +812,11 @@ channel.setMethodCallHandler{(call : FlutterMethodCall, result : @escaping Flutt
 |  | textStampDate | '2023/03/28' | String | 文本图章时间 |
 |  | textStampStyleShapeType | 'TEXT_STAMP_NONE','TEXT_STAMP_RECT'... | String | 文本图章样式,一共四种,无、圆角矩形、左箭头,右箭头 |
 |  | textStampStyleColorType | textStampWhite,textStampRed... | String | 文本图章颜色类型,白色,红色,绿色,蓝色 |
-
+| link | linkType | website,page,email | String | 超链接类型 |
+|  | linkWeb | https://pdfreaderpro.com/ | String | 网页链接 |
+|  | linkPage | 1~... | int | 跳转的页码 |
+|  | linkEmail| support@pdfreaderpro.com | String | 邮箱 | 
+| redact | 无 | | | |
 **响应**
 * 原生端无需返回设置注释属性结果
 
@@ -802,9 +851,10 @@ channel.setMethodCallHandler{(call : FlutterMethodCall, result : @escaping Flutt
 ##### 选中注释上下文菜单交互(CPDFContextMenuShowHelper)
 在CPDFReaderView视图中选中注释(例如:高亮),会弹出选择菜单,菜单中可以进行注释的属性调整、复制、删除等操作,其中属性调整需要与Flutter进行交互,通知Flutter弹出注释属性调整界面
 1. 在原生端Android注册**EventChannel**,iOS注册**FlutterEventChannel**,将**onListen**方法中的**EventChannel.EventSink**对象保存,以Android示例,iOS基本一致
+
 ```kotlin
         val readerViewContextMenuHelperEventChannel = 
-            EventChannel(messenger, “event_reader_view_context_menu_helper”)
+            EventChannel(messenger, “com.compdfkit.pdf.flutter.pdfview.context.menu.helper”)
         readerViewContextMenuHelperEventChannel.setStreamHandler {
             onListen { arguments, events ->
                 //此处保存events对象
@@ -873,7 +923,7 @@ channel.setMethodCallHandler{(call : FlutterMethodCall, result : @escaping Flutt
 
 3.在实现的**CPDFContextMenuShowHelper**中定义**MethodChannel**获取Flutter端传入的需要修改的注释属性
 ```kotlin
-        modifyAnnotationAttrChannel = MethodChannel(messenger,“method_modify_annotation_attribute”)
+        modifyAnnotationAttrChannel = MethodChannel(messenger,“com.compdfkit.pdf.flutter.pdfview.modify.annotation.attribute”)
         modifyAnnotationAttrChannel.setMethodCallHandler { call, result ->
             //这里获取flutter传入的颜色、透明度等参数
             val configuration = call.arguments as? HashMap<String, Any>
@@ -942,20 +992,20 @@ channel.setMethodCallHandler{(call : FlutterMethodCall, result : @escaping Flutt
 
 4.在用户关闭调节选项弹窗后会发出**dismissModifyAnnotationAttr**通知,请在此通知中释放**之前赋值的全局变量**
 ```kotlin
-        modifyAnnotationAttrChannel = MethodChannel(messenger,“method_modify_annotation_attribute”)
-        modifyAnnotationAttrChannel.setMethodCallHandler { call, result ->
-            //这里获取flutter传入的颜色、透明度等参数
-            val configuration = call.arguments as? HashMap<String, Any>
-            when(call.method){
-                “modifyAnnotationAttribute” ->{
-                ...
-                }
-                "dismissModifyAnnotationAttr" -> {
-                    selectMarkupAnnotImpl = null
-                    selectPageView = null
-                }
-            }
-        }
+        modifyAnnotationAttrChannel = MethodChannel(messenger,“com.compdfkit.pdf.flutter.pdfview.modify.annotation.attribute”)
+modifyAnnotationAttrChannel.setMethodCallHandler { call, result ->
+  //这里获取flutter传入的颜色、透明度等参数
+  val configuration = call.arguments as? HashMap<String, Any>
+  when(call.method){
+      “modifyAnnotationAttribute” ->{
+    ...
+  }
+    "dismissModifyAnnotationAttr" -> {
+      selectMarkupAnnotImpl = null
+      selectPageView = null
+    }
+  }
+}
 ```
 | 方法名 | 通讯方式 | 说明 |
 | --- | --- | --- |
@@ -963,6 +1013,7 @@ channel.setMethodCallHandler{(call : FlutterMethodCall, result : @escaping Flutt
 
 ***
 
+<div id="3.5"></div>
 
 ##### CPDFReaderView 注释状态变化监听
 在设置完签名注释、图章注释后,当前的currentFocusedType、touchMode会改变,当前焦点会从**添加注释状态**改为**阅读状态**,所以需要监听**cpdfReaderView.setOnFocusedTypeChangedListener** 通知flutter端当前的状态,以便于底部注释工具类选中状态变更
@@ -980,19 +1031,21 @@ iOS端请通过FlutterEventChannel返回当前焦点类型
 * Android示例
 ```kotlin
         // 首先定义EventChannel
-        val readerViewFocusedChangEventChannel = EventChannel(messenger, "event_reader_view_focused_change_call_back")
-        readerViewFocusedChangEventChannel.setStreamHandler {
-            onListen { arguments, events ->
-                readerView.setFocusedChangeEventEmitter(events)
-            }
-        }
-        
-        //CPDFReaderView监听焦点类型变化,通过EventChannel传递给flutter端,直接传入注释类型即可,CPDFAnnotation.Type
-        pdfReaderView.setOnFocusedTypeChangedListener {
-            focusedChangeCallbackEventEmitter?.success(it.name)
-        }
-        
+val readerViewFocusedChangEventChannel = EventChannel(messenger, "com.compdfkit.pdf.flutter.pdfview.focused.change.callback")
+readerViewFocusedChangEventChannel.setStreamHandler {
+  onListen { arguments, events ->
+    readerView.setFocusedChangeEventEmitter(events)
+  }
+}
+
+//CPDFReaderView监听焦点类型变化,通过EventChannel传递给flutter端,直接传入注释类型即可,CPDFAnnotation.Type
+pdfReaderView.setOnFocusedTypeChangedListener {
+  focusedChangeCallbackEventEmitter?.success(it.name)
+}
+
 ```
+***
+