我正在构建一个 OCR 项目,并且正在为Tesseract使用 .Net 包装器。包装器的示例没有显示如何将 PDF 作为输入处理。使用 PDF 作为输入如何使用 c# 生成可搜索的 PDF?
如何通过保存原始 Pdf 的形状从 Pdf 获取文本
这是来自 pdf 的页面,我不想要只有文本,我希望文本的形状与原始 pdf 一样,并且英语不好
Kos*_*dis 13
仅出于文档原因,这里是OCR使用tesseract和pdf2image从图像 pdf 中提取文本的示例。
import pdf2image
try:
from PIL import Image
except ImportError:
import Image
import pytesseract
def pdf_to_img(pdf_file):
return pdf2image.convert_from_path(pdf_file)
def ocr_core(file):
text = pytesseract.image_to_string(file)
return text
def print_pages(pdf_file):
images = pdf_to_img(pdf_file)
for pg, img in enumerate(images):
print(ocr_core(img))
print_pages('sample.pdf')
Run Code Online (Sandbox Code Playgroud)
Tesseract 从 3.0 版本开始支持创建三明治。但是对于此功能,建议使用 3.02 或 3.03。 Pdfsandwich是一个脚本,它或多或少地满足您的需求。
在线服务www.sandwichpdf.com确实使用 tesseract 来创建可搜索的 PDF。在开始使用 tesseract 实施解决方案之前,您可能需要运行一些测试。结果还可以,但是有些商业产品可以提供更好的结果。披露:我是www.sandwichpdf.com的创建者。