KMBatchConvertParameter.swift 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //
  2. // KMBatchConvertParameter.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by kdanmobile on 2023/10/25.
  6. //
  7. import Cocoa
  8. class KMBatchConvertParameter: KMBatchBaseParameter {
  9. var convertType: KMConvertWithPDFType?
  10. var allInOneSheet: Bool? // FP转excel用
  11. var isExtreactTabel: Bool? // Com_converter 转excel用
  12. var isRetainLayout: Bool? // NO 为流排
  13. var dpi: Int? // 转图片用
  14. // var extensionString: String = "" // FP方式转换需要用到
  15. var excelContentOption: CPDFConvertExcelContentOptions?
  16. var excelWorksheetOption: CPDFConvertExcelWorksheetOptions?
  17. // 是否使用OCR
  18. var isAllowOCR = false
  19. var ocrLanguage: COCRLanguage?
  20. override init(file:KMBatchOperateFile) {
  21. super.init(file: file)
  22. self.dpi = 150
  23. }
  24. func extensionString() -> String? {
  25. var rtString: String? = nil
  26. if self.convertType == .WordStandard || self.convertType == .WordAdvance {
  27. rtString = "docx"
  28. } else if self.convertType == .Excel {
  29. rtString = "xlsx"
  30. } else if self.convertType == .PowerPoint {
  31. rtString = "pptx"
  32. } else if self.convertType == .RTF {
  33. rtString = "rtf"
  34. } else if self.convertType == .CSV {
  35. rtString = "csv"
  36. } else if self.convertType == .HTML {
  37. rtString = "html"
  38. } else if self.convertType == .Text {
  39. rtString = "txt"
  40. } else if self.convertType == .JPEG {
  41. rtString = "jpeg"
  42. } else if self.convertType == .JPG {
  43. rtString = "jpg"
  44. } else if self.convertType == .PNG {
  45. rtString = "png"
  46. } else if self.convertType == .GIF {
  47. rtString = "gif"
  48. } else if self.convertType == .TGA {
  49. rtString = "tga"
  50. } else if self.convertType == .BMP {
  51. rtString = "bmp"
  52. } else if self.convertType == .TIFF {
  53. rtString = "tiff"
  54. } else if self.convertType == .JPEG2000 {
  55. rtString = "jp2"
  56. } else if self.convertType == .Json {
  57. rtString = "json"
  58. }
  59. return rtString
  60. }
  61. override func fetchDestinationFilepath() -> String? {
  62. if self.savePath?.count ?? 0 > 0 && self.operateFile?.filePath.count ?? 0 > 0{
  63. if self.convertType == .JPEG || self.convertType == .CSV || self.convertType == .JPG || self.convertType == .PNG || self.convertType == .GIF || self.convertType == .TIFF || self.convertType == .TGA || self.convertType == .BMP || self.convertType == .JPEG2000{
  64. self.outPutPath = self.getUniqueFilePath(filePath: self.savePath!.stringByAppendingPathComponent(self.operateFile!.filePath.deletingPathExtension.lastPathComponent))
  65. if self.operateFile?.CSVParameter.isExtreactTabel ?? false {
  66. self.outPutPath = (self.outPutPath! as NSString).appendingPathExtension("zip")
  67. self.outPutPath = self.getUniqueFilePath(filePath: self.outPutPath ?? "")
  68. }
  69. return self.outPutPath
  70. } else if self.convertType == .WordStandard || self.convertType == .WordAdvance || self.convertType == .Excel || self.convertType == .PowerPoint || self.convertType == .RTF || self.convertType == .HTML || self.convertType == .Text || self.convertType == .Json {
  71. let filePath1 = self.savePath?.stringByAppendingPathComponent(self.operateFile!.filePath.getLastComponentDeleteExtension)
  72. self.outPutPath = self.getUniqueFilePath(filePath: filePath1!.stringByAppendingPathExtension(self.extensionString()!))
  73. return self.outPutPath
  74. }
  75. }
  76. return nil
  77. }
  78. override var outPutPath: String? {
  79. set {
  80. super.outPutPath = newValue
  81. }
  82. get {
  83. let existOutPutPath = super.outPutPath
  84. if ((existOutPutPath?.isEmpty) != nil){
  85. if ((self.savePath?.isEmpty) == nil) && ((self.operateFile?.filePath.isEmpty) == nil) {
  86. if self.convertType == .JPEG || self.convertType == .CSV || self.convertType == .JPG || self.convertType == .PNG || self.convertType == .GIF || self.convertType == .TIFF || self.convertType == .TGA || self.convertType == .BMP || self.convertType == .JPEG2000{
  87. return self.getUniqueFilePath(filePath: self.savePath!.stringByAppendingPathComponent(self.operateFile!.filePath.lastPathComponent.deletingPathExtension))
  88. } else if self.convertType == .WordStandard ||
  89. self.convertType == .WordAdvance ||
  90. self.convertType == .Excel ||
  91. self.convertType == .PowerPoint ||
  92. self.convertType == .RTF ||
  93. self.convertType == .HTML ||
  94. self.convertType == .Text || self.convertType == .Json {
  95. let filePath1 = self.savePath!.stringByAppendingPathComponent(self.operateFile!.filePath.lastPathComponent.deletingPathExtension)
  96. return self.getUniqueFilePath(filePath: filePath1.stringByAppendingPathExtension(self.extensionString()!))
  97. }
  98. }
  99. }
  100. return super.outPutPath
  101. }
  102. }
  103. override var pagesArray: [NSNumber]? {
  104. let fullpagesArray = fetchUnlimitPagesArray()
  105. var isLimitConvert = false
  106. #if VERSION_FREE
  107. // 桌机版
  108. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
  109. isLimitConvert = false
  110. } else {
  111. if .PNG == self.convertType ||
  112. .JPEG == self.convertType ||
  113. .JPG == self.convertType ||
  114. .HTML == self.convertType ||
  115. .Text == self.convertType ||
  116. .WordStandard == self.convertType {
  117. isLimitConvert = false
  118. } else {
  119. isLimitConvert = true
  120. }
  121. }
  122. #else
  123. // 付费版
  124. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
  125. isLimitConvert = false
  126. } else {
  127. if .PNG == self.convertType ||
  128. .JPEG == self.convertType ||
  129. .JPG == self.convertType ||
  130. .HTML == self.convertType ||
  131. .Text == self.convertType ||
  132. .WordStandard == self.convertType {
  133. isLimitConvert = false
  134. } else {
  135. isLimitConvert = true
  136. }
  137. }
  138. #endif
  139. if isLimitConvert {
  140. if let cnt = fullpagesArray?.count, cnt > 10 {
  141. var newArr: [NSNumber] = []
  142. for i in 0 ..< 10 {
  143. let item = fullpagesArray![i]
  144. newArr.append(item)
  145. }
  146. return newArr
  147. } else {
  148. return fullpagesArray
  149. }
  150. }
  151. return fullpagesArray
  152. }
  153. }