|
@@ -65,7 +65,7 @@ class KMBatchManager: NSObject {
|
|
|
|
|
|
break
|
|
break
|
|
case .background:
|
|
case .background:
|
|
-
|
|
|
|
|
|
+ self.backgroundApplay(data: data, outputFolderPath: outputFolderPath)
|
|
break
|
|
break
|
|
case .headerAndFooter:
|
|
case .headerAndFooter:
|
|
|
|
|
|
@@ -353,13 +353,13 @@ extension KMBatchManager: KMBatchSettingViewExport {
|
|
!data.openPasswordString.isEmpty {
|
|
!data.openPasswordString.isEmpty {
|
|
options.updateValue(data.openPasswordString, forKey: .userPasswordOption)
|
|
options.updateValue(data.openPasswordString, forKey: .userPasswordOption)
|
|
}
|
|
}
|
|
-//
|
|
|
|
|
|
+ //
|
|
//权限密码
|
|
//权限密码
|
|
if data.isPermission &&
|
|
if data.isPermission &&
|
|
!data.permissionString.isEmpty {
|
|
!data.permissionString.isEmpty {
|
|
options.updateValue(data.permissionString, forKey: .ownerPasswordOption)
|
|
options.updateValue(data.permissionString, forKey: .ownerPasswordOption)
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// 限制打印
|
|
// 限制打印
|
|
if data.restrictOptions.contains(.print) {
|
|
if data.restrictOptions.contains(.print) {
|
|
options.updateValue(false, forKey: .allowsPrintingOption)
|
|
options.updateValue(false, forKey: .allowsPrintingOption)
|
|
@@ -376,7 +376,7 @@ extension KMBatchManager: KMBatchSettingViewExport {
|
|
|
|
|
|
|
|
|
|
let result = docuemt!.write(toFile: path, withOptions: options)
|
|
let result = docuemt!.write(toFile: path, withOptions: options)
|
|
-// let result = docuemt!.write(to: URL(fileURLWithPath: path), withOptions: options)
|
|
|
|
|
|
+ // let result = docuemt!.write(to: URL(fileURLWithPath: path), withOptions: options)
|
|
if result {
|
|
if result {
|
|
KMPrint("成功")
|
|
KMPrint("成功")
|
|
self.itemSuccess(item: item)
|
|
self.itemSuccess(item: item)
|
|
@@ -394,41 +394,91 @@ extension KMBatchManager: KMBatchSettingViewExport {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- func waterMarkApplay(data: KMBatchSettingItemViewModel) {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-// func waterMarkFile(data: KMWatermarkAdjectiveBaseModel, filesData: [KMBatchProcessingTableViewModel]?) {
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
- func backgroundApplay(data: KMBatchSettingItemViewModel) {
|
|
|
|
|
|
+ //MARK: 水印
|
|
|
|
+ func waterMarkApplay(data: KMBatchSettingItemViewModel, outputFolderPath: String) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- func backgroundFile(outputFolderPath: String, data: KMBackgroundModel, filesData: [KMBatchProcessingTableViewModel]?) {
|
|
|
|
|
|
+ func waterMarkFile(outputFolderPath: String, data: KMBatchSettingItemViewModel, filesData: [KMBatchProcessingTableViewModel]?) {
|
|
|
|
+
|
|
|
|
|
|
|
|
+ }
|
|
|
|
+ //MARK: 背景
|
|
|
|
+ func backgroundApplay(data: KMBatchSettingItemViewModel, outputFolderPath: String) {
|
|
|
|
+ if let data = data as? KMBatchBackgroundModel {
|
|
|
|
+ self.backgroundFile(outputFolderPath: outputFolderPath, data: data, filesData: self.batchFilesData)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ func backgroundFile(outputFolderPath: String, data: KMBatchBackgroundModel, filesData: [KMBatchProcessingTableViewModel]) {
|
|
|
|
+ if filesData.count != 0 {
|
|
|
|
+ for i in 0..<filesData.count {
|
|
|
|
+ let item = filesData[i]
|
|
|
|
+ var fileName = item.filePath.deletingPathExtension.lastPathComponent
|
|
|
|
+ if ((fileName.isEmpty)) {
|
|
|
|
+ fileName = NSLocalizedString("Untitled", comment: "")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let path = outputFolderPath + "/" + fileName + ".pdf"
|
|
|
|
+ let document = CPDFDocument.init(url: URL(fileURLWithPath: item.filePath))
|
|
|
|
+
|
|
|
|
+ if (document?.allowsPrinting == false || document?.allowsCopying == false) {
|
|
|
|
+ let alert = NSAlert()
|
|
|
|
+ alert.alertStyle = .critical
|
|
|
|
+ alert.messageText = "此文档不允许修改"
|
|
|
|
+ alert.runModal()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if let background = document?.background(), let model = data.backgroundModel {
|
|
|
|
+ KMBackgroundManager.defaultManager.updateBackground(background, withModel: model)
|
|
|
|
+
|
|
|
|
+ var pages = Array(0..<Int(document!.pageCount))
|
|
|
|
+ let pageIndexString = pages.isEmpty ? "" : pages.map { "\($0)" }.joined(separator: ",")
|
|
|
|
+ background.pageString = pageIndexString
|
|
|
|
+ background.update()
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (FileManager.default.fileExists(atPath: path)) {
|
|
|
|
+ try?FileManager.default.removeItem(atPath: path)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let result = document?.write(to: URL(fileURLWithPath: path)) ?? false
|
|
|
|
+ if (result) {
|
|
|
|
+ KMPrint("removeFile成功")
|
|
|
|
+ self.itemSuccess(item: item)
|
|
|
|
+ } else {
|
|
|
|
+ KMPrint("removeFile失败")
|
|
|
|
+ self.itemFailure(item: item, error: nil)
|
|
|
|
+ }
|
|
|
|
+ if i == filesData.count - 1 {
|
|
|
|
+ self.batchSuccess()
|
|
|
|
+ }
|
|
|
|
+ NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: path)])
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- func headAndFooterApplay(data: KMBatchSettingItemViewModel) {
|
|
|
|
|
|
+ //MARK: 页眉页脚
|
|
|
|
+ func headAndFooterApplay(data: KMBatchSettingItemViewModel, outputFolderPath: String) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-// func headAndFooterFile(outputFolderPath: String, data: KMHeaderFooterModel, filesData: [KMBatchProcessingTableViewModel]?) {
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
|
|
+ func headAndFooterFile(outputFolderPath: String, data: KMBatchSettingItemViewModel, filesData: [KMBatchProcessingTableViewModel]?) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
- func batesApplay(data: KMBatchSettingItemViewModel) {
|
|
|
|
|
|
+ //MARK: 贝茨码
|
|
|
|
+ func batesApplay(data: KMBatchSettingItemViewModel, outputFolderPath: String) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- func batesFile(outputFolderPath: String, data: KMBatesModel, filesData: [KMBatchProcessingTableViewModel]?) {
|
|
|
|
|
|
+ func batesFile(outputFolderPath: String, data: KMBatchSettingItemViewModel, filesData: [KMBatchProcessingTableViewModel]?) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
+ //MARK: 移除
|
|
func removeApplay(data: KMBatchSettingItemViewModel, outputFolderPath: String) {
|
|
func removeApplay(data: KMBatchSettingItemViewModel, outputFolderPath: String) {
|
|
self.removeFile(outputFolderPath: outputFolderPath, data: data as! KMBatchRemoveViewModel, filesData: self.batchFilesData)
|
|
self.removeFile(outputFolderPath: outputFolderPath, data: data as! KMBatchRemoveViewModel, filesData: self.batchFilesData)
|
|
}
|
|
}
|