项目作者: JayBizzle

项目描述 :
Extract text from a Word Doc
高级语言: PHP
项目地址: git://github.com/JayBizzle/doc-to-text.git
创建时间: 2018-12-05T19:50:27Z
项目社区:https://github.com/JayBizzle/doc-to-text

开源协议:MIT License

下载


Extract text from a Word Doc

Latest Version on Packagist
Software License
Build Status
Quality Score
Total Downloads

This package provides a class to extract text from a Word Doc.

  1. <?php
  2. use Jaybizzle\DocToText\Doc;
  3. echo Doc::getText('book.doc'); // returns the text from the doc

Requirements

Behind the scenes this package leverages antiword. You can verify if the binary is installed on your system by issuing this command:

  1. which antiword

If it is installed it will return the path to the binary.

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

  1. apt-get install antiword

Installation

You can install the package via composer:

  1. composer require jaybizzle/doc-to-text

Usage

Extracting text from a Doc is easy.

  1. $text = (new Doc())
  2. ->setDoc('book.doc')
  3. ->text();

Or easier:

  1. echo Doc::getText('book.doc');

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

  1. $text = (new Doc('/custom/path/to/antiword'))
  2. ->setDoc('book.doc')
  3. ->text();

or as the second parameter to the getText static method:

  1. echo Doc::getText('book.doc', '/custom/path/to/antiword');

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

  1. $text = (new Doc())
  2. ->setDoc('table.doc')
  3. ->setOptions(['f', 'w 80'])
  4. ->text()
  5. ;

or as the third parameter to the getText static method:

  1. echo Doc::getText('book.doc', null, ['f', 'w 80']);

Change log

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

Testing

  1. composer test

Security

If you discover any security related issues, please email mbeech@mark-beech.co.uk instead of using the issue tracker.

Credits

License

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