KMBatchOperateConvertViewController.swift 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958
  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 == false {
  540. KMMemberInfo.shared.advancedFunctionUsage()
  541. return
  542. }
  543. }
  544. @IBAction func buttonClicked_excelStyle(_ sender: NSButton) {
  545. if sender == onlyTextBtn {
  546. onlyTextBtn.state = NSControl.StateValue.on
  547. onlyTableBtn.state = NSControl.StateValue.off
  548. allContentBtn.state = NSControl.StateValue.off
  549. tableMenu.isEnabled = false
  550. allContentMenu.isEnabled = false
  551. excelContentOption = .onlyText
  552. excelWorksheetOption = .forEachTable
  553. } else if sender == onlyTableBtn {
  554. onlyTableBtn.state = NSControl.StateValue.on
  555. onlyTextBtn.state = NSControl.StateValue.off
  556. allContentBtn.state = NSControl.StateValue.off
  557. tableMenu.isEnabled = true
  558. allContentMenu.isEnabled = false
  559. excelContentOption = .onlyTable
  560. transform(withString: tableMenu.selectedItem?.title ?? "")
  561. } else if sender == allContentBtn {
  562. allContentBtn.state = NSControl.StateValue.on
  563. onlyTextBtn.state = NSControl.StateValue.off
  564. onlyTableBtn.state = NSControl.StateValue.off
  565. tableMenu.isEnabled = false
  566. allContentMenu.isEnabled = true
  567. excelContentOption = .allContent
  568. transform(withString: allContentMenu.selectedItem?.title ?? "")
  569. }
  570. }
  571. @IBAction func buttonClicked_tableMenu(_ sender: NSPopUpButton) {
  572. transform(withString: self.tableMenu.selectedItem!.title)
  573. }
  574. @IBAction func buttonClickec_allContentMenu(_ sender: NSButton) {
  575. transform(withString: self.allContentMenu.selectedItem!.title)
  576. }
  577. func intConvertType(num: Int) -> KMConvertWithPDFType {
  578. var type: KMConvertWithPDFType?
  579. switch num {
  580. case 0:
  581. type = .WordAdvance
  582. case 1:
  583. type = .WordStandard
  584. case 2:
  585. type = .Excel
  586. case 3:
  587. type = .PowerPoint
  588. case 4:
  589. type = .RTF
  590. case 5:
  591. type = .CSV
  592. case 6:
  593. type = .HTML
  594. case 7:
  595. type = .Text
  596. case 8:
  597. type = .JPEG
  598. case 9:
  599. type = .JPG
  600. case 10:
  601. type = .PNG
  602. case 11:
  603. type = .GIF
  604. case 12:
  605. type = .TIFF
  606. case 13:
  607. type = .TGA
  608. case 14:
  609. type = .BMP
  610. case 15:
  611. type = .JPEG2000
  612. case 16:
  613. type = .Json
  614. default:
  615. type = .WordAdvance
  616. }
  617. return type!
  618. }
  619. func moreConvertInfoAction() {
  620. if KMMemberInfo.shared.isPermitConvert == false {
  621. #if VERSION_DMG
  622. if KMMemberInfo.shared.isMemberAllFunction && KMMemberInfo.shared.isPermitConvert == false {
  623. let limitWC = KMPurchaseLimitWindowController.currentLimitWC()
  624. limitWC.continueBlock = { windowController in
  625. }
  626. limitWC.window?.center()
  627. limitWC.showWindow(nil)
  628. }else{
  629. KMProductCompareWC.shared.orientation = false
  630. let winC = KMProductCompareWC.shared
  631. if let viewC = self.view.window?.contentViewController, viewC.kEventTag == 1 {
  632. winC.kEventName = "Onbrd_ConvertPDF_BuyNow"
  633. } else {
  634. if convertType == .WordStandard || convertType == .WordAdvance {
  635. winC.kEventName = "Onbrd_PDFtoWord_BuyNow"
  636. } else if convertType == .Excel {
  637. winC.kEventName = "Onbrd_PDFtoExcel_BuyNow"
  638. } else if convertType == .PowerPoint {
  639. winC.kEventName = "Onbrd_PDFtoPPT_BuyNow"
  640. }
  641. }
  642. winC.showWindow(nil)
  643. }
  644. #else
  645. if KMMemberInfo.shared.isPermitConvert {
  646. self.convertActionVC()
  647. } else {
  648. KMMemberInfo.shared.advancedFunctionUsage()
  649. }
  650. #endif
  651. }
  652. }
  653. @IBAction func buttonClicked_FormatSelect(_ sender: NSButton) {
  654. guard let item = self.formatSelectButton.selectedItem else { return }
  655. convertType = KMConvertWithPDFType(rawValue: item.tag) ?? .WordAdvance
  656. updateBottomView()
  657. }
  658. @IBAction func comboxClicked_OcrLanguage(_ sender: AnyObject?) {
  659. switch (ocrLanguageBox.indexOfSelectedItem) {
  660. case 0: //chinese
  661. self.ocrLanguage_ = .chinese
  662. break
  663. case 1: //chinese zht
  664. self.ocrLanguage_ = .chineseTraditional
  665. break
  666. case 2: //English
  667. self.ocrLanguage_ = .english
  668. break
  669. case 3:
  670. //Japanese
  671. self.ocrLanguage_ = .japanese
  672. break
  673. case 4:
  674. //Kroean
  675. self.ocrLanguage_ = .korean
  676. break
  677. case 5:
  678. //Serbian
  679. self.ocrLanguage_ = .serbian
  680. break
  681. case 6:
  682. //Occitan
  683. self.ocrLanguage_ = .occitan
  684. break
  685. case 7:
  686. //Danish
  687. self.ocrLanguage_ = .danish
  688. break
  689. case 8:
  690. //German
  691. self.ocrLanguage_ = .german
  692. break
  693. case 9:
  694. //French
  695. self.ocrLanguage_ = .french
  696. break
  697. case 10:
  698. //Italian
  699. self.ocrLanguage_ = .italian
  700. break
  701. case 11:
  702. //Spanish
  703. self.ocrLanguage_ = .spanish
  704. break
  705. case 12:
  706. //Portuguese
  707. self.ocrLanguage_ = .portuguese
  708. break
  709. case 13:
  710. //Maori
  711. self.ocrLanguage_ = .maori
  712. break
  713. case 14:
  714. //Malay
  715. self.ocrLanguage_ = .malay
  716. break
  717. case 15:
  718. //Malay
  719. self.ocrLanguage_ = .maltese
  720. break
  721. case 16:
  722. //Dutch
  723. self.ocrLanguage_ = .dutch
  724. break
  725. case 17:
  726. //Norwegian
  727. self.ocrLanguage_ = .norwegian
  728. break
  729. case 18:
  730. //Polish
  731. self.ocrLanguage_ = .polish
  732. break
  733. case 19:
  734. //Romanian
  735. self.ocrLanguage_ = .romanian
  736. break
  737. case 20:
  738. //Slovak
  739. self.ocrLanguage_ = .slovak
  740. break
  741. case 21:
  742. //Slovenian
  743. self.ocrLanguage_ = .slovenian
  744. break
  745. case 22:
  746. //Albanian
  747. self.ocrLanguage_ = .albanian
  748. break
  749. case 23:
  750. //Swedish
  751. self.ocrLanguage_ = .swedish
  752. break
  753. case 24:
  754. //Swahili
  755. self.ocrLanguage_ = .swahili
  756. break
  757. case 25:
  758. //Tagalog
  759. self.ocrLanguage_ = .tagalog
  760. break
  761. case 26:
  762. //Turish
  763. self.ocrLanguage_ = .turish
  764. break
  765. case 27:
  766. //Uzbek
  767. self.ocrLanguage_ = .uzbek
  768. break
  769. case 28:
  770. //Vietnamese
  771. self.ocrLanguage_ = .vietnamese
  772. break
  773. case 29:
  774. //Afrikaans
  775. self.ocrLanguage_ = .afrikaans
  776. break
  777. case 30:
  778. //Azerbaijani
  779. self.ocrLanguage_ = .azerbaijani
  780. break
  781. case 31:
  782. //Bosnian
  783. self.ocrLanguage_ = .bosnian
  784. break
  785. case 32:
  786. //Czech
  787. self.ocrLanguage_ = .czech
  788. break
  789. case 33: //Welsh
  790. self.ocrLanguage_ = .welsh
  791. break
  792. case 34: //Estonian
  793. self.ocrLanguage_ = .estonian
  794. break
  795. case 35: //Irish
  796. self.ocrLanguage_ = .irish
  797. break
  798. case 36: //Croatian
  799. self.ocrLanguage_ = .croatian
  800. break
  801. case 37: //Hungarian
  802. self.ocrLanguage_ = .hungarian
  803. break
  804. case 38: //Indonesian
  805. self.ocrLanguage_ = .indonesian
  806. break
  807. case 39: //Icelandic
  808. self.ocrLanguage_ = .icelandic
  809. break
  810. case 40: //Kurdish
  811. self.ocrLanguage_ = .kurdish
  812. break
  813. case 41: //Lithuanian
  814. self.ocrLanguage_ = .lithuanian
  815. break
  816. case 42: //Latvian
  817. self.ocrLanguage_ = .latvian
  818. break
  819. case 43: //Marathi
  820. self.ocrLanguage_ = .marathi
  821. break
  822. case 44: //Nepali
  823. self.ocrLanguage_ = .nepali
  824. break
  825. case 45: //Latvia
  826. self.ocrLanguage_ = .latvian
  827. break
  828. case 46: //Bihari
  829. self.ocrLanguage_ = .bihari
  830. break
  831. case 47: //Maithili
  832. self.ocrLanguage_ = .maithili
  833. break
  834. case 48: //Angika
  835. self.ocrLanguage_ = .angika
  836. break
  837. case 49: //Bhojpuri
  838. self.ocrLanguage_ = .bhojpuri
  839. break
  840. case 50: //Magahi
  841. self.ocrLanguage_ = .magahi
  842. break
  843. case 51: //Nagpur
  844. self.ocrLanguage_ = .nagpur
  845. break
  846. case 52: //Newari
  847. self.ocrLanguage_ = .newari
  848. break
  849. case 53: //GoanKonkani
  850. self.ocrLanguage_ = .goanKonkani
  851. break
  852. case 54: //SaudiArabia
  853. self.ocrLanguage_ = .saudiArabia
  854. break
  855. default:
  856. self.ocrLanguage_ = .english
  857. break
  858. }
  859. }
  860. @IBAction func comboxClicked_SupoortOCR(_ sender: AnyObject?) {
  861. if(ocrButton.state == .on) {
  862. ocrLabel.textColor = KMAppearance.titleColor()
  863. ocrLanguageBox.isEnabled = true
  864. } else {
  865. ocrLabel.textColor = KMAppearance.Layout.h2Color()
  866. ocrLanguageBox.isEnabled = false
  867. }
  868. }
  869. }