|
@@ -1950,214 +1950,6 @@ extension KMMainViewController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- @objc private func shareDocument(sender:KMToolbarViewController, limit: Bool = false) {
|
|
|
|
- if (limit) {
|
|
|
|
- let document = self.listView.document ?? CPDFDocument()
|
|
|
|
- if document?.documentURL == nil {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- var doucumentURL : URL = self.listView.document.documentURL
|
|
|
|
- if doucumentURL.path.count > 0 {
|
|
|
|
- let docDir = NSTemporaryDirectory()
|
|
|
|
- let documentName : String = doucumentURL.path.lastPathComponent
|
|
|
|
- let path = docDir.stringByAppendingPathComponent(documentName)
|
|
|
|
- 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
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- let document = self.listView.document ?? CPDFDocument()
|
|
|
|
- if document?.documentURL == nil {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- var doucumentURL : URL = self.listView.document.documentURL
|
|
|
|
- if doucumentURL.path.count > 0 {
|
|
|
|
- let docDir = NSTemporaryDirectory()
|
|
|
|
- let documentName : String = doucumentURL.path.lastPathComponent
|
|
|
|
- let path = docDir.stringByAppendingPathComponent(documentName)
|
|
|
|
- let writeSuccess = self.listView.document.write(to: URL(fileURLWithPath: path))
|
|
|
|
- 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)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @objc private func shareFlatten(sender:KMToolbarViewController, limit: Bool = false) {
|
|
|
|
- if (limit) {
|
|
|
|
- let document = self.listView.document ?? CPDFDocument()
|
|
|
|
- var path: String?
|
|
|
|
- if document?.documentURL != nil {
|
|
|
|
- path = document?.documentURL.path ?? ""
|
|
|
|
- }
|
|
|
|
- if path?.count ?? 0 > 0 {
|
|
|
|
- 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()
|
|
|
|
- var path: String?
|
|
|
|
- if document?.documentURL != nil {
|
|
|
|
- path = document?.documentURL.path ?? ""
|
|
|
|
- }
|
|
|
|
- if path?.count ?? 0 > 0 {
|
|
|
|
- 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 success : Bool = document?.writeFlatten(to: URL(fileURLWithPath: path ?? "")) ?? false
|
|
|
|
- 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)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- @objc private func shareOriginalPDF(sender:KMToolbarViewController, limit: Bool = false) {
|
|
|
|
- guard let pdfDoc = self.listView.document else {
|
|
|
|
- NSSound.beep()
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- if !pdfDoc.allowsCopying || !pdfDoc.allowsPrinting {
|
|
|
|
- let alert = NSAlert()
|
|
|
|
- alert.alertStyle = .critical
|
|
|
|
- alert.messageText = NSLocalizedString("This is a secured document. Editing is not permitted.", comment: "")
|
|
|
|
- alert.runModal()
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (limit) {
|
|
|
|
- let document = self.listView.document ?? CPDFDocument()
|
|
|
|
- var path: String?
|
|
|
|
- if document?.documentURL != nil {
|
|
|
|
- path = document?.documentURL.path ?? ""
|
|
|
|
- }
|
|
|
|
- if path?.count ?? 0 > 0{
|
|
|
|
- let docDir = NSTemporaryDirectory()
|
|
|
|
- let documentName : String = path?.lastPathComponent ?? ""
|
|
|
|
- path = docDir.stringByAppendingPathComponent(documentName)
|
|
|
|
- }
|
|
|
|
- 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 ?? ""))
|
|
|
|
- let cnt = newDocument?.pageCount ?? 0
|
|
|
|
- for i in 0 ..< cnt {
|
|
|
|
- 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 ?? "")) ?? false
|
|
|
|
- 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()
|
|
|
|
- var path: String?
|
|
|
|
- if document?.documentURL != nil {
|
|
|
|
- path = document?.documentURL.path ?? ""
|
|
|
|
- }
|
|
|
|
- if path?.count ?? 0 > 0 {
|
|
|
|
- let docDir = NSTemporaryDirectory()
|
|
|
|
- let documentName : String = path?.lastPathComponent ?? ""
|
|
|
|
- path = docDir.stringByAppendingPathComponent(documentName)
|
|
|
|
- }
|
|
|
|
- var writeSuccess = document?.write(to: URL(fileURLWithPath: path ?? ""))
|
|
|
|
- if writeSuccess == false {
|
|
|
|
- __NSBeep()
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- let newDocument = CPDFDocument(url: URL(fileURLWithPath: path ?? ""))
|
|
|
|
-
|
|
|
|
- let cnt = newDocument?.pageCount ?? 0
|
|
|
|
- for i in 0 ..< cnt {
|
|
|
|
- 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 ?? false {
|
|
|
|
- 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)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
// 开启/关闭左边栏
|
|
// 开启/关闭左边栏
|
|
@objc func toggleLeftPane() -> Void {
|
|
@objc func toggleLeftPane() -> Void {
|
|
@@ -3072,24 +2864,6 @@ extension KMMainViewController : KMToolbarViewControllerDelegate {
|
|
self.trackEvent_share()
|
|
self.trackEvent_share()
|
|
}
|
|
}
|
|
|
|
|
|
- func toolbarViewController(_ viewController: KMToolbarViewController, shareDocument item: NSMenuItem) {
|
|
|
|
- self.shareDocument(sender: viewController)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- func toolbarViewController(_ viewController: KMToolbarViewController, shareFlatten item: NSMenuItem) {
|
|
|
|
- if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
|
- let winC = KMPurchaseCompareWindowController.sharedInstance()
|
|
|
|
- winC?.kEventName = "Reading_Flatten_BuyNow"
|
|
|
|
- winC?.showWindow(nil)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- self.shareFlatten(sender: viewController)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- func toolbarViewController(_ viewController: KMToolbarViewController, shareOriginalPDF item: NSMenuItem) {
|
|
|
|
- self.shareOriginalPDF(sender: viewController)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
func toolbarViewController(_ viewController: KMToolbarViewController, scanOCRModel selectedTag: Int) {
|
|
func toolbarViewController(_ viewController: KMToolbarViewController, scanOCRModel selectedTag: Int) {
|
|
if(0 == selectedTag) {
|
|
if(0 == selectedTag) {
|
|
} else {
|
|
} else {
|