|
@@ -18,10 +18,10 @@ let KMPDFConvertOptionsKeyImageWithAnnotation = "KMPDFConvertOptionsKeyImageWith
|
|
|
|
|
|
let kDefaultPassword = "666666"
|
|
let kDefaultPassword = "666666"
|
|
|
|
|
|
-class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
|
|
-
|
|
|
|
|
|
+class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPToolDelegate
|
|
|
|
+{
|
|
var pdfConverter:CPDFConverter?
|
|
var pdfConverter:CPDFConverter?
|
|
- var fpConverter:CPDFConverterFP?
|
|
|
|
|
|
+ var fpConverter:AnyObject?
|
|
var options:CPDFConvertOptions?
|
|
var options:CPDFConvertOptions?
|
|
|
|
|
|
var originSrcPath:String = ""
|
|
var originSrcPath:String = ""
|
|
@@ -100,7 +100,6 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
}
|
|
}
|
|
|
|
|
|
// NSLog("%@ - %@\n\(inSrcPath)", useOldLib ? "老库" : "新库", params ?? "")
|
|
// NSLog("%@ - %@\n\(inSrcPath)", useOldLib ? "老库" : "新库", params ?? "")
|
|
-
|
|
|
|
self.convertQueue.async {
|
|
self.convertQueue.async {
|
|
if (LogViewController.shared().isVisable()) {
|
|
if (LogViewController.shared().isVisable()) {
|
|
LogViewController.shared().appendLog("\n转档:\(NSString(string: inSrcPath).lastPathComponent)\n")
|
|
LogViewController.shared().appendLog("\n转档:\(NSString(string: inSrcPath).lastPathComponent)\n")
|
|
@@ -110,6 +109,7 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
let document = PDFDocument(url: url)
|
|
let document = PDFDocument(url: url)
|
|
if document == nil {
|
|
if document == nil {
|
|
self.didSuccess = -2;
|
|
self.didSuccess = -2;
|
|
|
|
+ self.complention(self.didSuccess)
|
|
self.accessSemaphore?.signal()
|
|
self.accessSemaphore?.signal()
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -144,6 +144,7 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
self.didSuccess = -1;
|
|
self.didSuccess = -1;
|
|
|
|
|
|
self.complention(self.didSuccess)
|
|
self.complention(self.didSuccess)
|
|
|
|
+ self.accessSemaphore?.signal()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}else if !useOldLib && NSArray(array: ["ppt", "PPT", "PPTX", "pptx"]).contains(self.pathExtension) {
|
|
}else if !useOldLib && NSArray(array: ["ppt", "PPT", "PPTX", "pptx"]).contains(self.pathExtension) {
|
|
@@ -241,37 +242,46 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
}
|
|
}
|
|
}else {
|
|
}else {
|
|
autoreleasepool {
|
|
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!) {
|
|
func fppdfConverter(_ converter: Any!, didEndConversion error: Error!) {
|
|
autoreleasepool {
|
|
autoreleasepool {
|
|
didSuccess = nil == error ? 1 : 0
|
|
didSuccess = nil == error ? 1 : 0
|
|
- self.fpConverter?.stopConvertsionIfNeed()
|
|
|
|
|
|
+ CPDFConverterFPTool.stopConvertsionIfNeed(self.fpConverter)
|
|
self.fpConverter = nil;
|
|
self.fpConverter = nil;
|
|
|
|
|
|
Thread.sleep(forTimeInterval: 0.3)
|
|
Thread.sleep(forTimeInterval: 0.3)
|
|
@@ -352,9 +362,9 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
|
|
/// Cancel
|
|
/// Cancel
|
|
func cancelTask() {
|
|
func cancelTask() {
|
|
if (self.fpConverter != nil) {
|
|
if (self.fpConverter != nil) {
|
|
- self.fpConverter!.stopConvertsionIfNeed()
|
|
|
|
|
|
+ CPDFConverterFPTool.stopConvertsionIfNeed(self.fpConverter)
|
|
self.fpConverter = nil;
|
|
self.fpConverter = nil;
|
|
-
|
|
|
|
|
|
+
|
|
Thread.sleep(forTimeInterval: 0.3)
|
|
Thread.sleep(forTimeInterval: 0.3)
|
|
}
|
|
}
|
|
if (self.pdfConverter != nil) {
|
|
if (self.pdfConverter != nil) {
|