Browse Source

【综合】新建空白文档,偶发创建失败问题修复

tangchao 1 year ago
parent
commit
a543360d2e

+ 5 - 0
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController.swift

@@ -648,6 +648,11 @@ extension KMHomeViewController {
     func openBlankPage() {
         let fileName: NSString = String(format: "%@.pdf", NSLocalizedString("Untitled", comment: "")) as NSString
         let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath() as String)
+        let filePath = savePath.deletingLastPathComponent
+        if FileManager.default.fileExists(atPath: filePath) == false {
+            try?FileManager.default.createDirectory(atPath: filePath, withIntermediateDirectories: false)
+        }
+        
         let pdfDocument = CPDFDocument()
         pdfDocument?.insertPage(CGSize(width: 595, height: 842), at: 0)
         pdfDocument?.write(to: URL(fileURLWithPath: savePath))