Browse Source

转档-整理代码

tangchao 1 year ago
parent
commit
20baddbb5a

+ 51 - 43
PDF Office/PDF Master/Class/PDFTools/Convert/Common/KMPDFConvert.swift

@@ -384,6 +384,11 @@ class KMPDFConvertImage: KMPDFConvert {
 }
 
 class KMPDFConvertPPT: KMPDFConvert {
+    override init() {
+        super.init()
+        
+        self.convertType = .ppt
+    }
     
     override func startConvert() {
         if self.pathExtension.isEmpty {
@@ -391,32 +396,38 @@ class KMPDFConvertPPT: KMPDFConvert {
             return
         }
         
-        if (self.convertType == .ppt) {
-            self.converter = CPDFConverterPPT(url: URL(fileURLWithPath: self.filePath), password: self.password)
-            self.converter.delegate = self
-            self.converter.convert(toFilePath: self.outputFilePath, pageIndexs: self.pages, options: nil)
-            return
-        }
+        self.converter = CPDFConverterPPT(url: URL(fileURLWithPath: self.filePath), password: self.password)
+        self.converter.delegate = self
+        self.converter.convert(toFilePath: self.outputFilePath, pageIndexs: self.pages, options: nil)
     }
 }
 
 class KMPDFConvertText: KMPDFConvert {
+    override init() {
+        super.init()
+        
+        self.convertType = .text
+    }
+    
     override func startConvert() {
         if self.pathExtension.isEmpty {
             self.convertSuccessful(isSuccessful: false, errorInfo: nil)
             return
         }
         
-        if (self.convertType == .text) {
-            self.converter = CPDFConverterTxt(url: URL(fileURLWithPath: self.filePath), password: self.password)
-            self.converter.delegate = self
-            self.converter.convert(toFilePath: self.outputFilePath, pageIndexs: self.pages, options: nil)
-            return
-        }
+        self.converter = CPDFConverterTxt(url: URL(fileURLWithPath: self.filePath), password: self.password)
+        self.converter.delegate = self
+        self.converter.convert(toFilePath: self.outputFilePath, pageIndexs: self.pages, options: nil)
     }
 }
 
 class KMPDFConvertCSV: KMPDFConvert {
+    override init() {
+        super.init()
+        
+        self.convertType = .csv
+    }
+    
     override func startConvert() {
         if self.pathExtension.isEmpty {
             self.convertSuccessful(isSuccessful: false, errorInfo: nil)
@@ -439,46 +450,43 @@ class KMPDFConvertCSV: KMPDFConvert {
 }
 
 class KMPDFConvertExcel: KMPDFConvert {
+    override init() {
+        super.init()
+        
+        self.convertType = .excel
+    }
+    
     override func startConvert() {
-        if self.pathExtension.isEmpty {
+        if (self.pathExtension.isEmpty) {
             self.convertSuccessful(isSuccessful: false, errorInfo: nil)
             return
         }
         
-        if (self.convertType == .excel) {
-            self.converter = CPDFConverterExcel(url: URL(fileURLWithPath: self.filePath), password: self.password)
-            self.converter.delegate = self
-
-            let options = CPDFConvertExcelOptions()
-            if (self.isExtractText) {
-                options.contentOptions = .onlyText
-            } else if (self.isExtractTable) {
-                options.contentOptions = .onlyTable
-                if (self.extractTableIndex == 0) {
-                    options.worksheetOptions = .forEachTable
-                } else if (self.extractTableIndex == 1) {
-                    options.worksheetOptions = .forEachPage
-                } else if (self.extractTableIndex == 2) {
-                    options.worksheetOptions = .forTheDocument
-                }
+        self.converter = CPDFConverterExcel(url: URL(fileURLWithPath: self.filePath), password: self.password)
+        self.converter.delegate = self
+        
+        let options = CPDFConvertExcelOptions()
+        if (self.isExtractText) {
+            options.contentOptions = .onlyText
+        } else if (self.isExtractTable) {
+            options.contentOptions = .onlyTable
+            if (self.extractTableIndex == 0) {
+                options.worksheetOptions = .forEachTable
+            } else if (self.extractTableIndex == 1) {
+                options.worksheetOptions = .forEachPage
+            } else if (self.extractTableIndex == 2) {
+                options.worksheetOptions = .forTheDocument
+            }
+        } else {
+            options.contentOptions = .allContent
+            if (self.isAllInOneSheet) {
+                options.worksheetOptions = .forTheDocument
             } else {
-                options.contentOptions = .allContent
-                if (self.isAllInOneSheet) {
-                    options.worksheetOptions = .forTheDocument
-                } else {
-                    options.worksheetOptions = .forEachPage
-                }
+                options.worksheetOptions = .forEachPage
             }
-            
-            self.converter.convert(toFilePath: self.outputFilePath, pageIndexs: self.pages, options: options)
-            return
         }
         
-        self.fpPDFConverter = CPDFConverterFP()
-        self.fpPDFConverter.setDelegate(self)
-
-        let options: [String : Any] = [CPDFConvertOptionsKey.allInOneSheet.rawValue : self.isAllInOneSheet]
-        self.fpPDFConverter.convertPDF(atPath: self.filePath, pdfPassword: self.password, pdfPageIndexs: self.pages, destDocType: self.pathExtension, destDocPath: self.outputFilePath, moreOptions: options)
+        self.converter.convert(toFilePath: self.outputFilePath, pageIndexs: self.pages, options: options)
     }
 }
 

+ 0 - 1
PDF Office/PDF Master/Class/PDFTools/Convert/Controller/KMConvertCSVWindowController.swift

@@ -58,7 +58,6 @@ class KMConvertCSVWindowController: KMConvertBaseWindowController {
     }
     
     override func convertModelAppendParams(convert: KMPDFConvert) {
-        convert.convertType = .csv
         let settingView: KMConvertCSVSettingView = self.settingView as! KMConvertCSVSettingView
         if settingView.selectedSettingIndex == 0 {
             convert.isExtractTable = false

+ 0 - 1
PDF Office/PDF Master/Class/PDFTools/Convert/Controller/KMConvertExcelWindowController.swift

@@ -78,7 +78,6 @@ class KMConvertExcelWindowController: KMConvertBaseWindowController {
             convert.isExtractTable = false
             convert.isExtractText = true
         }
-        convert.convertType = .excel
     }
     
 }

+ 2 - 6
PDF Office/PDF Master/Class/PDFTools/Convert/Controller/KMConvertPPTsWindowController.swift

@@ -83,15 +83,11 @@ class KMConvertPPTsWindowController: KMConvertBaseWindowController {
     }
     
     override func convertModelAppendParams(convert: KMPDFConvert) {
-        if (self.subType == 1) {
-            convert.convertType = .ppt
-        } else if (self.subType == 2) {
+        if (self.subType == 2) {
             convert.convertType = .rtf
         } else if (self.subType == 3) {
             convert.convertType = .html
-        } else if (self.subType == 4) {
-            convert.convertType = .text
-        }
+        } 
     }
     
 }