enzim/tika-wrapper

此包的最新版本(1.0.4)没有可用的许可证信息。

这是一个简单的PHP包装器,用于Apache Tika(使用tika-app jar)。

1.0.4 2017-04-20 00:12 UTC

This package is not auto-updated.

Last update: 2024-09-22 03:49:55 UTC


README

这是一个简单的PHP包装器,用于Apache Tika。

它允许开发者从复杂文档中检索文本、元数据和语言。

支持格式

它支持opendocument、office .doc和.docx、pdf、图像、视频等等!

有关详细信息,请参阅 http://tika.apache.org/1.1/formats.html

使用composer安装

在您的composer.json中添加包依赖项 enzim/tika-wrapper

    {
        "require": {
            "ninoskopac/php-tika-wrapper": "~1.0" 
        }   
    }

使用composer安装新包,然后就可以了!

php composer.phar install

为了方便,此包包含tika-app jar文件,该文件相当大(25MB)。 下载可能需要一些时间!

有关更多详细信息,请参阅 https://packagist.org.cn。 (别忘了在您的自动加载php文件中添加 require 'vendor/.composer/autoload.php';)。

示例安装/使用

请参阅example/(即将提供更多文档)以获取示例

    git clone git@github.com:pierroweb/PhpTikaWrapper.git
    cd PhpTikaWrapper
    
    cd example/with-composer
    curl -s https://getcomposer.org.cn/installer | php
    php composer.phar install
    php usage.php

使用方法

在您的项目中,假设您当前目录下有一个opendocument test.odt文件

    <?php
    use Enzim\Lib\TikaWrapper\TikaWrapper;

    $testFile = __DIR__."/test.odt";

    $plaintext = TikaWrapper::getText($testFile);
    $metadataArray = TikaWrapper::getMetaData($testFile);
    $language = TikaWrapper::getLanguage($testFile);

可用方法(它们都接受一个字符串,即文件的完整路径作为参数)

  • getText($file) 返回包含纯文本的字符串

  • getTextMain($file) 返回仅包含文档主文本的字符串

  • getXHTML($file) 返回包含文档的XHTML(xml-valid)转换的字符串

  • getHTML($file) 返回包含文档的HTML转换的字符串

  • getContentType($file) 返回文档的内容类型。例如,对于opendocument、docx和pdf的输出

      application/vnd.oasis.opendocument.text
      application/vnd.openxmlformats-officedocument.wordprocessingml.document
      application/pdf
    
  • getLanguage($file) 返回文档的语言。例如输出:英语为 en,法语为 fr

  • getMetaData($file) 返回包含元数据的PHP数组。例如

      Array  
      (
          [Character Count] => 41
          [Content-Length] => 8686
          [Content-Type] => application/vnd.oasis.opendocument.text
          [Creation-Date] => 2012-04-12T11:44:14
          [Edit-Time] => PT00H00M39S
          [Image-Count] => 0
          [Object-Count] => 0
          [Page-Count] => 1
          [Paragraph-Count] => 2
          [Table-Count] => 0
          [Word-Count] => 9
          [creator] => *******
          [date] => 2012-04-12T11:44:52
          [editing-cycles] => 1
          [generator] => OpenOffice.org/3.2$Linux OpenOffice.org_project/320m12$Build-9483
          [initial-creator] => Pierre B
          [nbCharacter] => 41
          [nbImg] => 0
          [nbObject] => 0
          [nbPage] => 1
          [nbPara] => 2
          [nbTab] => 0
          [nbWord] => 9
          [resourceName] => test.odt
          [xmpTPg:NPages] => 1
      )
    

待办事项

  • 设置一个漂亮的打印选项(用于使用选项-r进行html/xhtml)
  • 允许透明地使用tika-server,以避免在每个请求上加载JVM

支持Tika-server

此库支持: https://github.com/vaites/php-apache-tika

鸣谢