I am currently trying to create a searchable PDFDocument
after I have obtained a VNDocumentCameraScan
with the help of the VNDocumentCameraViewController
.
Currently I only take the images of the scan and put them into a PDFDocument
instance.
func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) {
let pdf = createPDF(from: scan)
}
fileprivate func createPDF(from scan: VNDocumentCameraScan) -> PDFDocument {
let pdfDocument = PDFDocument()
for i in 0 ..< scan.pageCount {
let pdfPage = PDFPage(image: scan.imageOfPage(at: i))
pdfDocument.insert(pdfPage!, at: i)
}
return pdfDocument
}
I also know how I would extract text out of the VNDocumentCameraScan
. The thing that I miss is how I incorporate the text information into the PDFDocument
instance. I need this because I want to scan documents, save them as .pdf
to the file system and search them afterwards.
I searched a lot but did not find a way to do that.
Does anyone know how I would accomplish this ?