|
@@ -41,9 +41,9 @@ class CPDFViewCtrlFactory: NSObject, FlutterPlatformViewFactory {
|
|
|
|
|
|
class CPDFViewCtrlFlutter: NSObject, FlutterPlatformView, CPDFViewBaseControllerDelete {
|
|
|
|
|
|
- private var _pdfViewController : CPDFViewController
|
|
|
+ private var pdfViewController : CPDFViewController
|
|
|
|
|
|
- private var _navigationController : CNavigationController
|
|
|
+ private var navigationController : CNavigationController
|
|
|
|
|
|
private var _methodChannel : FlutterMethodChannel
|
|
|
|
|
@@ -54,8 +54,7 @@ class CPDFViewCtrlFlutter: NSObject, FlutterPlatformView, CPDFViewBaseController
|
|
|
arguments args: Any?,
|
|
|
binaryMessenger messenger: FlutterBinaryMessenger?
|
|
|
) {
|
|
|
-
|
|
|
- // 解析 文档路径、密码、配置信息
|
|
|
+ // Parses the document path, password, and configuration information
|
|
|
let initInfo = args as? [String: Any]
|
|
|
let jsonString = initInfo?["configuration"] ?? ""
|
|
|
let password = initInfo?["password"] ?? ""
|
|
@@ -64,28 +63,28 @@ class CPDFViewCtrlFlutter: NSObject, FlutterPlatformView, CPDFViewBaseController
|
|
|
let jsonDataParse = CPDFJSONDataParse(String: jsonString as! String)
|
|
|
let configuration = jsonDataParse.configuration
|
|
|
|
|
|
- // 创建pdfview controller视图
|
|
|
- _pdfViewController = CPDFViewController(filePath: path, password: password as! String, configuration: configuration!)
|
|
|
+ // Create the pdfview controller view
|
|
|
+ pdfViewController = CPDFViewController(filePath: path, password: password as? String, configuration: configuration!)
|
|
|
|
|
|
- _navigationController = CNavigationController(rootViewController: _pdfViewController)
|
|
|
- _navigationController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
|
- _navigationController.view.frame = frame
|
|
|
+ navigationController = CNavigationController(rootViewController: pdfViewController)
|
|
|
+ navigationController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
|
+ navigationController.view.frame = frame
|
|
|
|
|
|
_methodChannel = FlutterMethodChannel.init(name: "com.compdfkit.flutter.ui.pdfviewer.\(viewId)", binaryMessenger: messenger!)
|
|
|
|
|
|
super.init()
|
|
|
|
|
|
- // 设置代理,但是未生效
|
|
|
- _pdfViewController.delegate = self
|
|
|
+ // Proxy set, but not used
|
|
|
+ pdfViewController.delegate = self
|
|
|
|
|
|
- _navigationController.setViewControllers([_pdfViewController], animated: false)
|
|
|
+ navigationController.setViewControllers([pdfViewController], animated: false)
|
|
|
|
|
|
registeryMethodChannel(viewId: viewId, binaryMessenger: messenger!)
|
|
|
|
|
|
}
|
|
|
|
|
|
func view() -> UIView {
|
|
|
- return _navigationController.view
|
|
|
+ return navigationController.view
|
|
|
}
|
|
|
|
|
|
public func PDFViewBaseControllerDissmiss(_ baseControllerDelete: CPDFViewBaseController) {
|
|
@@ -101,8 +100,25 @@ class CPDFViewCtrlFlutter: NSObject, FlutterPlatformView, CPDFViewBaseController
|
|
|
switch call.method {
|
|
|
case "save":
|
|
|
// save pdf
|
|
|
- print("ComPDFKit-Flutter: save PDF")
|
|
|
- result(true) // or return false
|
|
|
+ guard let pdfListView = self.pdfViewController.pdfListView else {
|
|
|
+ result(true)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var isSuccess = false
|
|
|
+ if (pdfListView.isEditing() == true && pdfListView.isEdited() == true) {
|
|
|
+ pdfListView.commitEditing()
|
|
|
+ if pdfListView.document.isModified() == true {
|
|
|
+ isSuccess = pdfListView.document.write(to: pdfListView.document.documentURL)
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ if(pdfListView.document != nil) {
|
|
|
+ if pdfListView.document.isModified() == true {
|
|
|
+ isSuccess = pdfListView.document.write(to: pdfListView.document.documentURL)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ result(isSuccess) // or return false
|
|
|
default:
|
|
|
result(FlutterMethodNotImplemented)
|
|
|
}
|