KMRedactTools.swift 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //
  2. // KMRedactTools.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/1/19.
  6. //
  7. import Cocoa
  8. class KMRedactTools: NSObject {
  9. class func eraserDocument(_ document: CPDFDocument, callback: @escaping (_ result: Bool, _ errorAnno: CPDFAnnotation?) -> ()) {
  10. for i in 0 ..< document.pageCount {
  11. guard let page: CPDFPage = document.page(at: i) else {
  12. continue
  13. }
  14. for anno in page.annotations {
  15. if ((anno.isKind(of: CPDFRedactAnnotation.self)) == false) {
  16. continue
  17. }
  18. let result = page.erasureRedact(from: anno.bounds)
  19. if (result == false) {
  20. callback(false, anno)
  21. return
  22. }
  23. }
  24. }
  25. callback(true, nil)
  26. }
  27. class func getPageIndexs(_ type: Int, string: String, _ pageCount: Int) -> IndexSet {
  28. var indexs: IndexSet = []
  29. if (type == 1) { /// 所有页面
  30. for i in 0 ..< pageCount {
  31. indexs.insert(i)
  32. }
  33. } else if (type == 2) { /// 奇数页
  34. for i in 0 ..< pageCount {
  35. if (i % 2 == 1) {
  36. continue
  37. }
  38. indexs.insert(i)
  39. }
  40. } else if (type == 3) { /// 偶数页
  41. for i in 0 ..< pageCount {
  42. if (i % 2 == 0) {
  43. continue
  44. }
  45. indexs.insert(i)
  46. }
  47. } else if (type == 4) {
  48. let array = KMPageRangeTools.findSelectPage(pageRangeString: string, pageCount: pageCount)
  49. for i in array {
  50. indexs.insert(i-1)
  51. }
  52. }
  53. return indexs
  54. }
  55. }