|
@@ -12,13 +12,13 @@ typealias KMMergeWindowControllerAddFilesAction = (_ controller: KMMergeWindowCo
|
|
|
typealias KMMergeWindowControllerMergeAction = (_ controller: KMMergeWindowController) -> Void
|
|
|
typealias KMMergeWindowControllerClearAction = (_ controller: KMMergeWindowController) -> Void
|
|
|
|
|
|
-class KMMergeWindowController: NSWindowController {
|
|
|
+class KMMergeWindowController: KMBaseWindowController {
|
|
|
|
|
|
@IBOutlet weak var mergeView: KMMergeView!
|
|
|
|
|
|
- var cancelAction: KMMergeWindowControllerCancelAction?
|
|
|
+// var cancelAction: KMMergeWindowControllerCancelAction?
|
|
|
|
|
|
- var pdfDocument: PDFDocument = PDFDocument()
|
|
|
+ var oldPDFDocument: PDFDocument = PDFDocument()
|
|
|
var password: String = ""
|
|
|
|
|
|
var oriDucumentUrl: URL?
|
|
@@ -185,7 +185,7 @@ extension KMMergeWindowController {
|
|
|
|
|
|
for number in file.fetchSelectPages() {
|
|
|
let page = tDocument.page(at: number - 1)
|
|
|
- self.pdfDocument.insert(page!, at: self.pdfDocument.pageCount)
|
|
|
+ self.oldPDFDocument.insert(page!, at: self.oldPDFDocument.pageCount)
|
|
|
// self.insertIndexSet.addIndex:(self.pdfDocument.pageCount - 1)
|
|
|
}
|
|
|
}
|
|
@@ -193,13 +193,13 @@ extension KMMergeWindowController {
|
|
|
|
|
|
let fileName = (files.first?.filePath.lastPathComponent)! + "_Merged"
|
|
|
DispatchQueue.main.async {
|
|
|
- self.pdfDocument.outlineRoot = PDFOutline.init()
|
|
|
+ self.oldPDFDocument.outlineRoot = PDFOutline.init()
|
|
|
if allPage {
|
|
|
var insertIndex = 0
|
|
|
for i in 0..<rootPDFOutlineArray.count {
|
|
|
let rootOutline = rootPDFOutlineArray[i]
|
|
|
for j in 0..<rootOutline.numberOfChildren {
|
|
|
- self.pdfDocument.outlineRoot?.insertChild(rootOutline.child(at: j)!, at: insertIndex)
|
|
|
+ self.oldPDFDocument.outlineRoot?.insertChild(rootOutline.child(at: j)!, at: insertIndex)
|
|
|
}
|
|
|
insertIndex = insertIndex + 1
|
|
|
}
|
|
@@ -216,9 +216,9 @@ extension KMMergeWindowController {
|
|
|
if result != nil {
|
|
|
var outputSavePanel = savePanel.url?.path
|
|
|
DispatchQueue.main.async {
|
|
|
- var success = self.pdfDocument.write(toFile: outputSavePanel!)
|
|
|
+ var success = self.oldPDFDocument.write(toFile: outputSavePanel!)
|
|
|
if !success {
|
|
|
- success = ((try?self.pdfDocument.dataRepresentation()?.write(to: URL(string: outputSavePanel!)!)) != nil)
|
|
|
+ success = ((try?self.oldPDFDocument.dataRepresentation()?.write(to: URL(string: outputSavePanel!)!)) != nil)
|
|
|
}
|
|
|
|
|
|
if success {
|
|
@@ -265,25 +265,25 @@ extension KMMergeWindowController {
|
|
|
}
|
|
|
|
|
|
var pagesArray: [PDFPage] = []
|
|
|
- let pageCount = self.pdfDocument.pageCount
|
|
|
+ let pageCount = self.oldPDFDocument.pageCount
|
|
|
for i in 0..<pageCount {
|
|
|
- pagesArray.append(self.pdfDocument.page(at: 0)!)
|
|
|
- self.pdfDocument.removePage(at: 0)
|
|
|
+ pagesArray.append(self.oldPDFDocument.page(at: 0)!)
|
|
|
+ self.oldPDFDocument.removePage(at: 0)
|
|
|
}
|
|
|
|
|
|
for i in 0..<pageCount {
|
|
|
let page: KMMergePDFPage = KMMergePDFPage.init()
|
|
|
page.setBounds(CGRectMake(0, 0, size.width, size.height), for: .mediaBox)
|
|
|
page.drawingPage = pagesArray[i]
|
|
|
- self.pdfDocument.insert(page, at: i)
|
|
|
+ self.oldPDFDocument.insert(page, at: i)
|
|
|
}
|
|
|
|
|
|
- if self.pdfDocument.outlineRoot != nil {
|
|
|
- let childCount = self.pdfDocument.outlineRoot?.numberOfChildren
|
|
|
+ if self.oldPDFDocument.outlineRoot != nil {
|
|
|
+ let childCount = self.oldPDFDocument.outlineRoot?.numberOfChildren
|
|
|
var outlineArray: [PDFOutline] = []
|
|
|
|
|
|
for i in 0..<childCount! {
|
|
|
- outlineArray.append((self.pdfDocument.outlineRoot?.child(at: i))!)
|
|
|
+ outlineArray.append((self.oldPDFDocument.outlineRoot?.child(at: i))!)
|
|
|
}
|
|
|
|
|
|
for outline in outlineArray {
|