Nefertiti by Dmytro Skorokhod is an open source iOS library for making searchable PDF documents from photos. It takes an array of UIImage objects and returns a file confirming to NefertitiFileProtocol.
Nefertiti is available as a Swift package. To start using the library add package dependancy, then import Nefertiti and NefertitiFile into your source code file.
Here is an example of usage Nefertiti with VisionKit:
import Nefertiti
import NefertitiFile
import VisionKit
let nefertiti: NefertitiPDFMakerProtocol = NefertitiSearchablePDFMaker()
var pdfDocumentSavingOperation: ((any NefertitiFileProtocol) -> ())?
extension VisionDocumentCameraManager: VNDocumentCameraViewControllerDelegate {
func documentCameraViewController(_ controller: VNDocumentCameraViewController,
didFinishWith scan: VNDocumentCameraScan) {
var pageImages = [UIImage]()
for pageIndex in 0 ..< scan.pageCount {
pageImages.append(scan.imageOfPage(at: pageIndex))
}
nefertiti.generatePdfDocumentFile(from: images) { file, error in
if let error = error {
debugPrint(error)
return
}
guard let file = file,
let pdfDocumentSavingOperation = pdfDocumentSavingOperation else { return }
pdfDocumentSavingOperation(file)
}
}
}
Read the NefertitiFile library documentation for the examples of NefertitiFileProtocol
usage.
This project is an example of using Nefertiti.
The articles I recommend to read to understand the topic better:
From UIImage to searchable PDF by Alexander Weiß.
Create searchable PDFs in Swift by Jerry Stratton.