joest8/pdfinterpreter
Composer 安装命令:
composer require joest8/pdfinterpreter
包简介
This class is designed to convert multiple PDF files, whether image-based or text-based, into an array of data.The class uses user-defined templates containing regular expressions to control the data extraction process, allowing for customized and flexible output.
README 文档
README
Introduction
This class is designed to convert multiple PDF files, whether image-based or text-based, into an array of data. The class uses user-defined templates containing regular expressions to control the data extraction process, allowing for customized and flexible output.
Table of Contents
This README is divided into several sections:
Installation
composer require joest8/pdfinterpreter
Console Applications
To use this class, you'll need to install the following applications:
- Poppler (necessary to convert pdf to text and get information about number of pages in file)
- Tesseract (necessary to read and interpret png file)
- ImageMagick (necessary to convert pdf->png)
Make sure you have a package-manager installed on your system.
Automated installation
Run the following code from the source folder to autoinstall all dependencies and tesseract language files:
php install/install_dependencies.php
Manual installation with homebrew
If homebrew is installed run the following commands to install the Homebrew packages:
brew install poppler tesseract imagemagick
Manual installation of Tesseract Language Files
You also need to install the required Tesseract language files. You can check the available languages at: https://github.com/tesseract-ocr/tessdata_best/
Download the necessary language files and place them in the appropriate directory. To find the directory use:
tesseract --list-langs
Usage
Create Object
<?php require_once '../vendor/autoload.php'; use PdfInterpreter\PdfInterpreter; //get path from terminal: 'echo $PATH' $path_env = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin:/opt/homebrew/bin"; $pdf = new PdfInterpreter($path_env);
Get Sample Output
Using the get_sample_output-Method will allow you to get a sample of a text output without any interpretation of patterns.
<?php require_once '../vendor/autoload.php'; use PdfInterpreter\PdfInterpreter; //get path from terminal: 'echo $PATH' $path_env = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin:/opt/homebrew/bin"; $pdf = new PdfInterpreter($path_env); print_r($pdf->get_sample_output());
Set new template
Using the add_new_template-Method will help you to create a new template.
For more informations about the demanded parameters read the DocBloc of the method.
<?php require_once '../vendor/autoload.php'; use PdfInterpreter\PdfInterpreter; //get path from terminal: 'echo $PATH' $path_env = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin:/opt/homebrew/bin"; $pdf = new PdfInterpreter($path_env); $pdf->add_new_template("sample","Sample","/[Cc]ompany[\W]?[Aa][Bb][Cc]/","1","eng");
Add pattern to template
Using the add_pattern_to_template-Method will help you to add a new pattern to an existing template.
For more informations about the demanded parameters read the DocBloc of the method.
$pdf->add_pattern_to_template("sample","invoice_no","/INVOICE # *([\d]*)/","1"); $pdf->add_pattern_to_template("sample","date","/INVOICE DATE *([\d]{2}.[\d]{2}.[\d]{4})/","1"); $pdf->add_pattern_to_template("sample","positions","/([\d]{1,4}) *(.*?) *([\d]{1,8},[\d]{2}) *([\d]{1,8},[\d]{2})/m","a",true,['pieces','item','price','amount']);
Get Template
Using the get_template-Method will return the entire template.
For more informations about the demanded parameters read the DocBloc of the method.
print_r($pdf->get_template("sample"));
Delete Template
Using the delete_template-Method will delete the entire template.
For more informations about the demanded parameters read the DocBloc of the method.
print_r($pdf->delete_template("sample"));
Convert Files from Folder
Using the convert_folder-Method will convert all files from a folder into an array of data.
For more informations about the demanded parameters read the DocBloc of the method.
print_r(print_r($pdf->convert_folder("/../docs/",true,false,ocr_lang: "eng")));
Convert File
Using the convert_file-Method will convert a single file into an array of data.
For more informations about the demanded parameters read the DocBloc of the method.
print_r($pdf->convert_file("/../docs/sample-bill.pdf",true,false));
joest8/pdfinterpreter 适用场景与选型建议
joest8/pdfinterpreter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 11 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 joest8/pdfinterpreter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 joest8/pdfinterpreter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-11-05