agussaputrapro/ocrmypdf

OCRmyPDF 的简单 PHP 包装器

0.1.3 2022-02-07 07:57 UTC

This package is auto-updated.

Last update: 2024-09-07 13:26:40 UTC


README

OCRmyPDF 的简单 PHP 包装器

安装

通过 Composer

$ composer require mishagp/ocrmypdf

此库依赖于 OCRmyPDF. 请参阅 GitHub 仓库中的说明,了解如何在您的平台上安装 OCRmyPDF。

用法

基本示例

use mishagp\OCRmyPDF\OCRmyPDF;

//Return file path of outputted, OCRed PDF
echo (new OCRmyPDF('document.pdf'))->run();

//Return file contents of outputted, OCRed PDF
echo (new OCRmyPDF('scannedImage.png'))->setOutputPDFPath(null)->run();

API

本节仍在进行中。

setInputData

将内存中加载的图像/PDF 数据直接通过 stdin 传递给 ocrmypdf

use mishagp\OCRmyPDF\OCRmyPDF;

//Using Imagick
$data = $img->getImageBlob();
$size = $img->getImageLength();

//Using GD
ob_start();
imagepng($img, null, 0);
$size = ob_get_length();
$data = ob_get_clean();

echo (new OCRmyPDF())
    ->setInputData($data, $size)
    ->run();

setOutputPDFPath

指定一个可写路径,其中 ocrmypdf 应生成输出 PDF。

use mishagp\OCRmyPDF\OCRmyPDF;
echo (new OCRmyPDF('document.pdf'))
    ->setOutputPDFPath('/outputDir/ocr_document.pdf')
    ->run();

setExecutable

如果出于任何原因,ocrmypdf 不在 $PATH 中,请定义 ocrmypdf 的自定义位置。

use mishagp\OCRmyPDF\OCRmyPDF;
echo (new OCRmyPDF('document.pdf'))
    ->setExecutable('/path/to/ocrmypdf')
    ->run();

许可证

ocrmypdf-php 在 AGPL-3.0 许可证 下发布。

鸣谢

ocrmypdf-php 的发展基于由 thiagoalessio 和相关贡献者开发的 tesseract PHP 包装器库 tesseract-ocr-for-php