|
@@ -18,10 +18,10 @@ let KMPDFConvertOptionsKeyImageWithAnnotation = "KMPDFConvertOptionsKeyImageWith
|
|
|
|
|
|
let kDefaultPassword = "666666"
|
|
|
|
|
|
-class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
|
-
|
|
|
+class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPToolDelegate
|
|
|
+{
|
|
|
var pdfConverter:CPDFConverter?
|
|
|
- var fpConverter:CPDFConverterFP?
|
|
|
+ var fpConverter:AnyObject?
|
|
|
var options:CPDFConvertOptions?
|
|
|
|
|
|
var originSrcPath:String = ""
|
|
@@ -100,7 +100,6 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
|
}
|
|
|
|
|
|
// NSLog("%@ - %@\n\(inSrcPath)", useOldLib ? "老库" : "新库", params ?? "")
|
|
|
-
|
|
|
self.convertQueue.async {
|
|
|
if (LogViewController.shared().isVisable()) {
|
|
|
LogViewController.shared().appendLog("\n转档:\(NSString(string: inSrcPath).lastPathComponent)\n")
|
|
@@ -110,6 +109,7 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
|
let document = PDFDocument(url: url)
|
|
|
if document == nil {
|
|
|
self.didSuccess = -2;
|
|
|
+ self.complention(self.didSuccess)
|
|
|
self.accessSemaphore?.signal()
|
|
|
return
|
|
|
}
|
|
@@ -144,6 +144,7 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
|
self.didSuccess = -1;
|
|
|
|
|
|
self.complention(self.didSuccess)
|
|
|
+ self.accessSemaphore?.signal()
|
|
|
}
|
|
|
}
|
|
|
}else if !useOldLib && NSArray(array: ["ppt", "PPT", "PPTX", "pptx"]).contains(self.pathExtension) {
|
|
@@ -241,37 +242,46 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
|
}
|
|
|
}else {
|
|
|
autoreleasepool {
|
|
|
- if self.fpConverter == nil {
|
|
|
- self.fpConverter = CPDFConverterFP.init()
|
|
|
- self.fpConverter?.setDelegate(self)
|
|
|
- }else {
|
|
|
- self.fpConverter?.stopConvertsionIfNeed()
|
|
|
- }
|
|
|
-
|
|
|
- var needMerge = NSArray(array: ["csv", "CSV"]).contains(self.pathExtension)
|
|
|
- let dpi = tParams.value(forKey: "KMPDFConvertOptionsKeyImageDPI")
|
|
|
- if (needMerge && tParams.value(forKey: "CPDFConvertOptionsKeyAllInOneSheet") != nil) {
|
|
|
- needMerge = (tParams.value(forKey: "CPDFConvertOptionsKeyAllInOneSheet") as! NSNumber).boolValue
|
|
|
- }
|
|
|
+ let className = "CPDFConverterFP"
|
|
|
+ let cl = NSClassFromString(className)
|
|
|
|
|
|
- if (LogViewController.shared().isVisable()) {
|
|
|
- LogViewController.shared().appendLog("转档参数\n")
|
|
|
- LogViewController.shared().appendLog("- 库版本: 老库\n")
|
|
|
- let options = [
|
|
|
- "KMPDFConvertOptionsKeyImageDPI" : (dpi as? String) ?? "72",
|
|
|
- "CPDFConvertOptionsKeyAllInOneSheet":NSNumber(booleanLiteral: needMerge)
|
|
|
- ]
|
|
|
- LogViewController.shared().appendLog("- 其它参数:\(options)\n")
|
|
|
+ if (nil == cl) {
|
|
|
+ self.complention(-1)
|
|
|
+ self.accessSemaphore?.signal()
|
|
|
+ }else {
|
|
|
+ if self.fpConverter == nil {
|
|
|
+ self.fpConverter = CPDFConverterFPTool.createConverterFP() as AnyObject
|
|
|
+ CPDFConverterFPTool.setDelegate(self, forConverterFP: self.fpConverter)
|
|
|
+ }else {
|
|
|
+ CPDFConverterFPTool.stopConvertsionIfNeed(self.fpConverter)
|
|
|
+ }
|
|
|
+
|
|
|
+ var needMerge = NSArray(array: ["csv", "CSV"]).contains(self.pathExtension)
|
|
|
+ let dpi = tParams.value(forKey: "KMPDFConvertOptionsKeyImageDPI")
|
|
|
+ if (needMerge && tParams.value(forKey: "CPDFConvertOptionsKeyAllInOneSheet") != nil) {
|
|
|
+ needMerge = (tParams.value(forKey: "CPDFConvertOptionsKeyAllInOneSheet") as! NSNumber).boolValue
|
|
|
+ }
|
|
|
+
|
|
|
+ if (LogViewController.shared().isVisable()) {
|
|
|
+ LogViewController.shared().appendLog("转档参数\n")
|
|
|
+ LogViewController.shared().appendLog("- 库版本: 老库\n")
|
|
|
+ let options = [
|
|
|
+ "KMPDFConvertOptionsKeyImageDPI" : (dpi as? String) ?? "72",
|
|
|
+ "CPDFConvertOptionsKeyAllInOneSheet":NSNumber(booleanLiteral: needMerge)
|
|
|
+ ]
|
|
|
+ LogViewController.shared().appendLog("- 其它参数:\(options)\n")
|
|
|
+ }
|
|
|
+ CPDFConverterFPTool.convertPDF(forConverterFP: self.fpConverter,
|
|
|
+ path: self.srcPath,
|
|
|
+ pdfPassword: password as? String,
|
|
|
+ pdfPageIndexs: self.pages,
|
|
|
+ destDocType: self.pathExtension,
|
|
|
+ destDocPath: self.desPath,
|
|
|
+ moreOptions: [
|
|
|
+ "KMPDFConvertOptionsKeyImageDPI" : (dpi as? String) ?? "72",
|
|
|
+ "CPDFConvertOptionsKeyAllInOneSheet":NSNumber(booleanLiteral: needMerge)
|
|
|
+ ])
|
|
|
}
|
|
|
- self.fpConverter?.convertPDF(atPath: self.srcPath,
|
|
|
- pdfPassword: password as? String,
|
|
|
- pdfPageIndexs: self.pages,
|
|
|
- destDocType: self.pathExtension,
|
|
|
- destDocPath: self.desPath,
|
|
|
- moreOptions: [
|
|
|
- "KMPDFConvertOptionsKeyImageDPI" : (dpi as? String) ?? "72",
|
|
|
- "CPDFConvertOptionsKeyAllInOneSheet":NSNumber(booleanLiteral: needMerge)
|
|
|
- ])
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -339,7 +349,7 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
|
func fppdfConverter(_ converter: Any!, didEndConversion error: Error!) {
|
|
|
autoreleasepool {
|
|
|
didSuccess = nil == error ? 1 : 0
|
|
|
- self.fpConverter?.stopConvertsionIfNeed()
|
|
|
+ CPDFConverterFPTool.stopConvertsionIfNeed(self.fpConverter)
|
|
|
self.fpConverter = nil;
|
|
|
|
|
|
Thread.sleep(forTimeInterval: 0.3)
|
|
@@ -352,9 +362,9 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
|
/// Cancel
|
|
|
func cancelTask() {
|
|
|
if (self.fpConverter != nil) {
|
|
|
- self.fpConverter!.stopConvertsionIfNeed()
|
|
|
+ CPDFConverterFPTool.stopConvertsionIfNeed(self.fpConverter)
|
|
|
self.fpConverter = nil;
|
|
|
-
|
|
|
+
|
|
|
Thread.sleep(forTimeInterval: 0.3)
|
|
|
}
|
|
|
if (self.pdfConverter != nil) {
|