|
@@ -102,7 +102,8 @@ extension KMMergeWindowController {
|
|
}
|
|
}
|
|
|
|
|
|
let openPanel = NSOpenPanel()
|
|
let openPanel = NSOpenPanel()
|
|
- openPanel.allowedFileTypes = ["pdf"]
|
|
|
|
|
|
+// openPanel.allowedFileTypes = ["pdf"]
|
|
|
|
+ openPanel.allowedFileTypes = KMTools.imageExtensions + KMTools.pdfExtensions
|
|
|
|
|
|
if KMPurchaseManager.manager.state == .subscription {
|
|
if KMPurchaseManager.manager.state == .subscription {
|
|
openPanel.allowsMultipleSelection = true
|
|
openPanel.allowsMultipleSelection = true
|
|
@@ -116,7 +117,22 @@ extension KMMergeWindowController {
|
|
if result == NSApplication.ModalResponse.OK {
|
|
if result == NSApplication.ModalResponse.OK {
|
|
var array: [URL] = []
|
|
var array: [URL] = []
|
|
for fileURL in openPanel.urls {
|
|
for fileURL in openPanel.urls {
|
|
- array.append(fileURL)
|
|
|
|
|
|
+ if KMTools.isImageType(fileURL.pathExtension) {
|
|
|
|
+ if let image = NSImage(contentsOf: fileURL) {
|
|
|
|
+ if let page = PDFPage(image: image) {
|
|
|
|
+ let document = PDFDocument()
|
|
|
|
+ document.insert(page, at: 0)
|
|
|
|
+
|
|
|
|
+ let path = self._saveImagePath() + "/" + fileURL.deletingPathExtension().lastPathComponent + ".pdf"
|
|
|
|
+ let result = document.write(toFile: path)
|
|
|
|
+ if result {
|
|
|
|
+ array.append(URL(fileURLWithPath: path))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ array.append(fileURL)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
let attribe = try?FileManager.default.attributesOfItem(atPath: openPanel.urls.first!.path)
|
|
let attribe = try?FileManager.default.attributesOfItem(atPath: openPanel.urls.first!.path)
|
|
@@ -134,6 +150,15 @@ extension KMMergeWindowController {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private func _saveImagePath() -> String {
|
|
|
|
+ let rootPath = KMDataManager.fetchAppSupportOfBundleIdentifierDirectory()
|
|
|
|
+ let path = rootPath.appendingPathComponent("Merge").path
|
|
|
|
+ if FileManager.default.fileExists(atPath: path) == false {
|
|
|
|
+ try?FileManager.default.createDirectory(atPath: path, withIntermediateDirectories: false)
|
|
|
|
+ }
|
|
|
|
+ return path
|
|
|
|
+ }
|
|
|
|
+
|
|
func mergeFiles(files: [KMFileAttribute], size: CGSize = .zero) {
|
|
func mergeFiles(files: [KMFileAttribute], size: CGSize = .zero) {
|
|
var size = 0.0
|
|
var size = 0.0
|
|
for file in files {
|
|
for file in files {
|