如何在 Laravel 中对波斯语 pdf 进行字数统计?

How to word-counting of persian pdf in Laravel?

我的项目在 Laravel 框架上。我的网站是基于翻译文件和书籍等。客户上传他的源文件为pdf,在后台,pdf的字数需要通过OCR计算才能确定最终价格,所以字数非常重要。主要问题是 OCR 对波斯字符有问题。你怎么能帮我解决这个问题?

按照我的方法,希望你得到你想要的正确答案:

将 PDFParser 添加到您的 composer.json 文件,然后 composer update:

{
    "require": {
        "smalot/pdfparser": "*"
    }
}

在您的控制器中使用以下代码来计算您的字数:

$parser = new \Smalot\PdfParser\Parser();
$pdf = $parser->parseFile("../public/1.pdf");

$text = $pdf->getText();
$text = trim( $text );
$text = str_replace( " ", "", $text );

echo str_word_count( $text );

注意:将您的PDF文件放入public文件夹中进行测试。