gruz / gvc-pdf2pdf
在原始PDF图像上叠加来自Google Vision Cloud(OCR)的文本
Requires
- laravel/helpers: ^1.2
- setasign/fpdi: ^2.3
- setasign/tfpdf: ^1.31
This package is auto-updated.
Last update: 2024-09-22 05:22:47 UTC
README
当需要时
您有一个PDF图像。您已经通过Google Vision Cloud(gvc)OCR服务识别了文本。现在想将文本应用到PDF上以便使其可搜索。
注意!这同样仅适用于用GVC识别的PDF。对于用GVC识别的图像,您可以使用更好的工具,如[https://github.com/dinosauria123/gcv2hocr/]。您还可以尝试使用[https://github.com/mah-jp/pdf4search]。我未能学习日语。
问题
由于无法使用相同的字体和文本大小,因此文本将添加到与图像上相同的大致位置。不要期望100%的好结果。
快速示例
在 examples
文件夹中,您可以找到一对文件(PDF图像和由Google Vision Cloud JSON生成的文件)以及一些输出文件(用于生产的隐藏文本和用于调试的可见文本)。
观看展示结果的视频以获得灵感 [https://streamable.com/r2gyk9]
安装
当然需要PHP。
在您的项目中使用
composer require gruz/gvc-pdf2pdf
或者
git clone git@github.com:gruz/gcv-pdf2pdf.git
cd gcv-pdf2pdf
composer install
用法
检查代码,用法很明显。快速入门
use GvcPdf2Pdf\PdfTextApply; $jsonFile = __DIR__ .'/01-in-google-vision-cloud.json'; $pdfSourceFile = __DIR__ .'/01-in-pdf-as-image.pdf'; $pdfOutFile1 = __DIR__ .'/01-out-pdf-with-text-hidden.pdf'; $pdf = new PdfTextApply($jsonFile, $pdfSourceFile, $pdfOutFile1); $pdf->watermark->text = 'gruz.ml'; $pdf->run();
运行示例
单个文件
如果不在项目中,请转到项目文件夹并运行
php example/example.php
这将(重新生成)example/01-out-pdf-with-text-hidden.pdf
和 example/01-out-pdf-with-text-visible-for-debug.pdf
文件。
文件夹
如果不在项目中,请转到项目文件夹并运行
php example/example-folder.php
它使用放置在 example/in/
的文件对,并将输出生成到 example/out/
作为结果,您将获得重新生成的PDF文件。