|
@@ -192,7 +192,7 @@ extension KMHomeViewController {
|
|
(type == "pict") ||
|
|
(type == "pict") ||
|
|
(type == "sgi") ||
|
|
(type == "sgi") ||
|
|
(type == "heic") {
|
|
(type == "heic") {
|
|
- imageUrl.append(url)
|
|
|
|
|
|
+ openImageFile(url: url)
|
|
} else if (type == "doc") ||
|
|
} else if (type == "doc") ||
|
|
(type == "docx") ||
|
|
(type == "docx") ||
|
|
(type == "xls") ||
|
|
(type == "xls") ||
|
|
@@ -203,12 +203,6 @@ extension KMHomeViewController {
|
|
self.openOfficeFile(url: url)
|
|
self.openOfficeFile(url: url)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if imageUrl.count > 0 {
|
|
|
|
- let imageToPDFWindow: KMImageToPDFWindowController = KMImageToPDFWindowController.init(windowNibName: "KMImageToPDFWindowController")
|
|
|
|
- imageToPDFWindow.showWindow(NSApp.mainWindow)
|
|
|
|
- imageToPDFWindow.batchPrecessingView.inputData = imageUrl
|
|
|
|
- imageToPDFWindow.inputType = .ImageToPDF
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -406,10 +400,7 @@ extension KMHomeViewController {
|
|
(type == "pict") ||
|
|
(type == "pict") ||
|
|
(type == "sgi") ||
|
|
(type == "sgi") ||
|
|
(type == "heic") {
|
|
(type == "heic") {
|
|
- let imageToPDFWindow: KMImageToPDFWindowController = KMImageToPDFWindowController.init(windowNibName: "KMImageToPDFWindowController")
|
|
|
|
- imageToPDFWindow.showWindow(NSApp.mainWindow)
|
|
|
|
- imageToPDFWindow.batchPrecessingView.inputData = [path]
|
|
|
|
- imageToPDFWindow.inputType = .ImageToPDF
|
|
|
|
|
|
+ openImageFile(url: path)
|
|
} else if (type == "doc") ||
|
|
} else if (type == "doc") ||
|
|
(type == "docx") ||
|
|
(type == "docx") ||
|
|
(type == "xls") ||
|
|
(type == "xls") ||
|
|
@@ -420,18 +411,42 @@ extension KMHomeViewController {
|
|
let fileName: NSString = String(format: "%@.pdf", NSLocalizedString("Untitled", comment: "")) as NSString
|
|
let fileName: NSString = String(format: "%@.pdf", NSLocalizedString("Untitled", comment: "")) as NSString
|
|
let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath())
|
|
let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath())
|
|
openOfficeFile(url: path)
|
|
openOfficeFile(url: path)
|
|
-// CPDFKit.sharedInstance().convertFilePath(path.path, toPath: savePath) { success in
|
|
|
|
-// if success {
|
|
|
|
-// NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: savePath), display: true) { document, documentWasAlreadyOpen, error in
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ func openImageFile(url: URL) -> Void {
|
|
|
|
+ let filePath = url.path
|
|
|
|
+
|
|
|
|
+ let fileName: NSString = url.lastPathComponent as NSString
|
|
|
|
+ let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath()).deletingLastPathComponent
|
|
|
|
+
|
|
|
|
+ let imageName = NSString(string: NSString(string: filePath).lastPathComponent).deletingPathExtension
|
|
|
|
+
|
|
|
|
+ let path = self.fetchDifferentFilePath(filePath: savePath + "/" + imageName + ".pdf")
|
|
|
|
+ let document = CPDFDocument.init()
|
|
|
|
+ var success = false
|
|
|
|
+
|
|
|
|
+ //FIXME: 无法插入图片
|
|
|
|
+ let image = NSImage(contentsOfFile: filePath)
|
|
|
|
+ let insertPageSuccess = document?.insertPage(image!.size, withImage: filePath, at: document!.pageCount)
|
|
|
|
+ if insertPageSuccess != nil {
|
|
|
|
+ //信号量控制异步
|
|
|
|
+ let semaphore = DispatchSemaphore(value: 0)
|
|
|
|
+ DispatchQueue.global().async {
|
|
|
|
+ success = ((document?.write(toFile: path)) != nil)
|
|
|
|
+ semaphore.signal()
|
|
|
|
+ }
|
|
|
|
+ semaphore.wait()
|
|
|
|
+ } else {
|
|
|
|
+ }
|
|
|
|
+ if success {
|
|
|
|
+ NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: path), display: true) { document, documentWasAlreadyOpen, error in
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
func openOfficeFile(url: URL) -> Void {
|
|
func openOfficeFile(url: URL) -> Void {
|
|
let filePath = url.path
|
|
let filePath = url.path
|
|
let folderPath = "convertToPDF.pdf"
|
|
let folderPath = "convertToPDF.pdf"
|