Explorar o código

【打印】打印时的文档名称显示成“test2.pdf” -- 修复

lizhe hai 6 meses
pai
achega
55b4f62410

+ 5 - 2
PDF Office/PDF Master/Class/PDFTools/Print/KMPrintWindowController.swift

@@ -258,9 +258,11 @@ extension KMPrintWindowController {
     
     static func showPrintWindowControll(inputData: URL?, inputDocument: AnyObject?, inputType: DataNavigationViewButtonActionType = .Print, inputPageRange: KMPrintPageRange) {
         var document: PDFDocument?
-        let filePath = KMPrintPresenter.fetchSaveFilePath("")
+        var filePath = ""
+        
         var password: String = ""
         if inputDocument != nil {
+            filePath = KMPrintPresenter.fetchSaveFilePath(fileName: inputDocument?.documentURL?.path.lastPathComponent ?? "text.pdf")
 //            if inputDocument != nil {
             if inputDocument is CPDFDocument {
                 let success = inputDocument?.writeDecrypt(to: URL(fileURLWithPath: filePath))
@@ -274,6 +276,7 @@ extension KMPrintWindowController {
         }
 
         if inputData != nil {
+            filePath = KMPrintPresenter.fetchSaveFilePath(fileName: inputData?.path.lastPathComponent ?? "text.pdf")
             document = PDFDocument.init(url: inputData!)!
         }
         
@@ -284,7 +287,7 @@ extension KMPrintWindowController {
                 inputPageRange.selectPages.count != 0) {
                 
                 let printPresent = KMPrintPresenter()
-                let filePath = KMPrintPresenter.fetchSaveFilePath("")
+//                let filePath = KMPrintPresenter.fetchSaveFilePath("")
                 let paperSize = (document?.page(at: 0)?.bounds(for: .cropBox).size) ?? CGSizeZero
                 let context: CGContext = printPresent.createContext(filePath, paperSize)
                 var pages: [PDFPage] = []

+ 5 - 4
PDF Office/PDF Master/Class/PDFTools/Print/Presenter/KMPrintPresenter.swift

@@ -100,7 +100,7 @@ extension KMPrintPresenter: KMPrintPresenterDocument {
         //获取每张纸的page
         let drawPages: [KMPrintDrawPage] = self.fetchDrawPages(paperSize, printModel.page, paperCount, pageOfPaperCount, pages)
         //导出地址
-        let filePath = KMPrintPresenter.fetchSaveFilePath(toFilePath)
+        let filePath = KMPrintPresenter.fetchSaveFilePath(filePath:toFilePath ?? "")
         
         
         //方法一
@@ -261,10 +261,11 @@ extension KMPrintPresenter: KMPrintPresenterDocument {
      @param contentType annoation类型
      @param selectPages 当type 为custom时  传入选中page的下标
      */
-    static func fetchSaveFilePath(_ filePath: String?) -> String {
-        var saveFilePath = filePath ?? ""
+    static func fetchSaveFilePath(filePath: String = "", fileName: String = "test2.pdf") -> String {
+        var saveFilePath = filePath
+        var saveFileName = fileName 
         if saveFilePath.count == 0 {
-            saveFilePath = NSTemporaryDirectory() + "/PDFReaderProTest/test2.pdf"
+            saveFilePath = NSTemporaryDirectory() + "PDFReaderProTest/" + saveFileName
         }
         
         if !FileManager.default.fileExists(atPath: NSTemporaryDirectory() + "/PDFReaderProTest") {