KMBatchOperateConvertViewController.swift 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  1. //
  2. // KMBatchOperateConvertViewController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by kdanmobile on 2023/11/1.
  6. //
  7. import Cocoa
  8. typealias detailInfoViewMouseDownCallback = (_ mouseDown: Bool) -> ()
  9. class KMDetailInfoView: NSView{
  10. var mouseDownCallback: detailInfoViewMouseDownCallback?
  11. override func mouseDown(with event: NSEvent) {
  12. super.mouseDown(with: event)
  13. guard let callBack = mouseDownCallback else { return }
  14. callBack(true)
  15. }
  16. }
  17. class KMBatchOperateConvertViewController: KMBatchOperateBaseViewController{
  18. var dataSourcesArray: [KMConvertWithPDFType]?
  19. @IBOutlet var bottomView: NSView!
  20. @IBOutlet var convertButton: NSButton!
  21. @IBOutlet var buttonBottemOffset: NSLayoutConstraint!
  22. @IBOutlet var detailInfoLabel: NSTextField!
  23. @IBOutlet var detailInfoBox: NSBox!
  24. @IBOutlet var separateStypeTopOffset: NSLayoutConstraint!
  25. @IBOutlet var separateStypeBox: NSBox!
  26. @IBOutlet var wordButtonOne: NSButton!
  27. @IBOutlet var wordButtonTwo: NSButton!
  28. @IBOutlet var excelStyleBox: NSBox!
  29. @IBOutlet var allContentMenu: NSPopUpButton!
  30. @IBOutlet var allContentMenu2: NSMenuItem!
  31. @IBOutlet var allContentMenu3: NSMenuItem!
  32. @IBOutlet var onlyTextBtn: NSButton!
  33. @IBOutlet var onlyTableBtn: NSButton!
  34. @IBOutlet var allContentBtn: NSButton!
  35. @IBOutlet var tableMenu1: NSMenuItem!
  36. @IBOutlet var tableMenu2: NSMenuItem!
  37. @IBOutlet var tableMenu3: NSMenuItem!
  38. @IBOutlet var tableMenu: NSPopUpButton!
  39. @IBOutlet var csvExtractButton: NSButton!
  40. @IBOutlet var ocrBox: NSBox!
  41. @IBOutlet var ocrLabel: NSTextField!
  42. @IBOutlet var ocrButton: NSButton!
  43. @IBOutlet var ocrLanguageBox: NSPopUpButton!
  44. @IBOutlet var ocrTopOffset: NSLayoutConstraint!
  45. @IBOutlet var headerView: KMConvertCollectionViewHeader!
  46. @IBOutlet var headerTopOffset: NSLayoutConstraint!
  47. @IBOutlet var formatLabel: NSTextField!
  48. @IBOutlet var formatSelectButton: NSPopUpButton!
  49. var excelContentOption: CPDFConvertExcelContentOptions?
  50. var excelWorksheetOption: CPDFConvertExcelWorksheetOptions?
  51. var haveFiles: Bool = false
  52. private var ocrLanguage_: COCRLanguage = .english
  53. deinit {
  54. NotificationCenter.default.removeObserver(self)
  55. }
  56. override var interfaceStatus: KMBatchOperateInterfaceStatus?{
  57. set{
  58. super.interfaceStatus = newValue
  59. self.convertButton.isEnabled = true
  60. if newValue == .Processing {
  61. formatSelectButton.isEnabled = false
  62. self.convertButton.title = NSLocalizedString("Cancel", comment: "")
  63. self.convertButton.tag = 2
  64. self.convertButton.setTitleColor(KMAppearance.Layout.w0Color())
  65. self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
  66. if self.convertType == .WordStandard {
  67. self.convertButton.title = NSLocalizedString("Convert", comment: "")
  68. self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().withAlphaComponent(0.4).cgColor
  69. self.convertButton.isEnabled = false
  70. }
  71. } else {
  72. DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
  73. var files: [URL] = []
  74. for url in self.successFilePathURLArray! {
  75. if FileManager.default.fileExists(atPath: url.path) {
  76. files.append(url)
  77. }
  78. }
  79. if files.count > 0 {
  80. let workspace = NSWorkspace.shared
  81. workspace.activateFileViewerSelecting(files)
  82. }
  83. }
  84. formatSelectButton.isEnabled = true
  85. self.convertButton.title = NSLocalizedString("Convert", comment: "")
  86. self.convertButton.tag = 1
  87. self.convertButton.setTitleColor(KMAppearance.Layout.w0Color())
  88. self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
  89. }
  90. }
  91. get{
  92. return super.interfaceStatus
  93. }
  94. }
  95. override var convertType: KMConvertWithPDFType?{
  96. set{
  97. super.convertType = newValue
  98. changeAllFilesToConvertType(convertType!)
  99. fetchFileListViewController()?.reloadConvertInterface(withType: convertType!)
  100. }
  101. get{
  102. return super.convertType
  103. }
  104. }
  105. func changeAllFilesToConvertType(_ type: KMConvertWithPDFType) {
  106. for i in 0..<self.files!.count {
  107. let file = self.files![i]
  108. file.convertType = type
  109. }
  110. }
  111. func switchToConvertType(_ convertType: KMConvertWithPDFType) {
  112. self.convertType = convertType
  113. self.manualSelectRow(convertType)
  114. self.updateBottomView()
  115. }
  116. func manualSelectRow(_ convertType: KMConvertWithPDFType) {
  117. var index = -1
  118. updateFormatView()
  119. for i in 0..<self.dataSourcesArray!.count {
  120. let number = self.dataSourcesArray![i]
  121. if number.rawValue == convertType.rawValue {
  122. index = i
  123. break
  124. }
  125. }
  126. if index != -1 {
  127. self.formatSelectButton.selectItem(at: index)
  128. }
  129. }
  130. func updateBottomView() {
  131. var isShowUpgrade = false
  132. #if VERSION_FREE
  133. #if VERSION_DMG
  134. // 桌机版
  135. if KMMemberInfo.shared.isMemberAllFunction {
  136. if KMMemberInfo.shared.isPermitConvert {
  137. } else {
  138. isShowUpgrade = true
  139. }
  140. } else {
  141. isShowUpgrade = true
  142. }
  143. #else
  144. // 免费版
  145. if KMMemberInfo.shared.isMemberAllFunction {
  146. if KMMemberInfo.shared.isPermitConvert {
  147. } else {
  148. isShowUpgrade = true
  149. }
  150. } else {
  151. isShowUpgrade = true
  152. }
  153. #endif
  154. #else
  155. if KMMemberInfo.shared.isPermitConvert {
  156. } else {
  157. isShowUpgrade = true
  158. }
  159. #endif
  160. var moreLabelString = ""
  161. #if VERSION_FREE
  162. if !KMMemberInfo.shared.isMemberAllFunction {
  163. moreLabelString = String(format: "%@ %@", KMLocalizedString("The first 10 pages for free"), KMLocalizedString("Unlimited Convert"))
  164. } else {
  165. if !KMMemberInfo.shared.isPermitConvert {
  166. if .WordAdvance == self.convertType ||
  167. .WordStandard == self.convertType ||
  168. .Excel == self.convertType ||
  169. .PowerPoint == self.convertType ||
  170. .CSV == self.convertType ||
  171. .RTF == self.convertType ||
  172. .GIF == self.convertType ||
  173. .TIFF == self.convertType ||
  174. .JPEG2000 == self.convertType ||
  175. .BMP == self.convertType ||
  176. .TGA == self.convertType ||
  177. .Json == self.convertType {
  178. moreLabelString = String(format: "%@ %@", KMLocalizedString("The first 10 pages for free"), KMLocalizedString("Unlimited Convert"))
  179. }
  180. }
  181. }
  182. #else
  183. // 付费版
  184. if !KMMemberInfo.shared.isPermitConvert {
  185. if .WordAdvance == self.convertType ||
  186. .WordStandard == self.convertType ||
  187. .Excel == self.convertType ||
  188. .PowerPoint == self.convertType ||
  189. .CSV == self.convertType ||
  190. .RTF == self.convertType ||
  191. .GIF == self.convertType ||
  192. .TIFF == self.convertType ||
  193. .JPEG2000 == self.convertType ||
  194. .BMP == self.convertType ||
  195. .TGA == self.convertType ||
  196. .Json == self.convertType {
  197. moreLabelString = String(format: "%@ %@", KMLocalizedString("The first 10 pages for free"), KMLocalizedString("Unlimited Convert"))
  198. }
  199. }
  200. #endif
  201. self.detailInfoLabel.stringValue = moreLabelString
  202. if let range = moreLabelString.range(of: NSLocalizedString("Unlimited Convert", comment: "")) {
  203. let newR: NSRange = moreLabelString.nsRange(from: range)!
  204. let attributedStr = NSMutableAttributedString(string: moreLabelString)
  205. attributedStr.addAttribute(.foregroundColor, value: NSColor.labelColor, range: NSRange(location: 0, length: newR.location - 1))
  206. attributedStr.addAttribute(.foregroundColor, value: NSColor(red: 8/255, green: 124/255, blue: 1, alpha: 1), range: newR)
  207. attributedStr.addAttribute(.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: newR)
  208. detailInfoLabel.attributedStringValue = attributedStr
  209. }
  210. if moreLabelString.count > 0 {
  211. detailInfoBox.isHidden = false
  212. buttonBottemOffset.constant = 45
  213. } else {
  214. detailInfoBox.isHidden = true
  215. buttonBottemOffset.constant = 10
  216. }
  217. if self.convertType == .WordAdvance {
  218. separateStypeBox.isHidden = false
  219. excelStyleBox.isHidden = true
  220. csvExtractButton.isHidden = true
  221. ocrBox.isHidden = false
  222. wordButtonOne.title = NSLocalizedString("Retain Flowing Text", comment: "")
  223. wordButtonTwo.title = NSLocalizedString("Retain Page Layout", comment: "")
  224. ocrTopOffset.constant = 15 + separateStypeBox.frame.height
  225. } else if self.convertType == .Excel {
  226. separateStypeBox.isHidden = true
  227. excelStyleBox.isHidden = false
  228. csvExtractButton.isHidden = true
  229. ocrBox.isHidden = false
  230. ocrTopOffset.constant = 15 + excelStyleBox.frame.height
  231. } else if .Json == convertType {
  232. wordButtonOne.title = NSLocalizedString("Extract text content", comment: "")
  233. wordButtonTwo.title = NSLocalizedString("Extract tables", comment: "")
  234. separateStypeBox.isHidden = false
  235. excelStyleBox.isHidden = true
  236. csvExtractButton.isHidden = true
  237. ocrBox.isHidden = false
  238. ocrTopOffset.constant = 15 + separateStypeBox.frame.height
  239. } else if (.PowerPoint == convertType ||
  240. .RTF == convertType ||
  241. .HTML == convertType ||
  242. .Text == convertType) {
  243. separateStypeBox.isHidden = true
  244. excelStyleBox.isHidden = true
  245. csvExtractButton.isHidden = true
  246. ocrBox.isHidden = false
  247. ocrTopOffset.constant = 15
  248. } else if self.convertType == .CSV {
  249. separateStypeBox.isHidden = true
  250. excelStyleBox.isHidden = true
  251. csvExtractButton.isHidden = false
  252. ocrBox.isHidden = true
  253. self.csvExtractButton.title = NSLocalizedString("Extract Tables Only", comment: "")
  254. } else {
  255. separateStypeBox.isHidden = true
  256. excelStyleBox.isHidden = true
  257. csvExtractButton.isHidden = true
  258. ocrBox.isHidden = true
  259. }
  260. }
  261. override func viewDidLoad() {
  262. super.viewDidLoad()
  263. self.prepareData()
  264. updateFormatView()
  265. self.view.wantsLayer = true
  266. convertButton.wantsLayer = true
  267. convertButton.font = NSFont.systemFont(ofSize: 13)
  268. convertButton.layer?.cornerRadius = 1.0
  269. interfaceStatus = .PrepareProcess
  270. allContentBtn.state = .on
  271. allContentMenu.isEnabled = true
  272. tableMenu.isEnabled = false
  273. excelContentOption = .allContent
  274. excelWorksheetOption = .forEachPage
  275. onlyTextBtn.title = NSLocalizedString("Only Text", comment: "")
  276. onlyTableBtn.title = NSLocalizedString("Only Table", comment: "")
  277. allContentBtn.title = NSLocalizedString("All Content", comment: "")
  278. onlyTextBtn.toolTip = NSLocalizedString("Only Text", comment: "")
  279. onlyTableBtn.toolTip = NSLocalizedString("Only Table", comment: "")
  280. allContentBtn.toolTip = NSLocalizedString("All Content", comment: "")
  281. tableMenu1.title = NSLocalizedString("Create Sheet for each Table", comment: "")
  282. tableMenu2.title = NSLocalizedString("Create Sheet for each Page", comment: "")
  283. allContentMenu2.title = NSLocalizedString("Create Sheet for each Page", comment: "")
  284. tableMenu3.title = NSLocalizedString("Create single Sheet for File", comment: "")
  285. allContentMenu3.title = NSLocalizedString("Create single Sheet for File", comment: "")
  286. formatLabel.stringValue = KMLocalizedString("Format:", nil)
  287. ocrBox.title = KMLocalizedString("OCR Settings", nil)
  288. ocrBox.titleFont = .SFProTextBoldFont(14.0)
  289. formatLabel.font = .SFProTextBoldFont(14.0)
  290. headerView.convertHeaderClickedCallBack = { [weak self] in
  291. self?.moreConvertInfoAction()
  292. }
  293. self.ocrButton.title = NSLocalizedString("Recognize text", comment: "")
  294. self.ocrLabel.stringValue = NSLocalizedString("Language Option", comment: "") + ":"
  295. ocrLanguageBox.selectItem(at: 2)
  296. ocrLabel.textColor = KMAppearance.Layout.h2Color()
  297. ocrLanguageBox.isEnabled = false
  298. ocrButton.state = .off
  299. self.updateViewColor()
  300. NotificationCenter.default.addObserver(self, selector: #selector(batchFilesCountNotification(notification:)), name: Notification.Name(rawValue: "KMBatchFilesCountNotification"), object: nil)
  301. NotificationCenter.default.addObserver(self, selector: #selector(IAPProductPurchasedNotification(notification:)), name: NSNotification.Name("KMIAPProductPurchasedNotification"), object: nil)
  302. NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFinishedNotification(notification:)), name: NSNotification.Name("KMIAPProductRestoreFinishedNotification"), object: nil)
  303. // NotificationCenter.default.addObserver(self, selector: #selector(themeChanged(notification:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
  304. DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChanged(notification:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
  305. NotificationCenter.default.addObserver(self, selector: #selector(deviceActivateStatusChanged(notification:)), name: NSNotification.Name("kDeviceActivateNotification"), object: nil)
  306. }
  307. @objc func batchFilesCountNotification(notification: NSNotification) {
  308. let arr: Array? = notification.object as? [KMBatchOperateFile]
  309. self.files? = arr ?? []
  310. if files!.count > 0 {
  311. self.convertButton.setTitleColor(NSColor.white)
  312. self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
  313. self.haveFiles = true
  314. } else {
  315. self.convertButton.setTitleColor(KMAppearance.Layout.w0Color().withAlphaComponent(0.6))
  316. self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().withAlphaComponent(0.4).cgColor
  317. self.haveFiles = false
  318. }
  319. }
  320. @objc func themeChanged(notification: NSNotification) {
  321. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  322. self.updateViewColor()
  323. }
  324. }
  325. @objc func IAPProductRestoreFinishedNotification(notification: NSNotification) {
  326. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  327. self.updateBottomView()
  328. self.prepareData()
  329. self.updateFormatView()
  330. }
  331. }
  332. @objc func IAPProductPurchasedNotification(notification: NSNotification) {
  333. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  334. self.updateBottomView()
  335. self.prepareData()
  336. self.updateFormatView()
  337. }
  338. }
  339. @objc func deviceActivateStatusChanged(notification: NSNotification) {
  340. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  341. self.updateBottomView()
  342. self.prepareData()
  343. self.updateFormatView()
  344. }
  345. }
  346. func updateViewColor() {
  347. self.view.wantsLayer = true
  348. if KMAppearance.isDarkMode() {
  349. self.view.layer?.backgroundColor = NSColor(red: 0.055, green: 0.067, blue: 0.078, alpha: 1).cgColor
  350. } else {
  351. self.view.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  352. }
  353. }
  354. func convertActionVC() {
  355. if(KMMemberInfo.shared.isLogin == false) {
  356. KMLoginWindowsController.shared.showWindow(nil)
  357. }
  358. }
  359. func prepareData() {
  360. let arr: [KMConvertWithPDFType] = [.Excel, .PowerPoint, .RTF, .CSV, .HTML, .Text, .JPEG, .JPG, .PNG, .GIF, .TIFF, .TGA, .BMP, .JPEG2000, .Json]
  361. self.dataSourcesArray = arr
  362. var needShowAdvance = true
  363. var needShowDefault = true
  364. #if VERSION_FREE
  365. // 桌机版
  366. if KMMemberInfo.shared.isMemberAllFunction {
  367. if KMMemberInfo.shared.isPermitConvert {
  368. needShowAdvance = true
  369. needShowDefault = false
  370. }
  371. }
  372. #else
  373. if KMMemberInfo.shared.isPermitConvert {
  374. needShowAdvance = true
  375. needShowDefault = false
  376. }
  377. #endif
  378. if needShowDefault {
  379. var wordType: KMConvertWithPDFType = .WordStandard
  380. self.dataSourcesArray?.insert(wordType, at: 0)
  381. }
  382. if needShowAdvance {
  383. var wordType: KMConvertWithPDFType = .WordAdvance
  384. self.dataSourcesArray?.insert(wordType, at: 0)
  385. }
  386. }
  387. func updateFormatView() {
  388. var isShowAdvanced = false
  389. #if VERSION_FREE
  390. #if VERSION_DMG
  391. // 桌机版
  392. isShowAdvanced = true
  393. if KMMemberInfo.shared.isMemberAllFunction {
  394. if KMMemberInfo.shared.isPermitConvert {
  395. isShowAdvanced = false
  396. }
  397. }
  398. #else
  399. // 免费版
  400. isShowAdvanced = true
  401. if KMMemberInfo.shared.isMemberAllFunction {
  402. if KMMemberInfo.shared.isPermitConvert {
  403. isShowAdvanced = false
  404. }
  405. }
  406. #endif
  407. #else
  408. isShowAdvanced = true
  409. if KMMemberInfo.shared.isPermitConvert {
  410. isShowAdvanced = false
  411. }
  412. #endif
  413. self.formatSelectButton.removeAllItems()
  414. for i in 0..<self.dataSourcesArray!.count {
  415. let number = self.dataSourcesArray![i]
  416. let item = NSMenuItem()
  417. item.target = self
  418. if(number == .WordAdvance) {
  419. if isShowAdvanced {
  420. let originStr = " \(NSLocalizedString("Advanced", comment: "")) "
  421. let str = NSLocalizedString("Word (.docx)", comment: "")
  422. let attributedStr = NSMutableAttributedString(string: "\(str) \(originStr)")
  423. 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))
  424. attributedStr.addAttribute(NSAttributedString.Key.foregroundColor, value: NSColor.white, range: NSMakeRange(str.count + 2, originStr.count))
  425. item.attributedTitle = attributedStr
  426. } else {
  427. item.title = "Word (.docx)"
  428. }
  429. item.tag = KMConvertWithPDFType.WordAdvance.rawValue
  430. } else if(number == .WordStandard) {
  431. if isShowAdvanced {
  432. let originStr = " \(KMLocalizedString("Standard", nil)) "
  433. let str = KMLocalizedString("Word (.docx)", nil)
  434. let attributedStr = NSMutableAttributedString(string: "\(str) \(originStr)")
  435. 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))
  436. attributedStr.addAttribute(NSAttributedString.Key.foregroundColor, value: NSColor.white, range: NSMakeRange(str.count + 2, originStr.count))
  437. item.attributedTitle = attributedStr
  438. } else {
  439. item.title = "Word (.docx)"
  440. }
  441. item.tag = KMConvertWithPDFType.WordStandard.rawValue
  442. } else if(number == .Excel) {
  443. item.title = "Excel (.xlsx)"
  444. item.tag = KMConvertWithPDFType.Excel.rawValue
  445. } else if(number == .PowerPoint) {
  446. item.title = "PowerPoint (.pptx)"
  447. item.tag = KMConvertWithPDFType.PowerPoint.rawValue
  448. } else if(number == .RTF) {
  449. item.title = "RTF (.rtf)"
  450. item.tag = KMConvertWithPDFType.RTF.rawValue
  451. } else if(number == .CSV) {
  452. item.title = "CSV (.csv)"
  453. item.tag = KMConvertWithPDFType.CSV.rawValue
  454. } else if(number == .HTML) {
  455. item.title = "Html (.html)"
  456. item.tag = KMConvertWithPDFType.HTML.rawValue
  457. } else if(number == .Text) {
  458. item.title = "Text (.txt)"
  459. item.tag = KMConvertWithPDFType.Text.rawValue
  460. } else if(number == .JPEG) {
  461. item.title = "JPEG (.jpeg)"
  462. item.tag = KMConvertWithPDFType.JPEG.rawValue
  463. } else if(number == .JPG) {
  464. item.title = "JPG (.jpg)"
  465. item.tag = KMConvertWithPDFType.JPG.rawValue
  466. } else if(number == .PNG) {
  467. item.title = "PNG (.png)"
  468. item.tag = KMConvertWithPDFType.PNG.rawValue
  469. } else if(number == .GIF) {
  470. item.title = "GIF (.gif)"
  471. item.tag = KMConvertWithPDFType.GIF.rawValue
  472. } else if(number == .TIFF) {
  473. item.title = "TIFF (.tiff)"
  474. item.tag = KMConvertWithPDFType.TIFF.rawValue
  475. } else if(number == .TGA) {
  476. item.title = "TGA (.tga)"
  477. item.tag = KMConvertWithPDFType.TGA.rawValue
  478. } else if(number == .BMP) {
  479. item.title = "BMP (.bmp)"
  480. item.tag = KMConvertWithPDFType.BMP.rawValue
  481. } else if(number == .JPEG2000) {
  482. item.title = "JPEG-2000 (.jp2)"
  483. item.tag = KMConvertWithPDFType.JPEG2000.rawValue
  484. } else if(number == .Json) {
  485. item.title = "Json(.json)"
  486. item.tag = KMConvertWithPDFType.Json.rawValue
  487. }
  488. self.formatSelectButton.menu?.addItem(item)
  489. }
  490. }
  491. @IBAction func buttonClicked_Convert(_ sender: NSButton) {
  492. if !self.haveFiles { return }
  493. self.view.window?.makeFirstResponder(nil)
  494. for i in 0..<self.files!.count {
  495. let file = self.files?[i]
  496. // file?.excelParameter.allInOneSheet = true // 看代码是没有用
  497. file?.advanceWordParameter.isRetainLayout = (self.wordButtonTwo.state == .on) ? true : false
  498. // file?.excelParameter.isExtreactTabel = (self.extractButton.state == .on) ? true : false // 看代码是没有用
  499. file?.CSVParameter.isExtreactTabel = (self.csvExtractButton.state == .on) ? true : false
  500. file?.excelParameter.excelContentOption = self.excelContentOption
  501. file?.excelParameter.excelWorksheetOption = self.excelWorksheetOption
  502. file?.JSONParameter.isExtreactTabel = self.wordButtonTwo.state == .on
  503. var isAllowOCR = self.ocrBox.isHidden == false
  504. if isAllowOCR {
  505. isAllowOCR = self.ocrButton.state == .on
  506. }
  507. file?.isAllowOCR = isAllowOCR
  508. file?.ocrLanguage = isAllowOCR ? self.ocrLanguage_ : .chinese
  509. }
  510. if sender.tag == 1 {
  511. self.beginBatchOperation()
  512. } else {
  513. self.cancelBatchOperation()
  514. }
  515. }
  516. @IBAction func moreButtonAction(_ sender: NSButton) {
  517. self.moreConvertInfoAction()
  518. }
  519. @IBAction func layoutButtonAction(_ sender: Any) {
  520. }
  521. @IBAction func buttonClicked_Cancel(_ sender: Any) {
  522. let basePath = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? ""
  523. let newPath = (basePath as NSString).appendingPathComponent(Bundle.main.bundleIdentifier ?? "")
  524. let filePath = newPath.stringByAppendingPathComponent("convert.pdf")
  525. if FileManager.default.fileExists(atPath: filePath) {
  526. try? FileManager.default.removeItem(atPath: filePath)
  527. }
  528. }
  529. func transform(withString string: String) {
  530. if string == NSLocalizedString("Create Sheet for each Table", comment: "") {
  531. self.excelWorksheetOption = .forEachTable
  532. } else if string == NSLocalizedString("Create Sheet for each Page", comment: "") {
  533. self.excelWorksheetOption = .forEachPage
  534. } else if string == NSLocalizedString("Create single Sheet for File", comment: "") {
  535. self.excelWorksheetOption = .forTheDocument
  536. }
  537. }
  538. @IBAction func buttonClicked_MoreConvert(_ sender: NSButton) {
  539. if KMMemberInfo.shared.isMemberAllFunction == true {
  540. if(KMMemberInfo.shared.isLogin == false) {
  541. KMLoginWindowsController.shared.showWindow(nil)
  542. }
  543. }
  544. }
  545. @IBAction func buttonClicked_excelStyle(_ sender: NSButton) {
  546. if sender == onlyTextBtn {
  547. onlyTextBtn.state = NSControl.StateValue.on
  548. onlyTableBtn.state = NSControl.StateValue.off
  549. allContentBtn.state = NSControl.StateValue.off
  550. tableMenu.isEnabled = false
  551. allContentMenu.isEnabled = false
  552. excelContentOption = .onlyText
  553. excelWorksheetOption = .forEachTable
  554. } else if sender == onlyTableBtn {
  555. onlyTableBtn.state = NSControl.StateValue.on
  556. onlyTextBtn.state = NSControl.StateValue.off
  557. allContentBtn.state = NSControl.StateValue.off
  558. tableMenu.isEnabled = true
  559. allContentMenu.isEnabled = false
  560. excelContentOption = .onlyTable
  561. transform(withString: tableMenu.selectedItem?.title ?? "")
  562. } else if sender == allContentBtn {
  563. allContentBtn.state = NSControl.StateValue.on
  564. onlyTextBtn.state = NSControl.StateValue.off
  565. onlyTableBtn.state = NSControl.StateValue.off
  566. tableMenu.isEnabled = false
  567. allContentMenu.isEnabled = true
  568. excelContentOption = .allContent
  569. transform(withString: allContentMenu.selectedItem?.title ?? "")
  570. }
  571. }
  572. @IBAction func buttonClicked_tableMenu(_ sender: NSPopUpButton) {
  573. transform(withString: self.tableMenu.selectedItem!.title)
  574. }
  575. @IBAction func buttonClickec_allContentMenu(_ sender: NSButton) {
  576. transform(withString: self.allContentMenu.selectedItem!.title)
  577. }
  578. func intConvertType(num: Int) -> KMConvertWithPDFType {
  579. var type: KMConvertWithPDFType?
  580. switch num {
  581. case 0:
  582. type = .WordAdvance
  583. case 1:
  584. type = .WordStandard
  585. case 2:
  586. type = .Excel
  587. case 3:
  588. type = .PowerPoint
  589. case 4:
  590. type = .RTF
  591. case 5:
  592. type = .CSV
  593. case 6:
  594. type = .HTML
  595. case 7:
  596. type = .Text
  597. case 8:
  598. type = .JPEG
  599. case 9:
  600. type = .JPG
  601. case 10:
  602. type = .PNG
  603. case 11:
  604. type = .GIF
  605. case 12:
  606. type = .TIFF
  607. case 13:
  608. type = .TGA
  609. case 14:
  610. type = .BMP
  611. case 15:
  612. type = .JPEG2000
  613. case 16:
  614. type = .Json
  615. default:
  616. type = .WordAdvance
  617. }
  618. return type!
  619. }
  620. func moreConvertInfoAction() {
  621. if KMMemberInfo.shared.isPermitConvert == false {
  622. #if VERSION_DMG
  623. if KMMemberInfo.shared.isMemberAllFunction && KMMemberInfo.shared.isPermitConvert == false {
  624. let limitWC = KMPurchaseLimitWindowController.currentLimitWC()
  625. limitWC.continueBlock = { windowController in
  626. }
  627. limitWC.window?.center()
  628. limitWC.showWindow(nil)
  629. }else{
  630. KMProductCompareWC.shared.orientation = false
  631. let winC = KMProductCompareWC.shared
  632. if let viewC = self.view.window?.contentViewController, viewC.kEventTag == 1 {
  633. winC.kEventName = "Onbrd_ConvertPDF_BuyNow"
  634. } else {
  635. if convertType == .WordStandard || convertType == .WordAdvance {
  636. winC.kEventName = "Onbrd_PDFtoWord_BuyNow"
  637. } else if convertType == .Excel {
  638. winC.kEventName = "Onbrd_PDFtoExcel_BuyNow"
  639. } else if convertType == .PowerPoint {
  640. winC.kEventName = "Onbrd_PDFtoPPT_BuyNow"
  641. }
  642. }
  643. winC.showWindow(nil)
  644. }
  645. #else
  646. if KMMemberInfo.shared.isMemberAllFunction == true {
  647. self.convertActionVC()
  648. } else {
  649. KMMemberInfo.shared.advancedFunctionUsage()
  650. }
  651. #endif
  652. }
  653. }
  654. @IBAction func buttonClicked_FormatSelect(_ sender: NSButton) {
  655. guard let item = self.formatSelectButton.selectedItem else { return }
  656. convertType = KMConvertWithPDFType(rawValue: item.tag) ?? .WordAdvance
  657. updateBottomView()
  658. }
  659. @IBAction func comboxClicked_OcrLanguage(_ sender: AnyObject?) {
  660. switch (ocrLanguageBox.indexOfSelectedItem) {
  661. case 0: //chinese
  662. self.ocrLanguage_ = .chinese
  663. break
  664. case 1: //chinese zht
  665. self.ocrLanguage_ = .chineseTraditional
  666. break
  667. case 2: //English
  668. self.ocrLanguage_ = .english
  669. break
  670. case 3:
  671. //Japanese
  672. self.ocrLanguage_ = .japanese
  673. break
  674. case 4:
  675. //Kroean
  676. self.ocrLanguage_ = .korean
  677. break
  678. case 5:
  679. //Serbian
  680. self.ocrLanguage_ = .serbian
  681. break
  682. case 6:
  683. //Occitan
  684. self.ocrLanguage_ = .occitan
  685. break
  686. case 7:
  687. //Danish
  688. self.ocrLanguage_ = .danish
  689. break
  690. case 8:
  691. //German
  692. self.ocrLanguage_ = .german
  693. break
  694. case 9:
  695. //French
  696. self.ocrLanguage_ = .french
  697. break
  698. case 10:
  699. //Italian
  700. self.ocrLanguage_ = .italian
  701. break
  702. case 11:
  703. //Spanish
  704. self.ocrLanguage_ = .spanish
  705. break
  706. case 12:
  707. //Portuguese
  708. self.ocrLanguage_ = .portuguese
  709. break
  710. case 13:
  711. //Maori
  712. self.ocrLanguage_ = .maori
  713. break
  714. case 14:
  715. //Malay
  716. self.ocrLanguage_ = .malay
  717. break
  718. case 15:
  719. //Malay
  720. self.ocrLanguage_ = .maltese
  721. break
  722. case 16:
  723. //Dutch
  724. self.ocrLanguage_ = .dutch
  725. break
  726. case 17:
  727. //Norwegian
  728. self.ocrLanguage_ = .norwegian
  729. break
  730. case 18:
  731. //Polish
  732. self.ocrLanguage_ = .polish
  733. break
  734. case 19:
  735. //Romanian
  736. self.ocrLanguage_ = .romanian
  737. break
  738. case 20:
  739. //Slovak
  740. self.ocrLanguage_ = .slovak
  741. break
  742. case 21:
  743. //Slovenian
  744. self.ocrLanguage_ = .slovenian
  745. break
  746. case 22:
  747. //Albanian
  748. self.ocrLanguage_ = .albanian
  749. break
  750. case 23:
  751. //Swedish
  752. self.ocrLanguage_ = .swedish
  753. break
  754. case 24:
  755. //Swahili
  756. self.ocrLanguage_ = .swahili
  757. break
  758. case 25:
  759. //Tagalog
  760. self.ocrLanguage_ = .tagalog
  761. break
  762. case 26:
  763. //Turish
  764. self.ocrLanguage_ = .turish
  765. break
  766. case 27:
  767. //Uzbek
  768. self.ocrLanguage_ = .uzbek
  769. break
  770. case 28:
  771. //Vietnamese
  772. self.ocrLanguage_ = .vietnamese
  773. break
  774. case 29:
  775. //Afrikaans
  776. self.ocrLanguage_ = .afrikaans
  777. break
  778. case 30:
  779. //Azerbaijani
  780. self.ocrLanguage_ = .azerbaijani
  781. break
  782. case 31:
  783. //Bosnian
  784. self.ocrLanguage_ = .bosnian
  785. break
  786. case 32:
  787. //Czech
  788. self.ocrLanguage_ = .czech
  789. break
  790. case 33: //Welsh
  791. self.ocrLanguage_ = .welsh
  792. break
  793. case 34: //Estonian
  794. self.ocrLanguage_ = .estonian
  795. break
  796. case 35: //Irish
  797. self.ocrLanguage_ = .irish
  798. break
  799. case 36: //Croatian
  800. self.ocrLanguage_ = .croatian
  801. break
  802. case 37: //Hungarian
  803. self.ocrLanguage_ = .hungarian
  804. break
  805. case 38: //Indonesian
  806. self.ocrLanguage_ = .indonesian
  807. break
  808. case 39: //Icelandic
  809. self.ocrLanguage_ = .icelandic
  810. break
  811. case 40: //Kurdish
  812. self.ocrLanguage_ = .kurdish
  813. break
  814. case 41: //Lithuanian
  815. self.ocrLanguage_ = .lithuanian
  816. break
  817. case 42: //Latvian
  818. self.ocrLanguage_ = .latvian
  819. break
  820. case 43: //Marathi
  821. self.ocrLanguage_ = .marathi
  822. break
  823. case 44: //Nepali
  824. self.ocrLanguage_ = .nepali
  825. break
  826. case 45: //Latvia
  827. self.ocrLanguage_ = .latvian
  828. break
  829. case 46: //Bihari
  830. self.ocrLanguage_ = .bihari
  831. break
  832. case 47: //Maithili
  833. self.ocrLanguage_ = .maithili
  834. break
  835. case 48: //Angika
  836. self.ocrLanguage_ = .angika
  837. break
  838. case 49: //Bhojpuri
  839. self.ocrLanguage_ = .bhojpuri
  840. break
  841. case 50: //Magahi
  842. self.ocrLanguage_ = .magahi
  843. break
  844. case 51: //Nagpur
  845. self.ocrLanguage_ = .nagpur
  846. break
  847. case 52: //Newari
  848. self.ocrLanguage_ = .newari
  849. break
  850. case 53: //GoanKonkani
  851. self.ocrLanguage_ = .goanKonkani
  852. break
  853. case 54: //SaudiArabia
  854. self.ocrLanguage_ = .saudiArabia
  855. break
  856. default:
  857. self.ocrLanguage_ = .english
  858. break
  859. }
  860. }
  861. @IBAction func comboxClicked_SupoortOCR(_ sender: AnyObject?) {
  862. if(ocrButton.state == .on) {
  863. ocrLabel.textColor = KMAppearance.titleColor()
  864. ocrLanguageBox.isEnabled = true
  865. } else {
  866. ocrLabel.textColor = KMAppearance.Layout.h2Color()
  867. ocrLanguageBox.isEnabled = false
  868. }
  869. }
  870. }