skuola/pdf-text-parser

解析pdftotext产生的XML库

v0.4.2 2023-10-30 13:40 UTC

README

Build Status Code Climate SensioLabsInsight

此库是用于解析通过pdftotext获得的XML文本文件的解析器

您可以使用以下命令安装它:composer require skuola/pdf-text-parser

假设您刚刚转换了一个PDF文件,获取了一些如下所示的文本

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<doc>
  <page width="595.200000" height="841.800000">
    <word xMin="56.640000" yMin="59.770680" xMax="118.022880" yMax="72.406680">Lorem</word>
    <word xMin="121.209960" yMin="59.770680" xMax="176.485440" yMax="72.406680">ipsum</word>
  </page>
</doc>
</body>
</html>

上述文本是以下命令的结果:pdftotext -htmlmeta -bbox-layout yourfile.pdf -

您可以使用此库如下

<?php

require_once 'vendor/autoload.php';

$data = '...';  // the text above

$converter = new \Skuola\PdfTextParser\Converter($data);
// get as plain text...
$txt = $converter->getAsText();
// ...or get as HTML
$html = $converter->getAsHtml();

作为备用模式,您可以保存您的HTML文件并将其传递给库

<?php

require_once 'vendor/autoload.php';

$path = '...';  // a path containing the same text as previous example

$converter = new \Skuola\PdfTextParser\Converter(null, $path);
$html = $converter->getAsHtml();

生成的HTML由每个文档行的<h2>标签或<p>标签组成(取决于该行是否是标题)。

更多信息将陆续发布...