escarter/poppler-wrapper-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

escarter/poppler-wrapper-php

Composer 安装命令:

composer require escarter/poppler-wrapper-php

包简介

This is a php wrapper for Poppler Utility tools

README 文档

README

This package provides a class to extract text from a pdf.

use Escarter\PopplerPhp\PdfToText;
use Escarter\PopplerPhp\getOutput;

echo PdfToText::getText('document.pdf','/opt/homebrew/bin/pdftotext'); //returns the text from the pdf
echo PdfSeparate::getOutput('document.pdf','/opt/homebrew/bin/pdfseparate','destination_path/page_%d.pdf'); //returns null

Requirements

Behind the scenes this package leverages pdftotext and pdfseparate.You can verify if the binary installed on your system by issueing this command:

which pdftotext
which which pdfseparate

If they are installed the above commands will return the path to the binary.

To install the binary you can use this command on Ubuntu or Debian:

apt-get install poppler-utils

On a mac you can install the binary using brew

brew install poppler

If you're on RedHat or CentOS use this:

yum install poppler-utils

Installation

You can install the package via composer:

composer require escarter/poppler-wrapper-php

Usage Extracting text

Extracting text from a pdf is easy.

$text = (new PdfToText())
    ->setPdf('document.pdf')
    ->text();

Or easier:

echo PdfToText::getText('document.pdf');

By default the package will assume that the pdftotext command is located at /usr/bin/pdftotext. If it is located elsewhere pass its binary path to constructor

$text = (new PdfToText('/custom/path/to/pdftotext'))
    ->setPdf('document.pdf')
    ->text();

or as the second parameter to the getText static method:

echo PdfToText::getText('document.pdf', '/custom/path/to/pdftotext');

Sometimes you may want to use pdftotext options. To do so you can set them up using the setOptions method.

$text = (new PdfToText())
    ->setPdf('table.pdf')
    ->setOptions(['layout', 'r 96'])
    ->text()
;

or as the third parameter to the getText static method:

echo PdfToText::getText('document.pdf', null, ['layout', 'opw myP1$$Word']);

Please note that successive calls to setOptions() will overwrite options passed in during previous calls.

If you need to make multiple calls to add options (for example if you need to pass in default options when creating the Pdf object from a container, and then add context-specific options elsewhere), you can use the addOptions() method:

$text = (new PdfToText())
    ->setPdf('table.pdf')
    ->setOptions(['layout', 'r 96'])
    ->addOptions(['f 1'])
    ->text()
;

Usage Separating Pdf into single files for each page

Separating a single pdf file into multiple files for each page.

 (new PdfSeparate())
    ->setPdf('document.pdf')
    ->setDestination('destination_path/page_%d.pdf')
    ->split();

Or easier:

 PdfSeparate::getOutput('document.pdf','destination_path/page_%d.pdf');

Once this is executed you can check in the destination_path to see all the splitted files (page_1.pdf, page_2.pdf....)

Change log

Please see CHANGELOG for more information about what has changed recently.

Testing

 composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email mbutuhescarter@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 5.39k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固