123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- //
- // KMOCRWindowController.swift
- // PDF Master
- //
- // Created by lizhe on 2022/12/7.
- //
- import Cocoa
- class KMOCRWindowController: NSWindowController {
- @IBOutlet weak var batchPrecessingView: KMBatchProcessingView!
- @IBOutlet weak var chooseView: KMOCRChooseView!
- var chooseData: KMImageToPDFChooseModel?
- var batchData: [KMBatchProcessingTableViewModel]?
- var inputType: DataNavigationViewButtonActionType?
-
- deinit {
- KMPrint("KMOCRWindowController 释放")
- }
-
- override func windowDidLoad() {
- super.windowDidLoad()
- // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
- self.window?.title = "批量OCR"
- self.setup()
- self.reloadData()
- }
-
- func setup() {
-
- self.batchPrecessingView.delegate = self
- self.batchPrecessingView.inputType = self.inputType
- self.chooseView.delegate = self
- }
-
- func reloadData() {
-
- }
-
- //MARK: 打开文件
- static func openFiles(window:NSWindow) {
- KMBatchProcessingView.openfiles(window: window) { openPanel in
- openPanel.title = "选择图片"
- openPanel.canChooseDirectories = false
- openPanel.canChooseFiles = true
- openPanel.allowsMultipleSelection = true
- openPanel.allowedFileTypes = ["pdf"]
- } completion: {(panel ,data) in
- if data.count != 0 {
- let imageToPDFWindow: KMOCRWindowController = KMOCRWindowController.init(windowNibName: "KMOCRWindowController")
- imageToPDFWindow.showWindow(window)
- imageToPDFWindow.batchPrecessingView.inputData = data
- imageToPDFWindow.inputType = .OCR
- }
- }
- }
- }
- extension KMOCRWindowController: KMImageToPDFChooseViewDelegate {
- func exportAction(data: KMImageToPDFChooseModel) {
- KMPrint("导出")
- self.chooseData = data
- if self.batchData != nil {
- self.chooseData?.imageFilePaths = self.batchData
- KMImageToPDFManager.manager.exportPDF(model: self.chooseData!) { success, savePath, errors, OCRerrors in
- KMPrint(success)
- if success {
- NSWorkspace.shared.selectFile(savePath, inFileViewerRootedAtPath: "");
- } else {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = NSLocalizedString("导出失败", comment: "")
- alert.runModal()
- return
- }
- } progress: { status in
-
- }
- }
- }
- }
- extension KMOCRWindowController: KMOCRChooseViewDelegate {
- func exportAction(data: KMOCRModel) {
- KMPrint("export ocr success")
- }
- }
- extension KMOCRWindowController: KMBatchProcessingViewDelegate {
- func reloadData(data: [KMBatchProcessingTableViewModel]) {
- self.batchData = data
-
- }
-
- }
|