|
@@ -1466,7 +1466,33 @@ extension KMMainViewController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- @objc private func shareDocument(sender:KMToolbarViewController) {
|
|
|
|
|
|
+ @objc private func shareDocument(sender:KMToolbarViewController, limit: Bool = false) {
|
|
|
|
+ if (limit) {
|
|
|
|
+ var doucumentURL : URL = self.listView.document.documentURL
|
|
|
|
+ if doucumentURL != nil {
|
|
|
|
+ let docDir = NSTemporaryDirectory()
|
|
|
|
+ let documentName : String = doucumentURL.path.lastPathComponent
|
|
|
|
+ let path = docDir.stringByAppendingPathComponent(documentName)
|
|
|
|
+// let writeSuccess = self.listView.document.write(to: URL(fileURLWithPath: path))
|
|
|
|
+ let data = KMTools.saveWatermarkDocument(document: self.listView.document, to: URL(fileURLWithPath: path), secureOptions: self.secureOptions, removePWD: self.removeSecureFlag)
|
|
|
|
+ let writeSuccess = data != nil
|
|
|
|
+ if writeSuccess == false {
|
|
|
|
+ __NSBeep()
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ doucumentURL = URL(fileURLWithPath: path)
|
|
|
|
+ }
|
|
|
|
+ let array = [doucumentURL]
|
|
|
|
+ let picker = NSSharingServicePicker.init(items: array)
|
|
|
|
+ if sender.shareButton.window != nil {
|
|
|
|
+ picker.show(relativeTo: sender.shareButton.bounds, of: sender.shareButton, preferredEdge: NSRectEdge.minY)
|
|
|
|
+ } else {
|
|
|
|
+ picker.show(relativeTo: NSRect(x: (self.view.window?.contentView?.frame.size.width)!, y: (self.view.window?.contentView?.frame.size.height ?? 0)-8, width: 0, height: 0), of: self.view.window?.contentView ?? NSView(), preferredEdge: NSRectEdge.minY)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
var doucumentURL : URL = self.listView.document.documentURL
|
|
var doucumentURL : URL = self.listView.document.documentURL
|
|
if doucumentURL != nil {
|
|
if doucumentURL != nil {
|
|
let docDir = NSTemporaryDirectory()
|
|
let docDir = NSTemporaryDirectory()
|
|
@@ -1488,7 +1514,35 @@ extension KMMainViewController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- @objc private func shareFlatten(sender:KMToolbarViewController) {
|
|
|
|
|
|
+ @objc private func shareFlatten(sender:KMToolbarViewController, limit: Bool = false) {
|
|
|
|
+ if (limit) {
|
|
|
|
+ let document = self.listView.document ?? CPDFDocument()
|
|
|
|
+ var path = document!.documentURL.path
|
|
|
|
+ if path != nil {
|
|
|
|
+ let docDir = NSTemporaryDirectory()
|
|
|
|
+ let documentName : String = path.lastPathComponent
|
|
|
|
+ path = docDir.stringByAppendingPathComponent(documentName)
|
|
|
|
+ }
|
|
|
|
+ let pathFolder = path.fileURL.deletingLastPathComponent().path
|
|
|
|
+ var tfileName = path.deletingPathExtension.lastPathComponent
|
|
|
|
+ let tStdFileSuffix = "_flatten"
|
|
|
|
+ tfileName = tfileName + tStdFileSuffix + ".pdf"
|
|
|
|
+ path = pathFolder + "/" + tfileName
|
|
|
|
+
|
|
|
|
+ let data = KMTools.saveWatermarkDocumentForFlatten(document: document!, to: URL(fileURLWithPath: path))
|
|
|
|
+ let success = data != nil
|
|
|
|
+ if success {
|
|
|
|
+ let url = URL(fileURLWithPath: path)
|
|
|
|
+ let picker = NSSharingServicePicker.init(items: [url])
|
|
|
|
+ if sender.shareButton.window != nil {
|
|
|
|
+ picker.show(relativeTo: sender.shareButton.bounds, of: sender.shareButton, preferredEdge: NSRectEdge.minY)
|
|
|
|
+ } else {
|
|
|
|
+ picker.show(relativeTo: NSRect(x: (self.view.window?.contentView?.frame.size.width)!, y: (self.view.window?.contentView?.frame.size.height ?? 0)-8, width: 0, height: 0), of: self.view.window?.contentView ?? NSView(), preferredEdge: NSRectEdge.minY)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
let document = self.listView.document ?? CPDFDocument()
|
|
let document = self.listView.document ?? CPDFDocument()
|
|
var path = document!.documentURL.path
|
|
var path = document!.documentURL.path
|
|
if path != nil {
|
|
if path != nil {
|
|
@@ -1512,7 +1566,47 @@ extension KMMainViewController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- @objc private func shareOriginalPDF(sender:KMToolbarViewController) {
|
|
|
|
|
|
+ @objc private func shareOriginalPDF(sender:KMToolbarViewController, limit: Bool = false) {
|
|
|
|
+ if (limit) {
|
|
|
|
+ let document = self.listView.document ?? CPDFDocument()
|
|
|
|
+ var path = document!.documentURL.path
|
|
|
|
+ if path != nil {
|
|
|
|
+ let docDir = NSTemporaryDirectory()
|
|
|
|
+ let documentName : String = path.lastPathComponent
|
|
|
|
+ path = docDir.stringByAppendingPathComponent(documentName)
|
|
|
|
+ }
|
|
|
|
+// var writeSuccess = document!.write(to: URL(fileURLWithPath: path))
|
|
|
|
+ let data = KMTools.saveWatermarkDocument(document: document!, to: URL(fileURLWithPath: path), secureOptions: self.secureOptions, removePWD: self.removeSecureFlag)
|
|
|
|
+ var writeSuccess = data != nil
|
|
|
|
+ if writeSuccess == false {
|
|
|
|
+ __NSBeep()
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ let newDocument = CPDFDocument(url: URL(fileURLWithPath: path))!
|
|
|
|
+
|
|
|
|
+ for i in 0 ... newDocument.pageCount-1 {
|
|
|
|
+ let page = newDocument.page(at: i)
|
|
|
|
+ var annotations : [CPDFAnnotation] = []
|
|
|
|
+ for annotation in page!.annotations {
|
|
|
|
+ annotations.append(annotation)
|
|
|
|
+ }
|
|
|
|
+ for annotation in annotations {
|
|
|
|
+ annotation.page.removeAnnotation(annotation)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ writeSuccess = newDocument.write(to:URL(fileURLWithPath: path))
|
|
|
|
+ if writeSuccess {
|
|
|
|
+ let url = URL(fileURLWithPath: path)
|
|
|
|
+ let picker = NSSharingServicePicker.init(items: [url])
|
|
|
|
+ if sender.shareButton.window != nil {
|
|
|
|
+ picker.show(relativeTo: sender.shareButton.bounds, of: sender.shareButton, preferredEdge: NSRectEdge.minY)
|
|
|
|
+ } else {
|
|
|
|
+ picker.show(relativeTo: NSRect(x: (self.view.window?.contentView?.frame.size.width)!, y: (self.view.window?.contentView?.frame.size.height ?? 0)-8, width: 0, height: 0), of: self.view.window?.contentView ?? NSView(), preferredEdge: NSRectEdge.minY)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
let document = self.listView.document ?? CPDFDocument()
|
|
let document = self.listView.document ?? CPDFDocument()
|
|
var path = document!.documentURL.path
|
|
var path = document!.documentURL.path
|
|
if path != nil {
|
|
if path != nil {
|
|
@@ -2075,15 +2169,81 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
|
|
}
|
|
}
|
|
|
|
|
|
func toolbarViewController(_ viewController: KMToolbarViewController, shareDocument item: NSMenuItem) {
|
|
func toolbarViewController(_ viewController: KMToolbarViewController, shareDocument item: NSMenuItem) {
|
|
- self.shareDocument(sender: viewController)
|
|
|
|
|
|
+ if (!self.saveWatermarkFlag) {
|
|
|
|
+ self.shareDocument(sender: viewController)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ Task { @MainActor in
|
|
|
|
+ if await (KMLightMemberManager.manager.canPayFunction() == false) {
|
|
|
|
+ KMSubscribeWaterMarkWindowController.show(window: self.view.window!) { isSubscribeSuccess, isWaterMarkExport, isClose in
|
|
|
|
+ if (isClose) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if (isSubscribeSuccess) {
|
|
|
|
+ self.shareDocument(sender: viewController)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if (isWaterMarkExport) {
|
|
|
|
+ self.shareDocument(sender: viewController, limit: true)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ self.shareDocument(sender: viewController)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
func toolbarViewController(_ viewController: KMToolbarViewController, shareFlatten item: NSMenuItem) {
|
|
func toolbarViewController(_ viewController: KMToolbarViewController, shareFlatten item: NSMenuItem) {
|
|
- self.shareFlatten(sender: viewController)
|
|
|
|
|
|
+ if (!self.saveWatermarkFlag) {
|
|
|
|
+ self.shareFlatten(sender: viewController)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ Task { @MainActor in
|
|
|
|
+ if await (KMLightMemberManager.manager.canPayFunction() == false) {
|
|
|
|
+ KMSubscribeWaterMarkWindowController.show(window: self.view.window!) { isSubscribeSuccess, isWaterMarkExport, isClose in
|
|
|
|
+ if (isClose) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if (isSubscribeSuccess) {
|
|
|
|
+ self.shareFlatten(sender: viewController)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if (isWaterMarkExport) {
|
|
|
|
+ self.shareFlatten(sender: viewController, limit: true)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ self.shareFlatten(sender: viewController)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
func toolbarViewController(_ viewController: KMToolbarViewController, shareOriginalPDF item: NSMenuItem) {
|
|
func toolbarViewController(_ viewController: KMToolbarViewController, shareOriginalPDF item: NSMenuItem) {
|
|
- self.shareOriginalPDF(sender: viewController)
|
|
|
|
|
|
+ if (!self.saveWatermarkFlag) {
|
|
|
|
+ self.shareOriginalPDF(sender: viewController)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ Task { @MainActor in
|
|
|
|
+ if await (KMLightMemberManager.manager.canPayFunction() == false) {
|
|
|
|
+ let _ = KMSubscribeWaterMarkWindowController.show(window: self.view.window!) { isSubscribeSuccess, isWaterMarkExport, isClose in
|
|
|
|
+ if (isClose) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if (isSubscribeSuccess) {
|
|
|
|
+ self.shareOriginalPDF(sender: viewController)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if (isWaterMarkExport) {
|
|
|
|
+ self.shareOriginalPDF(sender: viewController, limit: true)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ self.shareOriginalPDF(sender: viewController)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
func toolbarViewController(_ viewController: KMToolbarViewController, scanOCRModel selectedTag: Int) {
|
|
func toolbarViewController(_ viewController: KMToolbarViewController, scanOCRModel selectedTag: Int) {
|
|
@@ -2259,6 +2419,7 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
|
|
if (response == .cancel) {
|
|
if (response == .cancel) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ self.commitEditingIfNeed()
|
|
guard let _url = KMTools.saveWatermarkDocument(document: self.document!, to: url!, secureOptions: self.secureOptions, removePWD: self.removeSecureFlag) else {
|
|
guard let _url = KMTools.saveWatermarkDocument(document: self.document!, to: url!, secureOptions: self.secureOptions, removePWD: self.removeSecureFlag) else {
|
|
return
|
|
return
|
|
}
|
|
}
|