win10原生系统下 OCRmyPDF安装使用
长期以来一直在代替freepic2pdf的工具,因为在图片转化PDF时,如果没有勾选该软件 添加OCR层 选项,印象中事后无法挂OCR层上去。

福昕风腾,Abbyy能对 整本PDF扫描书进行OCR,然后生成添加OCR层的PDF/A 文件吗?印象中,我是失败的。看到 OCRmyPDF 于是
打算安装,试试看。以下内容是我安装OCRmyPDF的记录。

这是安装说明 https://ocrmypdf.readthedocs.io/en/latest/installation.html#native-windows
提到需要的软件:
Python 3.7 (64-bit) or later
Tesseract 4.0 or later
Ghostscript 9.50 or later
提到用chocolatey  https://chocolatey.org/ ,安装之后,就有了跟pip
看来miniconda白装了,而且命令行 conda search命令,提示错误,无法连接到代理网络 。
卸载coda https://docs.anaconda.com/anaconda/install/uninstall/#windows

在线安装 Chocolatey package manager https://chocolatey.org/install
开始安装说明 https://docs.chocolatey.org/en-us/choco/setup
使用powershell(管理员模式)安装 Install with PowerShell.exe 提示要关闭 Get-ExecutionPolicy 限制
操作: 输入Get-ExecutionPolicy. If it returns Restricted,然后输入Set-ExecutionPolicy AllSigned 或者 Set-ExecutionPolicy Bypass -Scope Process.
出现黄标提示,忽略即可。如果没有error,输入choco,出现版本,说明成功。
如要Completely offline install 离线安装,见https://docs.chocolatey.org/en-us/choco/setup#more-install-options
首次使用课程 https://community.chocolatey.org/courses/installation

开始使用choco  https://docs.chocolatey.org/en-us/getting-started
更新Choco:choco upgrade chocolatey

安装需要的功能模块(提示,以下安装均需要电脑能访问谷歌)
choco install python3
choco install --pre tesseract
choco install ghostscript
choco install pngquant (optional)
安装 ocrmypdf
pip install ocrmypdf

安装chocolatey后 chocolatey 数据库文件出现在 C:\ProgramData\chocolatey\
在chocolatey 下载的功能模块安装包 出现在 C:\ProgramData\chocolatey\lib\
其中ocrmypdf 出现在 C:\Python310\Lib\site-packages\
以及 C:\Python310\Scripts\
Python出现在 C:\Python310\
ghostscript出现在 C:\Program Files\gs\
tesseract C:\Program Files\

添加语言包 https://ocrmypdf.readthedocs.io/en/latest/languages.html
从 https://github.com/tesseract-ocr/tessdata/  ,解压里面的扩展名为traineddata的文件,复制到 C:\Program Files\Tesseract-OCR\tessdata

使用OCRmyPDF
ocrmypdf -l chi_sim --pdf-renderer tesseract --output-type pdf source.pdf ocr.pdf
-l language的意思,chi_sim对应
 C:\Program Files\Tesseract-OCR\tessdata\ 路径下的 chi_sim.traineddata 文件,如果是中英文混排的情况,就把-l chi_sim改成
-l chi_sim+eng
更多使用说明 https://ocrmypdf.readthedocs.io/en/latest/cookbook.html

——————
感悟:来明天测试看看效果。不管明天效果如何,但看到choco(chocolatey)代替conda做版本管理 已经够了。

posted on 2022-09-07 22:03  马兹  阅读(1240)  评论(0编辑  收藏  举报