KMBatchOperateImageToPDFViewController.swift 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. //
  2. // KMBatchOperateImageToPDFViewController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by liujiajie on 2023/12/5.
  6. //
  7. import Cocoa
  8. class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController, KMImageToPDFMethodDelegate, NSPopoverDelegate{
  9. @IBOutlet var outputTypeLabel: NSTextField!
  10. @IBOutlet var createNewPDFBtn: NSButton!
  11. @IBOutlet var btnMerge: NSButton!
  12. @IBOutlet var appendPDFBtn: NSButton!
  13. @IBOutlet var appendTextField: NSTextField!
  14. @IBOutlet var appendOtherPDFBtn: NSButton!
  15. @IBOutlet var appendBackView: NSView!
  16. @IBOutlet var ocrLabel: NSTextField!
  17. @IBOutlet var ocrSelectBtn: NSButton!
  18. @IBOutlet var languaeBox: NSBox!
  19. @IBOutlet var languageButton: NSButton!
  20. @IBOutlet var saveAsButton: NSButton!
  21. @IBOutlet var planButton: NSButton!
  22. @IBOutlet var selectLanguageLabel: NSTextField!
  23. @IBOutlet var planBox: NSBox!
  24. @IBOutlet var actionButton: NSButton!
  25. var password: String = ""
  26. lazy var method: KMImageToPDFMethod = {
  27. let method = KMImageToPDFMethod()
  28. method.imageTopdfDelegate = self
  29. return method
  30. }()
  31. override var interfaceStatus: KMBatchOperateInterfaceStatus?{
  32. set{
  33. super.interfaceStatus = newValue
  34. if newValue == .PrepareProcess {
  35. DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
  36. let files = NSMutableArray()
  37. for url in self.successFilePathURLArray! {
  38. if FileManager.default.fileExists(atPath: url.path) {
  39. files.add(url)
  40. }
  41. }
  42. if files.count > 0 {
  43. let workspace = NSWorkspace.shared
  44. workspace.activateFileViewerSelecting(files as! [URL])
  45. }
  46. }
  47. self._updateActionButtonEnable(true)
  48. } else {
  49. self._updateActionButtonEnable(false)
  50. }
  51. }
  52. get{
  53. return super.interfaceStatus
  54. }
  55. }
  56. private func _updateActionButtonEnable(_ enabled: Bool) {
  57. if enabled {
  58. self.actionButton.tag = 1
  59. self.actionButton.title = NSLocalizedString("Save as PDF", comment: "")
  60. self.actionButton.setTitleColor(KMAppearance.Layout.w0Color())
  61. self.actionButton.isEnabled = true
  62. self.actionButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
  63. } else {
  64. self.actionButton.tag = 0
  65. self.actionButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
  66. self.actionButton.setTitleColor(KMAppearance.Layout.w0Color())
  67. self.actionButton.isEnabled = false
  68. }
  69. }
  70. deinit {
  71. NotificationCenter.default.removeObserver(self)
  72. DistributedNotificationCenter.default().removeObserver(self)
  73. }
  74. override func viewDidLoad() {
  75. super.viewDidLoad()
  76. self.localizedLanguage()
  77. self.configuUI()
  78. if let cnt = self.files?.count, cnt > 0 {
  79. self._updateActionButtonEnable(true)
  80. } else {
  81. self._updateActionButtonEnable(false)
  82. }
  83. NotificationCenter.default.addObserver(self, selector: #selector(OCRSelectedLanguagesChangeNotification(notification:)), name: NSNotification.Name("KMOCRSelectedLanguagesChangeNotification"), object: nil)
  84. NotificationCenter.default.addObserver(self, selector: #selector(OCRSelectedPlanChangeNotification(notification:)), name: NSNotification.Name("KMOCRSelectedPlanChangeNotification"), object: nil)
  85. // NotificationCenter.default.addObserver(self, selector: #selector(themeChanged(notification:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
  86. DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChanged(notification:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
  87. NotificationCenter.default.addObserver(self, selector: #selector(batchFilesCountNotification(notification:)), name: NSNotification.Name("KMBatchFilesCountNotification"), object: nil)
  88. }
  89. func localizedLanguage() {
  90. self.outputTypeLabel.stringValue = KMLocalizedString("Output",nil)
  91. self.btnMerge.title = KMLocalizedString("Merge All", nil)
  92. self.createNewPDFBtn.title = KMLocalizedString("New PDF Document", nil)
  93. self.appendPDFBtn.title = KMLocalizedString("Append To Existing File", nil)
  94. self.appendTextField.placeholderString = KMLocalizedString("Select a File", nil)
  95. self.selectLanguageLabel.stringValue = KMLocalizedString("Select OCR Language:",nil)
  96. self.ocrSelectBtn.title = KMLocalizedString("OCR Plan",nil)
  97. self.updateLanguageButton((KMGOCRManager.default().selectedLanguages?.value(forKeyPath: KMGOCRLanguageStringKey) as? [String]))
  98. self.actionButton.title = KMLocalizedString("Save as PDF", nil)
  99. self.saveAsButton.title = KMLocalizedString("Save as TXT", nil)
  100. self.OCRSelectedPlanChangeAction()
  101. }
  102. func configuUI() {
  103. self.view.wantsLayer = true
  104. appendOtherPDFBtn.wantsLayer = true
  105. appendBackView.wantsLayer = true
  106. appendBackView.layer?.borderWidth = 0.5
  107. self.actionButton.wantsLayer = true
  108. self.actionButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
  109. self.appendOtherPDFBtn.layer?.backgroundColor = KMAppearance.Interactive.s0Color().withAlphaComponent(0.4).cgColor
  110. self.actionButton.setTitleColor(KMAppearance.Layout.w0Color())
  111. self.actionButton.layer?.cornerRadius = 1.0
  112. self.createNewPDFBtn.setTitleColor(KMAppearance.Layout.h0Color())
  113. self.btnMerge.setTitleColor(KMAppearance.Layout.h0Color())
  114. self.appendPDFBtn.setTitleColor(KMAppearance.Layout.h0Color())
  115. self.ocrSelectBtn.setTitleColor(KMAppearance.Layout.h0Color())
  116. self.saveAsButton.setTitleColor(KMAppearance.Layout.h0Color())
  117. self.selectLanguageLabel.textColor = KMAppearance.Layout.h0Color()
  118. self.languageButton.isEnabled = false
  119. self.planButton.isEnabled = false
  120. self.saveAsButton.isEnabled = false
  121. appendTextField.backgroundColor = KMAppearance.Layout.l1Color()
  122. planButton.wantsLayer = true
  123. appendTextField.wantsLayer = true
  124. planButton.wantsLayer = true
  125. appendTextField.layer?.cornerRadius = 1.0
  126. languageButton.layer?.backgroundColor = NSColor.clear.cgColor
  127. languaeBox.borderColor = KMAppearance.Interactive.s0Color()
  128. planBox.borderColor = KMAppearance.Interactive.s0Color()
  129. languaeBox.fillColor = KMAppearance.Layout.l1Color()
  130. planBox.fillColor = KMAppearance.Layout.l1Color()
  131. self.updateViewColor()
  132. }
  133. func updateViewColor() {
  134. if KMAppearance.isDarkMode() {
  135. self.view.layer?.backgroundColor = NSColor(red: 0.055, green: 0.067, blue: 0.078, alpha: 1).cgColor
  136. appendBackView.layer?.borderColor = NSColor(red: 86/255.0, green: 88/255.0, blue: 90/255.0, alpha: 1).cgColor
  137. appendBackView.layer?.backgroundColor = NSColor(red: 57/255.0, green: 60/255.0, blue: 62/255.0, alpha: 1).cgColor
  138. } else {
  139. self.view.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  140. appendBackView.layer?.borderColor = NSColor(red: 218/255.0, green: 219/255.0, blue: 222/255.0, alpha: 1).cgColor
  141. appendBackView.layer?.backgroundColor = NSColor.white.cgColor;
  142. }
  143. }
  144. func updateLanguageButton(_ languages: [String]?) {
  145. if languages?.count ?? 0 < 1 {
  146. self.languageButton.title = " " + KMLocalizedString("Auto Detection", nil)
  147. return
  148. }
  149. var languageName: String = ""
  150. if languages?.count ?? 0 > 0 {
  151. for i in 0..<(languages?.count ?? 0) {
  152. let language = languages?[i]
  153. if i == 0 {
  154. languageName = language ?? ""
  155. } else {
  156. languageName = languageName.appendingFormat(",%@", language ?? "")
  157. }
  158. }
  159. } else {
  160. languageName = ""
  161. }
  162. self.languageButton.title = " " + languageName
  163. }
  164. func converArrType(arr: Array<KMBatchOperateFile>, keyString: String) -> [String] {
  165. let newArr = NSMutableArray()
  166. for item in arr {
  167. newArr.add(item.filePath)
  168. }
  169. return newArr as! [String]
  170. }
  171. func isConnectionAvailable() -> Bool {
  172. // var isExistenceNetwork = true
  173. // let reach = Reachability(hostname: "www.apple.com")
  174. // let status: NetworkStatus = NetworkStatus(rawValue: (reach?.currentReachabilityStatus())!.rawValue)
  175. // switch status.rawValue {
  176. // case 0:
  177. // isExistenceNetwork = false
  178. // case 1:
  179. // isExistenceNetwork = true
  180. // case 2:
  181. // isExistenceNetwork = true
  182. // default:
  183. // break
  184. // }
  185. if Reachability.forInternetConnection().currentReachabilityStatus().rawValue == 0 {
  186. return false
  187. }
  188. return true
  189. }
  190. func beginImageToPDF() {
  191. if self.files?.count ?? 0 < 1 {
  192. return
  193. }
  194. let photoArray = converArrType(arr: self.files!, keyString: "")
  195. var path: String = ""
  196. var isMerge = false
  197. var isCreatNewPDF = false
  198. var isOCR = false
  199. if self.ocrSelectBtn.state == .on {
  200. isOCR = true
  201. }
  202. var isSaveAs = false
  203. if self.saveAsButton.state == .on {
  204. isSaveAs = true
  205. }
  206. let plan = UserDefaults.standard.integer(forKey: "KMOCRCurrentPlanKey")
  207. if isOCR && !self.isConnectionAvailable() && plan == 0 {
  208. let alert = NSAlert()
  209. alert.alertStyle = .critical
  210. alert.messageText = NSLocalizedString("Connection Error", comment: "")
  211. alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
  212. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  213. if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  214. alert.beginSheetModal(for: self.view.window!, completionHandler: nil)
  215. } else {
  216. alert.runModal()
  217. }
  218. return
  219. }
  220. if self.createNewPDFBtn.state == .on {
  221. if (self.choosePath.count < 1) {
  222. let alert = NSAlert()
  223. alert.alertStyle = .critical
  224. alert.messageText = String(format: NSLocalizedString("Output Folder cannot be empty.", comment: ""))
  225. alert.runModal()
  226. return
  227. }
  228. path = self.choosePath
  229. if self.btnMerge.state == .on {
  230. isMerge = true
  231. }
  232. isCreatNewPDF = true
  233. } else {
  234. let appenString = self.appendTextField.stringValue
  235. if appenString.isEmpty {
  236. let alert = NSAlert()
  237. alert.alertStyle = .critical
  238. alert.messageText = String(format: NSLocalizedString("Select a File", comment: ""))
  239. alert.runModal()
  240. return
  241. }
  242. path = self.appendTextField.stringValue
  243. isMerge = true
  244. isCreatNewPDF = false
  245. }
  246. self.languageButton.isEnabled = false
  247. self.planButton.isEnabled = false
  248. self.method.password = self.password
  249. self.interfaceStatus = .Processing
  250. self.method.saveAsTestPath = self.choosePath
  251. self.method.exportPDFFile(fileArray: photoArray, savePath: path, isOCR: isOCR, isCreatPDF: isCreatNewPDF, isMerge: isMerge, isSaveAsText: isSaveAs) { [weak self] savePath, errorArr, errorOCRArray in
  252. self?.languageButton.isEnabled = true
  253. self?.planButton.isEnabled = true
  254. self?.interfaceStatus = .PrepareProcess
  255. if errorArr.count > 0 {
  256. let dict: [String: Any] = ["isMerge": false, "isSuccess": false]
  257. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMBatchOperateImageToPDFSuccessNotification"), object: self, userInfo: dict)
  258. let alert = NSAlert()
  259. alert.messageText = NSLocalizedString("Conversion Failed", comment: "")
  260. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  261. alert.informativeText = "\(errorArr)"
  262. alert.alertStyle = .informational
  263. alert.runModal()
  264. } else {
  265. if errorOCRArray.count > 0 {
  266. var contextString = NSLocalizedString("Some problems occurred during the last operation:", comment: "")
  267. for filePath in errorOCRArray {
  268. contextString += "\n" + (filePath as AnyObject).lastPathComponent
  269. }
  270. let alert = NSAlert()
  271. alert.messageText = NSLocalizedString("Converted Successfully", comment: "")
  272. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  273. alert.informativeText = contextString
  274. alert.alertStyle = .informational
  275. let response = alert.runModal()
  276. if response == .OK {
  277. self?.viewFileAtFinder(fileName: savePath)
  278. }
  279. } else {
  280. self?.viewFileAtFinder(fileName: savePath)
  281. }
  282. }
  283. }
  284. }
  285. func viewFileAtFinder(fileName: String) {
  286. let dict = ["isMerge": true, "isSuccess": true]
  287. NotificationCenter.default.post(name: Notification.Name("KMBatchOperateImageToPDFSuccessNotification"), object: self, userInfo: dict)
  288. let workspace = NSWorkspace.shared
  289. let url = URL(fileURLWithPath: fileName)
  290. workspace.activateFileViewerSelecting([url])
  291. }
  292. //MARK: Notification
  293. @objc func OCRSelectedLanguagesChangeNotification(notification: Notification) {
  294. let selectedLanguages = notification.object/* as? [KMBatchOperateFile]*/
  295. self.updateLanguageButton(selectedLanguages as? [String])
  296. }
  297. @objc func OCRSelectedPlanChangeNotification(notification: Notification) {
  298. self.OCRSelectedPlanChangeAction()
  299. }
  300. @objc func themeChanged(notification: Notification) {
  301. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  302. self.updateViewColor()
  303. }
  304. }
  305. func OCRSelectedPlanChangeAction() {
  306. let plan = UserDefaults.standard.integer(forKey: "KMOCRCurrentPlanKey")
  307. if plan == 0 {
  308. self.planButton.title = " " + KMLocalizedString("Plan 1 (Online)", nil)
  309. } else {
  310. self.planButton.title = " " + KMLocalizedString("Plan 2 (Offline)", nil)
  311. }
  312. KMGOCRManager.default().selectedLanguages = NSMutableArray()
  313. self.updateLanguageButton(KMGOCRManager.default().selectedLanguages?.value(forKeyPath: KMGOCRLanguageStringKey) as? [String])
  314. }
  315. @objc func batchFilesCountNotification(notification: Notification) {
  316. let files: Array? = notification.object as? [KMBatchOperateFile]
  317. self.files? = files ?? []
  318. let cnt = self.files?.count ?? 0
  319. if cnt > 0 {
  320. self._updateActionButtonEnable(true)
  321. } else {
  322. self._updateActionButtonEnable(false)
  323. }
  324. }
  325. @IBAction func buttonClicked_CreateNewPDF(_ sender: NSButton) {
  326. if (sender.state == .on) {
  327. self.btnMerge.isEnabled = true
  328. self.appendPDFBtn.state = .off
  329. self.appendOtherPDFBtn.isEnabled = false
  330. }
  331. }
  332. @IBAction func buttonClicked_AppendOtherPDF(_ sender: NSButton) {
  333. if (sender.state == .on) {
  334. self.createNewPDFBtn.state = .off
  335. self.btnMerge.isEnabled = false
  336. self.appendOtherPDFBtn.isEnabled = true
  337. }
  338. }
  339. @IBAction func buttonClicked_OCRSelect(_ sender: NSButton) {
  340. //MARK: 判断是否付费用户
  341. if IAPProductsManager.default().isAvailableAllFunction() == false {
  342. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  343. self.ocrSelectBtn.state = .off
  344. return
  345. }
  346. if (sender.state == .on) {
  347. self.languageButton.isEnabled = true
  348. self.planButton.isEnabled = true
  349. self.saveAsButton.isEnabled = true
  350. } else {
  351. self.languageButton.isEnabled = false
  352. self.planButton.isEnabled = false
  353. self.saveAsButton.isEnabled = false
  354. }
  355. }
  356. @IBAction func buttonClicked_ChooseLanguage(_ sender: NSButton) {
  357. let plan = UserDefaults.standard.integer(forKey: "KMOCRCurrentPlanKey")
  358. if plan == 0 {
  359. KMGOCRManager.default().ocrType = .google
  360. } else {
  361. KMGOCRManager.default().ocrType = .apple
  362. }
  363. let popover = NSPopover()
  364. popover.delegate = self
  365. popover.contentViewController = KMLanguageViewController(nibName: "KMLanguageViewController", bundle: Bundle.main)
  366. popover.animates = true
  367. popover.behavior = .transient
  368. popover.show(relativeTo: sender.bounds, of: sender as NSView, preferredEdge: .minX)
  369. }
  370. @IBAction func buttonClicked_ChoosePlan(_ sender: NSButton) {
  371. let popover = NSPopover()
  372. popover.delegate = self
  373. popover.contentViewController = KMPlanViewController(nibName: "KMPlanViewController", bundle: Bundle.main)
  374. popover.animates = true
  375. popover.behavior = .transient
  376. popover.show(relativeTo: sender.bounds, of: sender as NSView, preferredEdge: .minX)
  377. }
  378. @IBAction func buttonClicked_ImageToPDF(_ sender: NSButton) {
  379. //MARK: 判断是否付费用户,展示iap界面
  380. if self.files?.count ?? 0 < 1 {
  381. return
  382. }
  383. if IAPProductsManager.default().isAvailableAllFunction() == false && self.files?.count ?? 0 > 1{
  384. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  385. return
  386. }
  387. if sender.tag == 1 {
  388. self.choosePath = ""
  389. var hasTask = false
  390. for i in 0..<(self.files?.count ?? 0) {
  391. let file = self.files?[i]
  392. file?.currentOperateInfo?.resetState()
  393. if file?.fileType == .Image {
  394. hasTask = true
  395. }
  396. }
  397. if !hasTask {
  398. NSSound.beep()
  399. return
  400. }
  401. var isOCR = false
  402. if self.ocrSelectBtn.state == .on {
  403. isOCR = true
  404. }
  405. var isSaveAs = false
  406. if self.saveAsButton.state == .on {
  407. isSaveAs = true
  408. }
  409. let plan = UserDefaults.standard.integer(forKey: "KMOCRCurrentPlanKey")
  410. if isOCR && !isConnectionAvailable() && plan == 0 {
  411. let alert = NSAlert()
  412. alert.alertStyle = .critical
  413. alert.messageText = NSLocalizedString("Connection Error", comment: "")
  414. alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
  415. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  416. if let window = self.view.window {
  417. alert.beginSheetModal(for: window, completionHandler: nil)
  418. } else {
  419. alert.runModal()
  420. }
  421. return
  422. }
  423. if self.createNewPDFBtn.state == .off {
  424. let appenString = self.appendTextField.stringValue
  425. if appenString.isEmpty {
  426. let alert = NSAlert()
  427. alert.alertStyle = .critical
  428. alert.messageText = NSLocalizedString("Select a File", comment: "")
  429. alert.runModal()
  430. return
  431. }
  432. }
  433. let openPanel = NSOpenPanel()
  434. openPanel.canChooseFiles = false
  435. openPanel.canChooseDirectories = true
  436. openPanel.canCreateDirectories = true
  437. openPanel.beginSheetModal(for: self.view.window!) { (result) in
  438. if result == .OK {
  439. for fileURL in openPanel.urls {
  440. self.choosePath = fileURL.path
  441. self.beginImageToPDF()
  442. }
  443. }
  444. }
  445. } else { // Do something else }
  446. }
  447. }
  448. @IBAction func buttonItemClicked_AppendOtherPDF(_ sender: NSButton) {
  449. let openPanel = NSOpenPanel()
  450. openPanel.allowedFileTypes = ["pdf"]
  451. openPanel.canChooseDirectories = false
  452. openPanel.allowsMultipleSelection = false
  453. openPanel.beginSheetModal(for: self.view.window!) { (result) in
  454. if result == .OK {
  455. guard let url = openPanel.url else { return }
  456. guard let document = PDFDocument(url: url) else {
  457. let alert = NSAlert()
  458. alert.alertStyle = .critical
  459. alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
  460. alert.runModal()
  461. return
  462. }
  463. if !document.allowsCopying || !document.allowsPrinting {
  464. let alert = NSAlert()
  465. alert.alertStyle = .critical
  466. alert.messageText = NSLocalizedString("This is a secured document. Editing is not permitted.", comment: "")
  467. alert.runModal()
  468. return
  469. }
  470. if document.isLocked {
  471. KMBaseWindowController.checkPassword(url: url, type: .owner) { [weak self] success, resultPassword in
  472. if success {
  473. self?.password = resultPassword
  474. self?.appendTextField.stringValue = url.path
  475. }
  476. }
  477. } else {
  478. self.appendTextField.stringValue = url.path
  479. }
  480. }
  481. }
  482. }
  483. @IBAction func buttonClicked_Help(_ sender: NSButton) {
  484. let helpController = NSViewController()
  485. let textView = NSTextView(frame: NSRect(x: 0, y: 0, width: 300.0, height: 100.0))
  486. textView.backgroundColor = NSColor.clear
  487. textView.isEditable = false
  488. textView.layer?.cornerRadius = 6
  489. let tStrAuto = NSLocalizedString("Choose automatic language detection for better OCR results.", comment: "")
  490. let tStrVPN = NSLocalizedString("The OCR service works via an internet connection. We would suggest you to perform OCR using a VPN connection while the service is limited.", comment: "")
  491. let plan = UserDefaults.standard.integer(forKey: "KMOCRCurrentPlanKey")
  492. if plan == 0 {
  493. textView.string = "\(tStrAuto)\n\n\(tStrVPN)"
  494. } else {
  495. textView.frame = NSRect(x: 0, y: 0, width: 300.0, height: 40.0)
  496. textView.string = tStrAuto
  497. }
  498. helpController.view = textView
  499. let popover = NSPopover()
  500. popover.delegate = self
  501. popover.contentViewController = helpController
  502. popover.animates = true
  503. popover.behavior = .transient
  504. popover.show(relativeTo: sender.bounds, of: sender as NSView, preferredEdge: .minY)
  505. }
  506. //MARK: KMImageToPDFMethodDelegate
  507. func imageToPDFMethod(_ method: KMImageToPDFMethod, progress: Float) {
  508. }
  509. }