gpt4 book ai didi

ios - VNDocumentCameraScan 到可搜索的 PDF

转载 作者:行者123 更新时间:2023-12-05 06:11:49 25 4
gpt4 key购买 nike

VNDocumentCameraViewController 的帮助下获得 VNDocumentCameraScan 之后,我目前正在尝试创建一个可搜索的 PDFDocument

目前我只拍摄扫描图像并将它们放入 PDFDocument 实例中。


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
}

我也知道如何从 VNDocumentCameraScan 中提取文本。我想念的是如何将文本信息合并到 PDFDocument 实例中。我需要这个,因为我想扫描文档,将它们作为 .pdf 保存到文件系统中,然后再进行搜索。

我搜索了很多,但没有找到方法。

有谁知道我将如何做到这一点?

最佳答案

这篇博文详细介绍了该主题。我链接到系列的第 3 部分,因为它解决了您遇到的流程部分。

https://alexanderweiss.dev/blog/2021-03-29-from-uiimage-to-searchable-pdf-part-3

主要思想是在 pdf 中的图像下方绘制已识别的文本。文章中的基本步骤:

  1. Take the image
  2. Recognize the text on the image
  3. Create a PDF page with the dimensions of the image
  4. Use the recognized text to draw text
  5. Draw the image above the text on the pdf

VNRecognizedText 包含有关已识别文本位置的信息,可让您确定在何处绘制文本。我能够在我的应用程序中成功使用这篇文章中的代码;虽然在处理手写文本时它不是 100% 完美,但它工作得相当好。

关于ios - VNDocumentCameraScan 到可搜索的 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63811018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com