Browse Source

【编辑工具】水印自定义页数功能完善

lizhe 1 year ago
parent
commit
827209c4b2

+ 21 - 1
PDF Office/PDF Master/Class/PDFTools/Watermark/New/View/KMWatermarkView.swift

@@ -448,6 +448,7 @@ class KMWatermarkView: KMBaseXibView, NSTextFieldDelegate, NSComboBoxDelegate, N
     func checkPageRangeValidate(_ pageRangeString: String) -> Bool {
         let fileAttribute = KMFileAttribute()
         fileAttribute.filePath = (self.pdfDocument?.documentURL.path)!
+        fileAttribute.password = self.pdfDocument?.password ?? ""
         fileAttribute.bAllPage = false
         fileAttribute.pagesString = self.pageRangeComboBox.stringValue
         
@@ -743,7 +744,26 @@ extension KMWatermarkView {
     
     @IBAction func buttonClicked_Done(_ sender: Any) {
         if checkPageRangeValidate(pageRangeComboBox.stringValue) {
-            self.watermark.pagesString = pageRangeComboBox.stringValue
+            if watermark.pageRangeType == .other {
+                var pageString: String = ""
+                let fileAttribute = KMFileAttribute()
+                fileAttribute.filePath = (self.pdfDocument?.documentURL.path)!
+                fileAttribute.password = self.pdfDocument?.password ?? ""
+                fileAttribute.bAllPage = false
+                fileAttribute.pagesType = .custom
+                fileAttribute.pagesString = self.pageRangeComboBox.stringValue
+                let pages = fileAttribute.fetchSelectPages()
+                for i in 0 ..< pages.count {
+                    pageString.append("\(pages[i] - 1)")
+                    
+                    if (i != pages.count-1) {
+                        pageString.append(",")
+                    }
+                }
+                self.watermark.pagesString = pageString
+            } else {
+                self.watermark.pagesString = self.pageRangeComboBox.stringValue
+            }
             updatePDFView()
         }