123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969 |
- //
- // KMBatchOperateConvertViewController.swift
- // PDF Reader Pro
- //
- // Created by kdanmobile on 2023/11/1.
- //
- import Cocoa
- typealias detailInfoViewMouseDownCallback = (_ mouseDown: Bool) -> ()
- class KMDetailInfoView: NSView{
- var mouseDownCallback: detailInfoViewMouseDownCallback?
- override func mouseDown(with event: NSEvent) {
- super.mouseDown(with: event)
- guard let callBack = mouseDownCallback else { return }
- callBack(true)
- }
- }
- class KMBatchOperateConvertViewController: KMBatchOperateBaseViewController{
- var dataSourcesArray: [KMConvertWithPDFType]?
- @IBOutlet var bottomView: NSView!
-
- @IBOutlet var convertButton: NSButton!
-
- @IBOutlet var buttonBottemOffset: NSLayoutConstraint!
- @IBOutlet var detailInfoLabel: NSTextField!
- @IBOutlet var detailInfoBox: NSBox!
-
- @IBOutlet var separateStypeTopOffset: NSLayoutConstraint!
-
- @IBOutlet var separateStypeBox: NSBox!
- @IBOutlet var wordButtonOne: NSButton!
- @IBOutlet var wordButtonTwo: NSButton!
-
- @IBOutlet var excelStyleBox: NSBox!
- @IBOutlet var allContentMenu: NSPopUpButton!
- @IBOutlet var allContentMenu2: NSMenuItem!
- @IBOutlet var allContentMenu3: NSMenuItem!
- @IBOutlet var onlyTextBtn: NSButton!
- @IBOutlet var onlyTableBtn: NSButton!
- @IBOutlet var allContentBtn: NSButton!
- @IBOutlet var tableMenu1: NSMenuItem!
- @IBOutlet var tableMenu2: NSMenuItem!
- @IBOutlet var tableMenu3: NSMenuItem!
- @IBOutlet var tableMenu: NSPopUpButton!
-
- @IBOutlet var csvExtractButton: NSButton!
-
- @IBOutlet var ocrBox: NSBox!
- @IBOutlet var ocrLabel: NSTextField!
- @IBOutlet var ocrButton: NSButton!
- @IBOutlet var ocrLanguageBox: NSPopUpButton!
- @IBOutlet var ocrTopOffset: NSLayoutConstraint!
- @IBOutlet var headerView: KMConvertCollectionViewHeader!
- @IBOutlet var headerTopOffset: NSLayoutConstraint!
- @IBOutlet var formatLabel: NSTextField!
- @IBOutlet var formatSelectButton: NSPopUpButton!
-
- var excelContentOption: CPDFConvertExcelContentOptions?
- var excelWorksheetOption: CPDFConvertExcelWorksheetOptions?
- var haveFiles: Bool = false
-
- private var ocrLanguage_: COCRLanguage = .english
-
- deinit {
- NotificationCenter.default.removeObserver(self)
- }
- override var interfaceStatus: KMBatchOperateInterfaceStatus?{
- set{
- super.interfaceStatus = newValue
- self.convertButton.isEnabled = true
- if newValue == .Processing {
- formatSelectButton.isEnabled = false
- self.convertButton.title = NSLocalizedString("Cancel", comment: "")
- self.convertButton.tag = 2
- self.convertButton.setTitleColor(KMAppearance.Layout.w0Color())
- self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
- if self.convertType == .WordStandard {
- self.convertButton.title = NSLocalizedString("Convert", comment: "")
- self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().withAlphaComponent(0.4).cgColor
- self.convertButton.isEnabled = false
- }
- } else {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
- var files: [URL] = []
- for url in self.successFilePathURLArray! {
- if FileManager.default.fileExists(atPath: url.path) {
- files.append(url)
- }
- }
- if files.count > 0 {
- let workspace = NSWorkspace.shared
- workspace.activateFileViewerSelecting(files)
- }
- }
- formatSelectButton.isEnabled = true
- self.convertButton.title = NSLocalizedString("Convert", comment: "")
- self.convertButton.tag = 1
- self.convertButton.setTitleColor(KMAppearance.Layout.w0Color())
- self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
- }
- }
- get{
- return super.interfaceStatus
- }
- }
- override var convertType: KMConvertWithPDFType?{
- set{
- super.convertType = newValue
- changeAllFilesToConvertType(convertType!)
- fetchFileListViewController()?.reloadConvertInterface(withType: convertType!)
- }
- get{
- return super.convertType
- }
- }
- func changeAllFilesToConvertType(_ type: KMConvertWithPDFType) {
- for i in 0..<self.files!.count {
- let file = self.files![i]
- file.convertType = type
- }
- }
-
- func switchToConvertType(_ convertType: KMConvertWithPDFType) {
- self.convertType = convertType
- self.manualSelectRow(convertType)
- self.updateBottomView()
- }
-
- func manualSelectRow(_ convertType: KMConvertWithPDFType) {
- var index = -1
- updateFormatView()
- for i in 0..<self.dataSourcesArray!.count {
- let number = self.dataSourcesArray![i]
- if number.rawValue == convertType.rawValue {
- index = i
- break
- }
- }
- if index != -1 {
- self.formatSelectButton.selectItem(at: index)
- }
- }
-
- func updateBottomView() {
- var isShowUpgrade = false
-
- #if VERSION_FREE
- #if VERSION_DMG
- // 桌机版
- if KMMemberInfo.shared.isMemberAllFunction {
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- } else {
- isShowUpgrade = true
- }
- } else {
- isShowUpgrade = true
- }
- #else
- // 免费版
- if KMMemberInfo.shared.isMemberAllFunction {
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- } else {
- isShowUpgrade = true
- }
- } else {
- isShowUpgrade = true
- }
-
- #endif
- #else
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- } else {
- isShowUpgrade = true
- }
- #endif
- // if !isShowUpgrade {
- // headerView.isHidden = true
- // headerTopOffset.constant = 0
- // } else {
- // headerView.isHidden = false
- // headerTopOffset.constant = self.headerView.frame.height
- // }
- var moreLabelString = ""
- #if VERSION_FREE
- if !KMMemberInfo.shared.isMemberAllFunction {
- moreLabelString = String(format: "%@ %@", KMLocalizedString("The first 10 pages for free"), KMLocalizedString("Unlimited Convert"))
- } else {
- if !IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- if .WordAdvance == self.convertType ||
- .WordStandard == self.convertType ||
- .Excel == self.convertType ||
- .PowerPoint == self.convertType ||
- .CSV == self.convertType ||
- .RTF == self.convertType ||
- .GIF == self.convertType ||
- .TIFF == self.convertType ||
- .JPEG2000 == self.convertType ||
- .BMP == self.convertType ||
- .TGA == self.convertType ||
- .Json == self.convertType {
- moreLabelString = String(format: "%@ %@", KMLocalizedString("The first 10 pages for free"), KMLocalizedString("Unlimited Convert"))
- }
- }
- }
- #else
- // 付费版
- if !IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- if .WordAdvance == self.convertType ||
- .WordStandard == self.convertType ||
- .Excel == self.convertType ||
- .PowerPoint == self.convertType ||
- .CSV == self.convertType ||
- .RTF == self.convertType ||
- .GIF == self.convertType ||
- .TIFF == self.convertType ||
- .JPEG2000 == self.convertType ||
- .BMP == self.convertType ||
- .TGA == self.convertType ||
- .Json == self.convertType {
- moreLabelString = String(format: "%@ %@", KMLocalizedString("The first 10 pages for free"), KMLocalizedString("Unlimited Convert"))
- }
- }
- #endif
-
- self.detailInfoLabel.stringValue = moreLabelString
- if let range = moreLabelString.range(of: NSLocalizedString("Unlimited Convert", comment: "")) {
- let newR: NSRange = moreLabelString.nsRange(from: range)!
- let attributedStr = NSMutableAttributedString(string: moreLabelString)
- attributedStr.addAttribute(.foregroundColor, value: NSColor.labelColor, range: NSRange(location: 0, length: newR.location - 1))
- attributedStr.addAttribute(.foregroundColor, value: NSColor(red: 8/255, green: 124/255, blue: 1, alpha: 1), range: newR)
- attributedStr.addAttribute(.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: newR)
- detailInfoLabel.attributedStringValue = attributedStr
- }
-
- if moreLabelString.count > 0 {
- detailInfoBox.isHidden = false
- buttonBottemOffset.constant = 45
- } else {
- detailInfoBox.isHidden = true
- buttonBottemOffset.constant = 10
- }
-
- if self.convertType == .WordAdvance {
- separateStypeBox.isHidden = false
- excelStyleBox.isHidden = true
- csvExtractButton.isHidden = true
- ocrBox.isHidden = false
- wordButtonOne.title = NSLocalizedString("Retain Flowing Text", comment: "")
- wordButtonTwo.title = NSLocalizedString("Retain Page Layout", comment: "")
-
- ocrTopOffset.constant = 15 + separateStypeBox.frame.height
- } else if self.convertType == .Excel {
- separateStypeBox.isHidden = true
- excelStyleBox.isHidden = false
- csvExtractButton.isHidden = true
- ocrBox.isHidden = false
-
- ocrTopOffset.constant = 15 + excelStyleBox.frame.height
- } else if .Json == convertType {
- wordButtonOne.title = NSLocalizedString("Extract text content", comment: "")
- wordButtonTwo.title = NSLocalizedString("Extract tables", comment: "")
-
- separateStypeBox.isHidden = false
- excelStyleBox.isHidden = true
- csvExtractButton.isHidden = true
- ocrBox.isHidden = false
-
- ocrTopOffset.constant = 15 + separateStypeBox.frame.height
- } else if (.PowerPoint == convertType ||
- .RTF == convertType ||
- .HTML == convertType ||
- .Text == convertType) {
-
- separateStypeBox.isHidden = true
- excelStyleBox.isHidden = true
- csvExtractButton.isHidden = true
- ocrBox.isHidden = false
- ocrTopOffset.constant = 15
- } else if self.convertType == .CSV {
- separateStypeBox.isHidden = true
- excelStyleBox.isHidden = true
- csvExtractButton.isHidden = false
- ocrBox.isHidden = true
-
- self.csvExtractButton.title = NSLocalizedString("Extract Tables Only", comment: "")
- } else {
- separateStypeBox.isHidden = true
- excelStyleBox.isHidden = true
- csvExtractButton.isHidden = true
- ocrBox.isHidden = true
- }
-
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- self.prepareData()
- updateFormatView()
- self.view.wantsLayer = true
- convertButton.wantsLayer = true
- convertButton.font = NSFont.systemFont(ofSize: 13)
- convertButton.layer?.cornerRadius = 1.0
- interfaceStatus = .PrepareProcess
-
- allContentBtn.state = .on
- allContentMenu.isEnabled = true
- tableMenu.isEnabled = false
- excelContentOption = .allContent
- excelWorksheetOption = .forEachPage
-
- onlyTextBtn.title = NSLocalizedString("Only Text", comment: "")
- onlyTableBtn.title = NSLocalizedString("Only Table", comment: "")
- allContentBtn.title = NSLocalizedString("All Content", comment: "")
- onlyTextBtn.toolTip = NSLocalizedString("Only Text", comment: "")
- onlyTableBtn.toolTip = NSLocalizedString("Only Table", comment: "")
- allContentBtn.toolTip = NSLocalizedString("All Content", comment: "")
- tableMenu1.title = NSLocalizedString("Create Sheet for each Table", comment: "")
- tableMenu2.title = NSLocalizedString("Create Sheet for each Page", comment: "")
- allContentMenu2.title = NSLocalizedString("Create Sheet for each Page", comment: "")
- tableMenu3.title = NSLocalizedString("Create single Sheet for File", comment: "")
- allContentMenu3.title = NSLocalizedString("Create single Sheet for File", comment: "")
- formatLabel.stringValue = KMLocalizedString("Format:", nil)
- ocrBox.title = KMLocalizedString("OCR Settings", nil)
- ocrBox.titleFont = .SFProTextBoldFont(14.0)
- formatLabel.font = .SFProTextBoldFont(14.0)
-
- headerView.convertHeaderClickedCallBack = { [weak self] in
- self?.moreConvertInfoAction()
- }
-
- self.ocrButton.title = NSLocalizedString("Recognize text", comment: "")
- self.ocrLabel.stringValue = NSLocalizedString("Language Option", comment: "") + ":"
- ocrLanguageBox.selectItem(at: 2)
- ocrLabel.textColor = KMAppearance.Layout.h2Color()
- ocrLanguageBox.isEnabled = false
- ocrButton.state = .off
-
- self.updateViewColor()
-
- NotificationCenter.default.addObserver(self, selector: #selector(batchFilesCountNotification(notification:)), name: Notification.Name(rawValue: "KMBatchFilesCountNotification"), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(IAPProductPurchasedNotification(notification:)), name: NSNotification.Name("KMIAPProductPurchasedNotification"), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFinishedNotification(notification:)), name: NSNotification.Name("KMIAPProductRestoreFinishedNotification"), object: nil)
- // NotificationCenter.default.addObserver(self, selector: #selector(themeChanged(notification:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
- DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChanged(notification:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(deviceActivateStatusChanged(notification:)), name: NSNotification.Name("kDeviceActivateNotification"), object: nil)
- }
-
-
- @objc func batchFilesCountNotification(notification: NSNotification) {
- let arr: Array? = notification.object as? [KMBatchOperateFile]
- self.files? = arr ?? []
- if files!.count > 0 {
- self.convertButton.setTitleColor(NSColor.white)
- self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
- self.haveFiles = true
- } else {
- self.convertButton.setTitleColor(KMAppearance.Layout.w0Color().withAlphaComponent(0.6))
- self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().withAlphaComponent(0.4).cgColor
- self.haveFiles = false
- }
- }
-
- @objc func themeChanged(notification: NSNotification) {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
- self.updateViewColor()
- }
- }
-
- @objc func IAPProductRestoreFinishedNotification(notification: NSNotification) {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
- self.updateBottomView()
- self.prepareData()
- self.updateFormatView()
- }
- }
-
- @objc func IAPProductPurchasedNotification(notification: NSNotification) {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
- self.updateBottomView()
- self.prepareData()
- self.updateFormatView()
- }
- }
-
- @objc func deviceActivateStatusChanged(notification: NSNotification) {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
- self.updateBottomView()
- self.prepareData()
- self.updateFormatView()
- }
- }
-
- func updateViewColor() {
- self.view.wantsLayer = true
- if KMAppearance.isDarkMode() {
- self.view.layer?.backgroundColor = NSColor(red: 0.055, green: 0.067, blue: 0.078, alpha: 1).cgColor
- } else {
- self.view.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
- }
- }
-
- func convertActionVC() {
- var vc: KMToolCompareWindowController? = nil
- if(.WordStandard == self.convertType ||
- .WordAdvance == self.convertType) {
- vc = KMToolCompareWindowController(toolType: .Convert, selectNum: 1)
- } else if (.Excel == self.convertType) {
- vc = KMToolCompareWindowController(toolType: .Convert, selectNum: 2)
- } else if (.PowerPoint == self.convertType) {
- vc = KMToolCompareWindowController(toolType: .Convert, selectNum: 3)
- } else if (self.convertType == .JPG || self.convertType == .PNG || self.convertType == .GIF || self.convertType == .TIFF || self.convertType == .TGA || self.convertType == .BMP){
- vc = KMToolCompareWindowController(toolType: .Convert, selectNum: 4)
- } else {
- vc = KMToolCompareWindowController(toolType: .Convert, selectNum: 0)
- }
- vc?.showWindow(nil)
- }
-
- func prepareData() {
- let arr: [KMConvertWithPDFType] = [.Excel, .PowerPoint, .RTF, .CSV, .HTML, .Text, .JPEG, .JPG, .PNG, .GIF, .TIFF, .TGA, .BMP, .JPEG2000, .Json]
- self.dataSourcesArray = arr
-
- var needShowAdvance = true
- var needShowDefault = true
-
- #if VERSION_FREE
- // 桌机版
- if KMMemberInfo.shared.isMemberAllFunction {
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- needShowAdvance = true
- needShowDefault = false
- }
- }
- #else
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- needShowAdvance = true
- needShowDefault = false
- }
- #endif
-
- if needShowDefault {
- var wordType: KMConvertWithPDFType = .WordStandard
- self.dataSourcesArray?.insert(wordType, at: 0)
- }
-
- if needShowAdvance {
- var wordType: KMConvertWithPDFType = .WordAdvance
- self.dataSourcesArray?.insert(wordType, at: 0)
- }
- }
-
- func updateFormatView() {
- var isShowAdvanced = false
-
- #if VERSION_FREE
- #if VERSION_DMG
- // 桌机版
- isShowAdvanced = true
- if KMMemberInfo.shared.isMemberAllFunction {
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- isShowAdvanced = false
- }
- }
- #else
- // 免费版
- isShowAdvanced = true
- if KMMemberInfo.shared.isMemberAllFunction {
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- isShowAdvanced = false
- }
- }
-
- #endif
- #else
- isShowAdvanced = true
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- isShowAdvanced = false
- }
- #endif
- self.formatSelectButton.removeAllItems()
- for i in 0..<self.dataSourcesArray!.count {
- let number = self.dataSourcesArray![i]
- let item = NSMenuItem()
- item.target = self
-
- if(number == .WordAdvance) {
- if isShowAdvanced {
- let originStr = " \(NSLocalizedString("Advanced", comment: "")) "
- let str = NSLocalizedString("Word (.docx)", comment: "")
-
- let attributedStr = NSMutableAttributedString(string: "\(str) \(originStr)")
-
- attributedStr.addAttribute(NSAttributedString.Key.backgroundColor, value: NSColor(red: 245.0/255.0, green: 142.0/255.0, blue: 38.0/255.0, alpha: 1.0), range: NSMakeRange(str.count + 2, originStr.count))
-
- attributedStr.addAttribute(NSAttributedString.Key.foregroundColor, value: NSColor.white, range: NSMakeRange(str.count + 2, originStr.count))
-
- item.attributedTitle = attributedStr
- } else {
- item.title = "Word (.docx)"
- }
- item.tag = KMConvertWithPDFType.WordAdvance.rawValue
- } else if(number == .WordStandard) {
- if isShowAdvanced {
- let originStr = " \(KMLocalizedString("Standard", nil)) "
- let str = KMLocalizedString("Word (.docx)", nil)
-
- let attributedStr = NSMutableAttributedString(string: "\(str) \(originStr)")
-
- attributedStr.addAttribute(NSAttributedString.Key.backgroundColor, value: NSColor(red: 40/255.0, green: 193.0/255.0, blue: 107.0/255.0, alpha: 1.0), range: NSMakeRange(str.count + 2, originStr.count))
-
- attributedStr.addAttribute(NSAttributedString.Key.foregroundColor, value: NSColor.white, range: NSMakeRange(str.count + 2, originStr.count))
-
- item.attributedTitle = attributedStr
- } else {
- item.title = "Word (.docx)"
- }
- item.tag = KMConvertWithPDFType.WordStandard.rawValue
- } else if(number == .Excel) {
- item.title = "Excel (.xlsx)"
- item.tag = KMConvertWithPDFType.Excel.rawValue
- } else if(number == .PowerPoint) {
- item.title = "PowerPoint (.pptx)"
- item.tag = KMConvertWithPDFType.PowerPoint.rawValue
- } else if(number == .RTF) {
- item.title = "RTF (.rtf)"
- item.tag = KMConvertWithPDFType.RTF.rawValue
- } else if(number == .CSV) {
- item.title = "CSV (.csv)"
- item.tag = KMConvertWithPDFType.CSV.rawValue
- } else if(number == .HTML) {
- item.title = "Html (.html)"
- item.tag = KMConvertWithPDFType.HTML.rawValue
- } else if(number == .Text) {
- item.title = "Text (.txt)"
- item.tag = KMConvertWithPDFType.Text.rawValue
- } else if(number == .JPEG) {
- item.title = "JPEG (.jpeg)"
- item.tag = KMConvertWithPDFType.JPEG.rawValue
- } else if(number == .JPG) {
- item.title = "JPG (.jpg)"
- item.tag = KMConvertWithPDFType.JPG.rawValue
- } else if(number == .PNG) {
- item.title = "PNG (.png)"
- item.tag = KMConvertWithPDFType.PNG.rawValue
- } else if(number == .GIF) {
- item.title = "GIF (.gif)"
- item.tag = KMConvertWithPDFType.GIF.rawValue
- } else if(number == .TIFF) {
- item.title = "TIFF (.tiff)"
- item.tag = KMConvertWithPDFType.TIFF.rawValue
- } else if(number == .TGA) {
- item.title = "TGA (.tga)"
- item.tag = KMConvertWithPDFType.TGA.rawValue
- } else if(number == .BMP) {
- item.title = "BMP (.bmp)"
- item.tag = KMConvertWithPDFType.BMP.rawValue
- } else if(number == .JPEG2000) {
- item.title = "JPEG-2000 (.jp2)"
- item.tag = KMConvertWithPDFType.JPEG2000.rawValue
- } else if(number == .Json) {
- item.title = "Json(.json)"
- item.tag = KMConvertWithPDFType.Json.rawValue
- }
-
- self.formatSelectButton.menu?.addItem(item)
- }
-
- }
-
- @IBAction func buttonClicked_Convert(_ sender: NSButton) {
- if !self.haveFiles { return }
- self.view.window?.makeFirstResponder(nil)
- for i in 0..<self.files!.count {
- let file = self.files?[i]
- // file?.excelParameter.allInOneSheet = true // 看代码是没有用
- file?.advanceWordParameter.isRetainLayout = (self.wordButtonTwo.state == .on) ? true : false
- // file?.excelParameter.isExtreactTabel = (self.extractButton.state == .on) ? true : false // 看代码是没有用
- file?.CSVParameter.isExtreactTabel = (self.csvExtractButton.state == .on) ? true : false
- file?.excelParameter.excelContentOption = self.excelContentOption
- file?.excelParameter.excelWorksheetOption = self.excelWorksheetOption
- file?.JSONParameter.isExtreactTabel = self.wordButtonTwo.state == .on
- var isAllowOCR = self.ocrBox.isHidden == false
- if isAllowOCR {
- isAllowOCR = self.ocrButton.state == .on
- }
- file?.isAllowOCR = isAllowOCR
- file?.ocrLanguage = isAllowOCR ? self.ocrLanguage_ : .chinese
- }
- if sender.tag == 1 {
- self.beginBatchOperation()
- } else {
- self.cancelBatchOperation()
- }
-
- }
-
- @IBAction func moreButtonAction(_ sender: NSButton) {
- self.moreConvertInfoAction()
- }
-
- @IBAction func layoutButtonAction(_ sender: Any) {
- }
-
- @IBAction func buttonClicked_Cancel(_ sender: Any) {
- let basePath = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? ""
- let newPath = (basePath as NSString).appendingPathComponent(Bundle.main.bundleIdentifier ?? "")
- let filePath = newPath.stringByAppendingPathComponent("convert.pdf")
- if FileManager.default.fileExists(atPath: filePath) {
- try? FileManager.default.removeItem(atPath: filePath)
- }
- }
-
- func transform(withString string: String) {
- if string == NSLocalizedString("Create Sheet for each Table", comment: "") {
- self.excelWorksheetOption = .forEachTable
- } else if string == NSLocalizedString("Create Sheet for each Page", comment: "") {
- self.excelWorksheetOption = .forEachPage
- } else if string == NSLocalizedString("Create single Sheet for File", comment: "") {
- self.excelWorksheetOption = .forTheDocument
- }
- }
-
- @IBAction func buttonClicked_excelStyle(_ sender: NSButton) {
- if sender == onlyTextBtn {
- onlyTextBtn.state = NSControl.StateValue.on
- onlyTableBtn.state = NSControl.StateValue.off
- allContentBtn.state = NSControl.StateValue.off
- tableMenu.isEnabled = false
- allContentMenu.isEnabled = false
- excelContentOption = .onlyText
- excelWorksheetOption = .forEachTable
- } else if sender == onlyTableBtn {
- onlyTableBtn.state = NSControl.StateValue.on
- onlyTextBtn.state = NSControl.StateValue.off
- allContentBtn.state = NSControl.StateValue.off
- tableMenu.isEnabled = true
- allContentMenu.isEnabled = false
- excelContentOption = .onlyTable
- transform(withString: tableMenu.selectedItem?.title ?? "")
- } else if sender == allContentBtn {
- allContentBtn.state = NSControl.StateValue.on
- onlyTextBtn.state = NSControl.StateValue.off
- onlyTableBtn.state = NSControl.StateValue.off
- tableMenu.isEnabled = false
- allContentMenu.isEnabled = true
- excelContentOption = .allContent
- transform(withString: allContentMenu.selectedItem?.title ?? "")
- }
- }
-
- @IBAction func buttonClicked_tableMenu(_ sender: NSPopUpButton) {
- transform(withString: self.tableMenu.selectedItem!.title)
- }
-
- @IBAction func buttonClickec_allContentMenu(_ sender: NSButton) {
- transform(withString: self.allContentMenu.selectedItem!.title)
- }
-
- func intConvertType(num: Int) -> KMConvertWithPDFType {
- var type: KMConvertWithPDFType?
- switch num {
- case 0:
- type = .WordAdvance
- case 1:
- type = .WordStandard
- case 2:
- type = .Excel
- case 3:
- type = .PowerPoint
- case 4:
- type = .RTF
- case 5:
- type = .CSV
- case 6:
- type = .HTML
- case 7:
- type = .Text
- case 8:
- type = .JPEG
- case 9:
- type = .JPG
- case 10:
- type = .PNG
- case 11:
- type = .GIF
- case 12:
- type = .TIFF
- case 13:
- type = .TGA
- case 14:
- type = .BMP
- case 15:
- type = .JPEG2000
- case 16:
- type = .Json
- default:
- type = .WordAdvance
- }
- return type!
- }
-
- func moreConvertInfoAction() {
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() == false {
- #if VERSION_DMG
- if KMMemberInfo.shared.isMemberAllFunction && IAPProductsManager.default().isAvailableAdvancedPDFToOffice() == false {
- let limitWC = KMPurchaseLimitWindowController.currentLimitWC()
- limitWC.continueBlock = { windowController in
-
- }
- limitWC.window?.center()
- limitWC.showWindow(nil)
- }else{
- KMProductCompareWC.shared.orientation = false
- let winC = KMProductCompareWC.shared
- if let viewC = self.view.window?.contentViewController, viewC.kEventTag == 1 {
- winC.kEventName = "Onbrd_ConvertPDF_BuyNow"
- } else {
- if convertType == .WordStandard || convertType == .WordAdvance {
- winC.kEventName = "Onbrd_PDFtoWord_BuyNow"
- } else if convertType == .Excel {
- winC.kEventName = "Onbrd_PDFtoExcel_BuyNow"
- } else if convertType == .PowerPoint {
- winC.kEventName = "Onbrd_PDFtoPPT_BuyNow"
- }
- }
-
- winC.showWindow(nil)
- }
- #else
- if KMMemberInfo.shared.isMemberAllFunction == true {
- self.convertActionVC()
- } else {
- KMMemberInfo.shared.advancedFunctionUsage()
- }
- #endif
- }
- }
-
- @IBAction func buttonClicked_FormatSelect(_ sender: NSButton) {
- guard let item = self.formatSelectButton.selectedItem else { return }
- convertType = KMConvertWithPDFType(rawValue: item.tag) ?? .WordAdvance
-
- updateBottomView()
- }
-
- @IBAction func comboxClicked_OcrLanguage(_ sender: AnyObject?) {
- switch (ocrLanguageBox.indexOfSelectedItem) {
- case 0: //chinese
- self.ocrLanguage_ = .chinese
- break
- case 1: //chinese zht
- self.ocrLanguage_ = .chineseTraditional
- break
- case 2: //English
- self.ocrLanguage_ = .english
- break
- case 3:
- //Japanese
- self.ocrLanguage_ = .japanese
- break
- case 4:
- //Kroean
- self.ocrLanguage_ = .korean
- break
- case 5:
- //Serbian
- self.ocrLanguage_ = .serbian
- break
- case 6:
- //Occitan
- self.ocrLanguage_ = .occitan
- break
- case 7:
- //Danish
- self.ocrLanguage_ = .danish
- break
- case 8:
- //German
- self.ocrLanguage_ = .german
- break
- case 9:
- //French
- self.ocrLanguage_ = .french
- break
- case 10:
- //Italian
- self.ocrLanguage_ = .italian
- break
- case 11:
- //Spanish
- self.ocrLanguage_ = .spanish
- break
- case 12:
- //Portuguese
- self.ocrLanguage_ = .portuguese
- break
- case 13:
- //Maori
- self.ocrLanguage_ = .maori
- break
- case 14:
- //Malay
- self.ocrLanguage_ = .malay
- break
- case 15:
- //Malay
- self.ocrLanguage_ = .maltese
- break
- case 16:
- //Dutch
- self.ocrLanguage_ = .dutch
- break
- case 17:
- //Norwegian
- self.ocrLanguage_ = .norwegian
- break
- case 18:
- //Polish
- self.ocrLanguage_ = .polish
- break
- case 19:
- //Romanian
- self.ocrLanguage_ = .romanian
- break
- case 20:
- //Slovak
- self.ocrLanguage_ = .slovak
- break
- case 21:
- //Slovenian
- self.ocrLanguage_ = .slovenian
- break
- case 22:
- //Albanian
- self.ocrLanguage_ = .albanian
- break
- case 23:
- //Swedish
- self.ocrLanguage_ = .swedish
- break
- case 24:
- //Swahili
- self.ocrLanguage_ = .swahili
- break
- case 25:
- //Tagalog
- self.ocrLanguage_ = .tagalog
- break
- case 26:
- //Turish
- self.ocrLanguage_ = .turish
- break
- case 27:
- //Uzbek
- self.ocrLanguage_ = .uzbek
- break
- case 28:
- //Vietnamese
- self.ocrLanguage_ = .vietnamese
- break
- case 29:
- //Afrikaans
- self.ocrLanguage_ = .afrikaans
- break
- case 30:
- //Azerbaijani
- self.ocrLanguage_ = .azerbaijani
- break
- case 31:
- //Bosnian
- self.ocrLanguage_ = .bosnian
- break
- case 32:
- //Czech
- self.ocrLanguage_ = .czech
- break
- case 33: //Welsh
- self.ocrLanguage_ = .welsh
- break
- case 34: //Estonian
- self.ocrLanguage_ = .estonian
- break
- case 35: //Irish
- self.ocrLanguage_ = .irish
- break
- case 36: //Croatian
- self.ocrLanguage_ = .croatian
- break
- case 37: //Hungarian
- self.ocrLanguage_ = .hungarian
- break
- case 38: //Indonesian
- self.ocrLanguage_ = .indonesian
- break
- case 39: //Icelandic
- self.ocrLanguage_ = .icelandic
- break
- case 40: //Kurdish
- self.ocrLanguage_ = .kurdish
- break
- case 41: //Lithuanian
- self.ocrLanguage_ = .lithuanian
- break
- case 42: //Latvian
- self.ocrLanguage_ = .latvian
- break
- case 43: //Marathi
- self.ocrLanguage_ = .marathi
- break
- case 44: //Nepali
- self.ocrLanguage_ = .nepali
- break
- case 45: //Latvia
- self.ocrLanguage_ = .latvian
- break
- case 46: //Bihari
- self.ocrLanguage_ = .bihari
- break
- case 47: //Maithili
- self.ocrLanguage_ = .maithili
- break
- case 48: //Angika
- self.ocrLanguage_ = .angika
- break
- case 49: //Bhojpuri
- self.ocrLanguage_ = .bhojpuri
- break
- case 50: //Magahi
- self.ocrLanguage_ = .magahi
- break
- case 51: //Nagpur
- self.ocrLanguage_ = .nagpur
- break
- case 52: //Newari
- self.ocrLanguage_ = .newari
- break
- case 53: //GoanKonkani
- self.ocrLanguage_ = .goanKonkani
- break
- case 54: //SaudiArabia
- self.ocrLanguage_ = .saudiArabia
- break
- default:
- self.ocrLanguage_ = .english
- break
- }
- }
-
- @IBAction func comboxClicked_SupoortOCR(_ sender: AnyObject?) {
- if(ocrButton.state == .on) {
- ocrLabel.textColor = KMAppearance.titleColor()
- ocrLanguageBox.isEnabled = true
- } else {
- ocrLabel.textColor = KMAppearance.Layout.h2Color()
- ocrLanguageBox.isEnabled = false
- }
- }
- }
|