|
@@ -35,6 +35,8 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
|
var accessSemaphore:DispatchSemaphore? = DispatchSemaphore.init(value: 1)
|
|
|
var didSuccess:Int = 1
|
|
|
|
|
|
+ let m_currentVersion = CPDFConvertKit.sharedInstance().buildNumber
|
|
|
+
|
|
|
var complention = { (status:Int) in
|
|
|
|
|
|
}
|
|
@@ -97,7 +99,7 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- NSLog("%@ - %@\n\(inSrcPath)", useOldLib ? "老库" : "新库", params ?? "")
|
|
|
+// NSLog("%@ - %@\n\(inSrcPath)", useOldLib ? "老库" : "新库", params ?? "")
|
|
|
|
|
|
self.convertQueue.async {
|
|
|
let url = URL.init(fileURLWithPath: self.srcPath, isDirectory: false)
|
|
@@ -128,13 +130,7 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
|
}else {
|
|
|
(self.options as! CPDFConvertImgOptions).type = .PNG
|
|
|
}
|
|
|
- if (params != nil) {
|
|
|
- if let dipValue = params!["imageDpi"] as? NSNumber {
|
|
|
- if (CPDFConvertKit.sharedInstance().buildNumber > 150) {
|
|
|
- try? (self.options as! CPDFConvertImgOptions).imageDpi = Int32(dipValue.intValue)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ self.configForOptions(self.options, inParams: tParams);
|
|
|
do {
|
|
|
try? self.pdfConverter?.convert(toFilePath: cachePath, pageIndexs: self.pages, options: self.options)
|
|
|
}catch {
|
|
@@ -151,6 +147,7 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
|
}
|
|
|
self.pdfConverter?.delegate = self
|
|
|
self.options = CPDFConvertPPTOptions()
|
|
|
+ self.configForOptions(self.options, inParams: tParams);
|
|
|
self.pdfConverter?.convert(toFilePath: self.desPath,
|
|
|
pageIndexs: self.pages, options: self.options)
|
|
|
}
|
|
@@ -162,6 +159,7 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
|
}
|
|
|
self.pdfConverter?.delegate = self
|
|
|
self.options = CPDFConvertWordOptions()
|
|
|
+ self.configForOptions(self.options, inParams: tParams);
|
|
|
self.pdfConverter?.convert(toFilePath: self.desPath,
|
|
|
pageIndexs: self.pages, options: self.options)
|
|
|
}
|
|
@@ -173,6 +171,7 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
|
}
|
|
|
self.pdfConverter?.delegate = self
|
|
|
self.options = CPDFConvertExcelOptions()
|
|
|
+ self.configForOptions(self.options, inParams: tParams);
|
|
|
self.pdfConverter?.convert(toFilePath: self.desPath,
|
|
|
pageIndexs: self.pages, options: self.options)
|
|
|
}
|
|
@@ -185,6 +184,7 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
|
}
|
|
|
self.pdfConverter?.delegate = self
|
|
|
self.options = CPDFConvertCsvOptions()
|
|
|
+ self.configForOptions(self.options, inParams: tParams);
|
|
|
self.pdfConverter?.convert(toFilePath: cachePath,
|
|
|
pageIndexs: self.pages, options: self.options)
|
|
|
}
|
|
@@ -197,9 +197,10 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
|
}
|
|
|
self.pdfConverter?.delegate = self
|
|
|
self.options = CPDFConvertHtmlOptions()
|
|
|
- if ((tParams.value(forKey: "paneOptions") as? NSNumber) != nil) {
|
|
|
- (self.options as! CPDFConvertHtmlOptions).paneOptions = CPDFConvertHtmlPageAndNavigationPaneOptions(rawValue: (tParams.value(forKey: "paneOptions") as! NSNumber).intValue)!
|
|
|
- }
|
|
|
+// if ((tParams.value(forKey: "paneOptions") as? NSNumber) != nil) {
|
|
|
+// (self.options as! CPDFConvertHtmlOptions).paneOptions = CPDFConvertHtmlPageAndNavigationPaneOptions(rawValue: (tParams.value(forKey: "paneOptions") as! NSNumber).intValue)!
|
|
|
+// }
|
|
|
+ self.configForOptions(self.options, inParams: tParams);
|
|
|
self.pdfConverter?.convert(toFilePath: cachePath,
|
|
|
pageIndexs: self.pages, options: self.options)
|
|
|
}
|
|
@@ -211,6 +212,7 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
|
}
|
|
|
self.pdfConverter?.delegate = self
|
|
|
self.options = CPDFConvertRtfOptions()
|
|
|
+ self.configForOptions(self.options, inParams: tParams);
|
|
|
self.pdfConverter?.convert(toFilePath: self.desPath,
|
|
|
pageIndexs: self.pages, options: self.options)
|
|
|
}
|
|
@@ -222,6 +224,7 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
|
}
|
|
|
self.pdfConverter?.delegate = self
|
|
|
self.options = CPDFConvertTxtOptions()
|
|
|
+ self.configForOptions(self.options, inParams: tParams);
|
|
|
self.pdfConverter?.convert(toFilePath: self.desPath,
|
|
|
pageIndexs: self.pages, options: self.options)
|
|
|
}
|
|
@@ -352,5 +355,39 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
|
cancelTask();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ // Config Options Tools
|
|
|
+ func configForOptions(_ inOptions:CPDFConvertOptions?, inParams:NSDictionary?) {
|
|
|
+ // Fetch Options Info
|
|
|
+ let versionInfo = NSDictionary(dictionary: (inParams?.value(forKey: "Options") as? [AnyHashable:Any]) ?? [:])
|
|
|
+
|
|
|
+ // options is not empty or nil
|
|
|
+ if (versionInfo.allKeys.count > 0) {
|
|
|
+ var allVersions = versionInfo.allKeys
|
|
|
+
|
|
|
+ // Sort versions (by release date)
|
|
|
+ allVersions = allVersions.sorted(by: { version1, version2 in
|
|
|
+ let value1 = NSString(string: version1 as! String).integerValue
|
|
|
+ let value2 = NSString(string: version2 as! String).integerValue
|
|
|
+
|
|
|
+ return (value1 > value2);
|
|
|
+ });
|
|
|
+
|
|
|
+ NSLog("\(allVersions)");
|
|
|
+
|
|
|
+ for version in allVersions {
|
|
|
+ if (self.m_currentVersion >= NSString(string: version as! String).integerValue) {
|
|
|
+ // config params for version
|
|
|
+ let prams = versionInfo.value(forKey: version as! String) as! NSArray
|
|
|
+
|
|
|
+ for param in prams {
|
|
|
+ PerformSelectTool.performSelector(inOptions as Any, params: param as! [AnyHashable : Any]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|