KMBatchConvertParameter.swift 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. override init(file:KMBatchOperateFile) {
  18. super.init(file: file)
  19. self.dpi = 150
  20. }
  21. func extensionString() -> String? {
  22. var rtString: String? = nil
  23. if self.convertType == .WordStandard || self.convertType == .WordAdvance {
  24. rtString = "docx"
  25. } else if self.convertType == .Excel {
  26. rtString = "xlsx"
  27. } else if self.convertType == .PowerPoint {
  28. rtString = "pptx"
  29. } else if self.convertType == .RTF {
  30. rtString = "rtf"
  31. } else if self.convertType == .CSV {
  32. rtString = "csv"
  33. } else if self.convertType == .HTML {
  34. rtString = "html"
  35. } else if self.convertType == .Text {
  36. rtString = "txt"
  37. } else if self.convertType == .JPEG {
  38. rtString = "jpeg"
  39. } else if self.convertType == .JPG {
  40. rtString = "jpg"
  41. } else if self.convertType == .PNG {
  42. rtString = "png"
  43. } else if self.convertType == .GIF {
  44. rtString = "gif"
  45. } else if self.convertType == .TGA {
  46. rtString = "tga"
  47. } else if self.convertType == .BMP {
  48. rtString = "bmp"
  49. } else if self.convertType == .TIFF {
  50. rtString = "tiff"
  51. } else if self.convertType == .JPEG2000 {
  52. rtString = "jp2"
  53. }
  54. return rtString
  55. }
  56. override func fetchDestinationFilepath() -> String? {
  57. if self.savePath?.count ?? 0 > 0 && self.operateFile?.filePath.count ?? 0 > 0{
  58. 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{
  59. self.outPutPath = self.getUniqueFilePath(filePath: self.savePath!.stringByAppendingPathComponent(self.operateFile!.filePath.deletingPathExtension.lastPathComponent))
  60. if self.operateFile?.CSVParameter.isExtreactTabel ?? false {
  61. self.outPutPath = (self.outPutPath! as NSString).appendingPathExtension("zip")
  62. self.outPutPath = self.getUniqueFilePath(filePath: self.outPutPath ?? "")
  63. }
  64. return self.outPutPath
  65. } else if self.convertType == .WordStandard || self.convertType == .WordAdvance || self.convertType == .Excel || self.convertType == .PowerPoint || self.convertType == .RTF || self.convertType == .HTML || self.convertType == .Text {
  66. let filePath1 = self.savePath?.stringByAppendingPathComponent(self.operateFile!.filePath.getLastComponentDeleteExtension)
  67. self.outPutPath = self.getUniqueFilePath(filePath: filePath1!.stringByAppendingPathExtension(self.extensionString()!))
  68. return self.outPutPath
  69. }
  70. }
  71. return nil
  72. }
  73. override var outPutPath: String? {
  74. set {
  75. super.outPutPath = newValue
  76. }
  77. get {
  78. let existOutPutPath = super.outPutPath
  79. if ((existOutPutPath?.isEmpty) != nil){
  80. if ((self.savePath?.isEmpty) == nil) && ((self.operateFile?.filePath.isEmpty) == nil) {
  81. 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{
  82. return self.getUniqueFilePath(filePath: self.savePath!.stringByAppendingPathComponent(self.operateFile!.filePath.lastPathComponent.deletingPathExtension))
  83. } else if self.convertType == .WordStandard ||
  84. self.convertType == .WordAdvance ||
  85. self.convertType == .Excel ||
  86. self.convertType == .PowerPoint ||
  87. self.convertType == .RTF ||
  88. self.convertType == .HTML ||
  89. self.convertType == .Text {
  90. let filePath1 = self.savePath!.stringByAppendingPathComponent(self.operateFile!.filePath.lastPathComponent.deletingPathExtension)
  91. return self.getUniqueFilePath(filePath: filePath1.stringByAppendingPathExtension(self.extensionString()!))
  92. }
  93. }
  94. }
  95. return super.outPutPath
  96. }
  97. }
  98. override var pagesArray: [NSNumber]? {
  99. let fullpagesArray = fetchUnlimitPagesArray()
  100. var isLimitConvert = false
  101. #if VERSION_FREE
  102. // 桌机版
  103. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
  104. isLimitConvert = false
  105. } else {
  106. if .PNG == self.convertType ||
  107. .JPEG == self.convertType ||
  108. .JPG == self.convertType ||
  109. .HTML == self.convertType ||
  110. .Text == self.convertType ||
  111. .WordStandard == self.convertType {
  112. isLimitConvert = false
  113. } else {
  114. isLimitConvert = true
  115. }
  116. }
  117. #else
  118. // 付费版
  119. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
  120. isLimitConvert = false
  121. } else {
  122. if .PNG == self.convertType ||
  123. .JPEG == self.convertType ||
  124. .JPG == self.convertType ||
  125. .HTML == self.convertType ||
  126. .Text == self.convertType ||
  127. .WordStandard == self.convertType {
  128. isLimitConvert = false
  129. } else {
  130. isLimitConvert = true
  131. }
  132. }
  133. #endif
  134. if isLimitConvert {
  135. if let cnt = fullpagesArray?.count, cnt > 10 {
  136. var newArr: [NSNumber] = []
  137. for i in 0 ..< 10 {
  138. let item = fullpagesArray![i]
  139. newArr.append(item)
  140. }
  141. return newArr
  142. } else {
  143. return fullpagesArray
  144. }
  145. }
  146. return fullpagesArray
  147. }
  148. }