KMOCRWindowController.swift 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // KMOCRWindowController.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2022/12/7.
  6. //
  7. import Cocoa
  8. class KMOCRWindowController: NSWindowController {
  9. @IBOutlet weak var batchPrecessingView: KMBatchProcessingView!
  10. @IBOutlet weak var chooseView: KMOCRChooseView!
  11. var chooseData: KMImageToPDFChooseModel?
  12. var batchData: [KMBatchProcessingTableViewModel]?
  13. var inputType: DataNavigationViewButtonActionType?
  14. deinit {
  15. KMPrint("KMOCRWindowController 释放")
  16. }
  17. override func windowDidLoad() {
  18. super.windowDidLoad()
  19. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  20. self.window?.title = "批量OCR"
  21. self.setup()
  22. self.reloadData()
  23. }
  24. func setup() {
  25. self.batchPrecessingView.delegate = self
  26. self.batchPrecessingView.inputType = self.inputType
  27. self.chooseView.delegate = self
  28. }
  29. func reloadData() {
  30. }
  31. //MARK: 打开文件
  32. static func openFiles(window:NSWindow) {
  33. KMBatchProcessingView.openfiles(window: window) { openPanel in
  34. openPanel.title = "选择图片"
  35. openPanel.canChooseDirectories = false
  36. openPanel.canChooseFiles = true
  37. openPanel.allowsMultipleSelection = true
  38. openPanel.allowedFileTypes = ["pdf"]
  39. } completion: {(panel ,data) in
  40. if data.count != 0 {
  41. let imageToPDFWindow: KMOCRWindowController = KMOCRWindowController.init(windowNibName: "KMOCRWindowController")
  42. imageToPDFWindow.showWindow(window)
  43. imageToPDFWindow.batchPrecessingView.inputData = data
  44. imageToPDFWindow.inputType = .OCR
  45. }
  46. }
  47. }
  48. }
  49. extension KMOCRWindowController: KMImageToPDFChooseViewDelegate {
  50. func exportAction(data: KMImageToPDFChooseModel) {
  51. KMPrint("导出")
  52. self.chooseData = data
  53. if self.batchData != nil {
  54. self.chooseData?.imageFilePaths = self.batchData
  55. KMImageToPDFManager.manager.exportPDF(model: self.chooseData!) { success, savePath, errors, OCRerrors in
  56. KMPrint(success)
  57. if success {
  58. NSWorkspace.shared.selectFile(savePath, inFileViewerRootedAtPath: "");
  59. } else {
  60. let alert = NSAlert()
  61. alert.alertStyle = .critical
  62. alert.messageText = NSLocalizedString("导出失败", comment: "")
  63. alert.runModal()
  64. return
  65. }
  66. } progress: { status in
  67. }
  68. }
  69. }
  70. }
  71. extension KMOCRWindowController: KMOCRChooseViewDelegate {
  72. func exportAction(data: KMOCRModel) {
  73. KMPrint("export ocr success")
  74. }
  75. }
  76. extension KMOCRWindowController: KMBatchProcessingViewDelegate {
  77. func reloadData(data: [KMBatchProcessingTableViewModel]) {
  78. self.batchData = data
  79. }
  80. }