|
@@ -1174,6 +1174,57 @@ typealias KMMainDocumentCloudUploadHanddler = (@escaping(Bool, String)->()) -> (
|
|
|
formatPopup?.removeItem(at: formatPopup!.index(of: item))
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // MARK: - Printing
|
|
|
+
|
|
|
+ override func printOperation(withSettings printSettings: [NSPrintInfo.AttributeKey : Any]) throws -> NSPrintOperation {
|
|
|
+ let printInfo = self.printInfo.copy() as! NSPrintInfo
|
|
|
+ printInfo.dictionary().addEntries(from: printSettings)
|
|
|
+
|
|
|
+ var printOperation: NSPrintOperation?
|
|
|
+ if self.isHome {
|
|
|
+ return NSPrintOperation()
|
|
|
+ }
|
|
|
+ let documentURL = self.mainViewController?.document?.documentURL
|
|
|
+ if documentURL == nil {
|
|
|
+ return NSPrintOperation()
|
|
|
+ }
|
|
|
+
|
|
|
+ guard let pdfDoc = PDFDocument(url: documentURL!) else {
|
|
|
+ return NSPrintOperation()
|
|
|
+ }
|
|
|
+
|
|
|
+ if pdfDoc.responds(to: #selector(PDFDocument.printOperation(for:scalingMode:autoRotate:))) {
|
|
|
+ printOperation = pdfDoc.printOperation(for: printInfo, scalingMode: .pageScaleNone, autoRotate: true)
|
|
|
+ } else if pdfDoc.responds(to: #selector(PDFDocument.getPrintOperation(for:autoRotate:))) {
|
|
|
+ printOperation = pdfDoc.getPrintOperation(for: printInfo, autoRotate: true)
|
|
|
+ }
|
|
|
+
|
|
|
+ // NSPrintProtected is a private key that disables the items in the PDF popup of the Print panel, and is set for encrypted documents
|
|
|
+ if pdfDoc.isEncrypted {
|
|
|
+ printOperation?.printInfo.dictionary().setValue(false, forKey: "NSPrintProtected")
|
|
|
+ }
|
|
|
+
|
|
|
+ let printPanel = printOperation?.printPanel
|
|
|
+ printPanel?.options = [.showsCopies, .showsPageRange, .showsPaperSize, .showsOrientation, .showsScaling, .showsPreview]
|
|
|
+
|
|
|
+ if printOperation == nil {
|
|
|
+ throw NSError.printDocumentError(withLocalizedDescription: "")
|
|
|
+ }
|
|
|
+
|
|
|
+ return printOperation!
|
|
|
+ }
|
|
|
+
|
|
|
+ override func runModalPrintOperation(_ printOperation: NSPrintOperation, delegate: Any?, didRun didRunSelector: Selector?, contextInfo: UnsafeMutableRawPointer?) {
|
|
|
+ printOperation.run()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+extension PDFDocument {
|
|
|
+ @objc func getPrintOperation(for printInfo: NSPrintInfo, autoRotate: Bool) -> NSPrintOperation {
|
|
|
+ // 在此处实现方法的具体逻辑
|
|
|
+ return NSPrintOperation()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
extension KMMainDocument {
|