|
@@ -49,6 +49,10 @@ class KMOCRManager: NSObject {
|
|
|
return (KMGOCRManager.languages() as NSArray).value(forKeyPath: KMGOCRLanguageStringKey) as! [String]
|
|
|
}
|
|
|
|
|
|
+ func clearOCRTextData() {
|
|
|
+ ocrDictionary.removeAll()
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
// func isCantainsImagePage(_ document: CPDFDocument) -> Bool {
|
|
|
// var isContainsImagePage = false
|
|
@@ -242,7 +246,7 @@ extension KMOCRManager: KMGOCRManagerDelegate {
|
|
|
manager.cancelRecognition()
|
|
|
self.OCRManger = nil
|
|
|
} else if model.showType == .area {
|
|
|
- let string = self.fetchTXT(ocrDictionary: ocrDictionary)
|
|
|
+ let string = self.fetchTXT(ocrDictionary: ocrDictionary, needPageIndex: false)
|
|
|
self.OCRComplete?(nil, string, nil)
|
|
|
}
|
|
|
}
|
|
@@ -447,7 +451,7 @@ extension KMOCRManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func fetchTXT(ocrDictionary: [NSNumber: Any]) -> String {
|
|
|
+ func fetchTXT(ocrDictionary: [NSNumber: Any], needPageIndex: Bool = true) -> String {
|
|
|
let sortedKeys = ocrDictionary.keys.sorted(by: { ($0 ).compare($1 ) == .orderedAscending })
|
|
|
var textString = ""
|
|
|
|
|
@@ -460,8 +464,10 @@ extension KMOCRManager {
|
|
|
if textString.count > 0 {
|
|
|
textString += "\n\n"
|
|
|
}
|
|
|
- textString += String(format: NSLocalizedString("Page %ld", comment: ""), (key as AnyObject).intValue + 1)
|
|
|
- textString += "\n"
|
|
|
+ if needPageIndex {
|
|
|
+ textString += String(format: NSLocalizedString("Page %ld", comment: ""), (key as AnyObject).intValue + 1)
|
|
|
+ textString += "\n"
|
|
|
+ }
|
|
|
textString += rStr
|
|
|
}
|
|
|
return textString
|