Ver código fonte

【2025】【Convert】图片转PDF, 导入图片后, 选择保存到现有文档,但是没有选中文档,点击应用,崩溃-修复

lizhe 1 mês atrás
pai
commit
5fae1778d4

+ 13 - 4
PDF Office/PDF Master/KMClass/NewBatch/Manager/KMBatchManager.swift

@@ -716,13 +716,22 @@ extension KMBatchManager {
                     processFile(at: 0, outputFolderPath: outputFolderPath, data: data)
                 }
             } else {
-                var fileName = data.selectFilePath.deletingPathExtension.lastPathComponent
-                let path = self.fetchFilePath(type: .imageToPDF, filePath: data.selectFilePath, outputFolderPath: outputFolderPath)
+                let selectFilePath = data.selectFilePath
+                if selectFilePath.count == 0 {
+                    let alert = NSAlert()
+                    alert.alertStyle = .critical
+                    alert.messageText = KMLocalizedString("文件未选择")
+                    alert.runModal()
+                    return
+                }
+                
+                var fileName = selectFilePath.deletingPathExtension.lastPathComponent
+                let path = self.fetchFilePath(type: .imageToPDF, filePath: selectFilePath, outputFolderPath: outputFolderPath)
                 
-                var pdfDocument = CPDFDocument(url: NSURL(fileURLWithPath: data.selectFilePath) as URL)
+                var pdfDocument = CPDFDocument(url: NSURL(fileURLWithPath: selectFilePath) as URL)
                 let count: Int = Int(pdfDocument?.pageCount ?? 0)
                 for item in filesData {
-                    pdfDocument?.km_insert(image: item.image, at: pdfDocument?.pageCount ?? 0)
+                    pdfDocument?.km_insert(image: item.image, at: UInt(count))
                 }
                 
                 if data.isOCR {

+ 9 - 0
PDF Office/PDF Master/KMClass/NewBatch/View/Setting/ImageToPDF/KMBatchImageToPDFView.swift

@@ -284,6 +284,15 @@ extension KMBatchImageToPDFView {
     @objc func saveButtonClicked(_ sender: ComponentButton) {
         self.model.selectFilePath = self.selectFileInputButton.properties.text
         
+        let selectFilePath = self.model.selectFilePath
+        if selectFilePath.count == 0 {
+            let alert = NSAlert()
+            alert.alertStyle = .critical
+            alert.messageText = KMLocalizedString("文件未选择")
+            alert.runModal()
+            return
+        }
+        
         guard let callBack = self.batchExport else { return }
         
         callBack(self, model)