123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- //
- // KMBatchConvertParameter.swift
- // PDF Reader Pro
- //
- // Created by kdanmobile on 2023/10/25.
- //
- import Cocoa
- class KMBatchConvertParameter: KMBatchBaseParameter {
- var convertType: KMConvertWithPDFType?
- var allInOneSheet: Bool? // FP转excel用
- var isExtreactTabel: Bool? // Com_converter 转excel用
- var isRetainLayout: Bool? // NO 为流排
- var dpi: Int? // 转图片用
- // var extensionString: String = "" // FP方式转换需要用到
- var excelContentOption: CPDFConvertExcelContentOptions?
- var excelWorksheetOption: CPDFConvertExcelWorksheetOptions?
-
- // 是否使用OCR
- var isAllowOCR = false
- var ocrLanguage: COCRLanguage?
-
- override init(file:KMBatchOperateFile) {
- super.init(file: file)
- self.dpi = 150
- }
- func extensionString() -> String? {
- var rtString: String? = nil
- if self.convertType == .WordStandard || self.convertType == .WordAdvance {
- rtString = "docx"
- } else if self.convertType == .Excel {
- rtString = "xlsx"
- } else if self.convertType == .PowerPoint {
- rtString = "pptx"
- } else if self.convertType == .RTF {
- rtString = "rtf"
- } else if self.convertType == .CSV {
- rtString = "csv"
- } else if self.convertType == .HTML {
- rtString = "html"
- } else if self.convertType == .Text {
- rtString = "txt"
- } else if self.convertType == .JPEG {
- rtString = "jpeg"
- } else if self.convertType == .JPG {
- rtString = "jpg"
- } else if self.convertType == .PNG {
- rtString = "png"
- } else if self.convertType == .GIF {
- rtString = "gif"
- } else if self.convertType == .TGA {
- rtString = "tga"
- } else if self.convertType == .BMP {
- rtString = "bmp"
- } else if self.convertType == .TIFF {
- rtString = "tiff"
- } else if self.convertType == .JPEG2000 {
- rtString = "jp2"
- } else if self.convertType == .Json {
- rtString = "json"
- }
- return rtString
- }
- override func fetchDestinationFilepath() -> String? {
- if self.savePath?.count ?? 0 > 0 && self.operateFile?.filePath.count ?? 0 > 0{
- 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{
- self.outPutPath = self.getUniqueFilePath(filePath: self.savePath!.stringByAppendingPathComponent(self.operateFile!.filePath.deletingPathExtension.lastPathComponent))
- if self.operateFile?.CSVParameter.isExtreactTabel ?? false {
- self.outPutPath = (self.outPutPath! as NSString).appendingPathExtension("zip")
- self.outPutPath = self.getUniqueFilePath(filePath: self.outPutPath ?? "")
- }
- return self.outPutPath
- } 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 {
- let filePath1 = self.savePath?.stringByAppendingPathComponent(self.operateFile!.filePath.getLastComponentDeleteExtension)
- self.outPutPath = self.getUniqueFilePath(filePath: filePath1!.stringByAppendingPathExtension(self.extensionString()!))
- return self.outPutPath
- }
- }
- return nil
- }
- override var outPutPath: String? {
- set {
- super.outPutPath = newValue
- }
- get {
- let existOutPutPath = super.outPutPath
- if ((existOutPutPath?.isEmpty) != nil){
- if ((self.savePath?.isEmpty) == nil) && ((self.operateFile?.filePath.isEmpty) == nil) {
- 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{
- return self.getUniqueFilePath(filePath: self.savePath!.stringByAppendingPathComponent(self.operateFile!.filePath.lastPathComponent.deletingPathExtension))
- } 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 {
- let filePath1 = self.savePath!.stringByAppendingPathComponent(self.operateFile!.filePath.lastPathComponent.deletingPathExtension)
- return self.getUniqueFilePath(filePath: filePath1.stringByAppendingPathExtension(self.extensionString()!))
- }
- }
- }
- return super.outPutPath
- }
- }
- override var pagesArray: [NSNumber]? {
- let fullpagesArray = fetchUnlimitPagesArray()
- var isLimitConvert = false
- #if VERSION_FREE
- // 桌机版
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- isLimitConvert = false
- } else {
- if .PNG == self.convertType ||
- .JPEG == self.convertType ||
- .JPG == self.convertType ||
- .HTML == self.convertType ||
- .Text == self.convertType ||
- .WordStandard == self.convertType {
- isLimitConvert = false
- } else {
- isLimitConvert = true
- }
- }
- #else
- // 付费版
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- isLimitConvert = false
- } else {
- if .PNG == self.convertType ||
- .JPEG == self.convertType ||
- .JPG == self.convertType ||
- .HTML == self.convertType ||
- .Text == self.convertType ||
- .WordStandard == self.convertType {
- isLimitConvert = false
- } else {
- isLimitConvert = true
- }
- }
- #endif
-
- if isLimitConvert {
- if let cnt = fullpagesArray?.count, cnt > 10 {
- var newArr: [NSNumber] = []
- for i in 0 ..< 10 {
- let item = fullpagesArray![i]
- newArr.append(item)
- }
- return newArr
- } else {
- return fullpagesArray
- }
- }
- return fullpagesArray
- }
- }
|