12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- //
- // KMRedactTools.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2023/1/19.
- //
- import Cocoa
- class KMRedactTools: NSObject {
- class func eraserDocument(_ document: CPDFDocument, callback: @escaping (_ result: Bool, _ errorAnno: CPDFAnnotation?) -> ()) {
- for i in 0 ..< document.pageCount {
- guard let page: CPDFPage = document.page(at: i) else {
- continue
- }
- for anno in page.annotations {
- if ((anno.isKind(of: CPDFRedactAnnotation.self)) == false) {
- continue
- }
-
- let result = page.erasureRedact(from: anno.bounds)
- if (result == false) {
- callback(false, anno)
- return
- }
- }
- }
-
- callback(true, nil)
- }
-
- class func getPageIndexs(_ type: Int, string: String, _ pageCount: Int) -> IndexSet {
- var indexs: IndexSet = []
- if (type == 1) { /// 所有页面
- for i in 0 ..< pageCount {
- indexs.insert(i)
- }
- } else if (type == 2) { /// 奇数页
- for i in 0 ..< pageCount {
- if (i % 2 == 1) {
- continue
- }
- indexs.insert(i)
- }
- } else if (type == 3) { /// 偶数页
- for i in 0 ..< pageCount {
- if (i % 2 == 0) {
- continue
- }
- indexs.insert(i)
- }
- } else if (type == 4) {
- let array = KMPageRangeTools.findSelectPage(pageRangeString: string, pageCount: pageCount)
- for i in array {
- indexs.insert(i-1)
- }
- }
- return indexs
- }
-
- }
|