|
@@ -261,10 +261,10 @@ class KMImageToPDFMethod: NSObject, KMGOCRManagerDelegate {
|
|
|
}
|
|
|
|
|
|
|
|
|
- func dealWithResults(_ rlts: [KMGOCRResult]?, OCRImageAtIndex index: Int) {
|
|
|
+ func dealWithResults(_ results: [KMGOCRResult]?, OCRImageAtIndex index: Int) {
|
|
|
if isOCR {
|
|
|
if isMerge {
|
|
|
- self.results.add(rlts as Any)
|
|
|
+ self.results.add(results as Any)
|
|
|
var key = index
|
|
|
if isCreatPDF {
|
|
|
key = Int((self.appendPDF?.pageCount ?? 0) + UInt(index))
|
|
@@ -273,7 +273,14 @@ class KMImageToPDFMethod: NSObject, KMGOCRManagerDelegate {
|
|
|
if OCRResultString.count > 0 {
|
|
|
contents = self.OCRResultString
|
|
|
}
|
|
|
- let str: String = results.firstObject as? String ?? ""
|
|
|
+ var str: String = ""
|
|
|
+ if results!.count > 0 {
|
|
|
+ guard let firstResult: KMGOCRResult = results?.first else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ str = firstResult.text
|
|
|
+ }
|
|
|
+
|
|
|
contents = contents + "\n"
|
|
|
contents = contents + "Page" + "\(key + 1)"
|
|
|
contents = contents + "\n----------\n"
|
|
@@ -345,14 +352,16 @@ class KMImageToPDFMethod: NSObject, KMGOCRManagerDelegate {
|
|
|
let tString = model.photoName.deletingPathExtension.lastPathComponent
|
|
|
var savePath = fileSavePath.stringByAppendingPathComponent(tString).stringByAppendingPathExtension("pdf")
|
|
|
savePath = getUniqueFilePath(savePath)
|
|
|
- if results == nil { results = NSMutableArray() }
|
|
|
- KMGOCRManager.default().createPDFFile(savePath, imagePaths: [filePath], results: (results as! [Any]), scale: 1.0)
|
|
|
+ KMGOCRManager.default().createPDFFile(savePath, imagePaths: [filePath], results: [results as Any], scale: 1.0)
|
|
|
var tFileName = fileSavePath.stringByAppendingPathComponent(tString).stringByAppendingPathExtension("txt")
|
|
|
tFileName = getUniqueFilePath(tFileName)
|
|
|
if isSaveAsText {
|
|
|
var string: String = ""
|
|
|
- if results.count > 0 {
|
|
|
- string = results.firstObject as! String
|
|
|
+ if results!.count > 0 {
|
|
|
+ guard let firstResult: KMGOCRResult = results?.first else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ string = firstResult.text
|
|
|
try? string.write(toFile: tFileName, atomically: true, encoding: .utf8)
|
|
|
}
|
|
|
}
|