webgriffe/pdftotext-bundle

此扩展集将 Symfony2 与 pdftotext 二进制命令集成。

安装次数: 27,805

依赖项: 0

建议者: 0

安全性: 0

星标: 3

关注者: 5

分支: 3

开放问题: 0

类型:symfony-bundle

1.1.0 2017-04-24 16:35 UTC

This package is auto-updated.

Last update: 2024-09-07 20:57:57 UTC


README

此 Symfony2 扩展允许您将输入的 PDF 文件转换为纯文本。

转换通过 pdftotext 命令行工具(http://en.wikipedia.org/wiki/Pdftotext)进行。 pdftotext 是 Xpdf 软件套件的一部分,包含在许多 Linux 发行版中,也应适用于 Mac OS X 和 Windows 平台。

安装

像安装其他任何 Symfony2 扩展一样安装此扩展。

Symfony >= 2.1.x

将以下要求添加到您的 composer.json

"require": {
	…
	"webgriffe/pdftotext-bundle": "dev-master"
}

使用以下命令安装扩展

$ composer update webgriffe/pdftotext-bundle

AppKernel 中注册扩展

public function registerBundles()
{
	…
	new Webgriffe\PdfToTextBundle\WebgriffePdfToTextBundle(),
}

Symfony 2.0.x

在您的 deps 文件中添加以下要求

…
[WebgriffePdfToTextBundle]
	git=git://github.com/webgriffe/pdftotext-bundle.git
	target=bundles/Webgriffe/PdfToTextBundle

使用以下命令安装扩展

$ bin/vendors install

AppKernel 中注册扩展

public function registerBundles()
{
	…
	new Webgriffe\PdfToTextBundle\WebgriffePdfToTextBundle(),
}

用法

简单来说,您可以从 DIC 获取 PdfToTextConverter 并获取纯文本字符串。

// Acme\MyBundle\Controller\MyController

public function myAction()
{
	$pdfFile = '/path/to/file.pdf';
	$pdfToTextConverter = $this->get('webgriffe_pdf_to_text.converter');
	$pdfText = $pdfToTextConverter->convert($pdfFile);
	
	return new \Symfony\Component\HttpFoundation\Response($pdfText);
}

您还可以指定输出编码(默认为 UTF-8)。

$pdfText = $pdfToTextConverter->convert($pdfFile, 'ISO-8859-1');

指定 pdftotext 二进制路径

您可以在 config.yml 中指定 pdftotext 二进制路径

webgriffe_pdf_to_text:
    bin_path: /usr/local/bin/pdftotext

致谢

此扩展由 Webgriffe® 开发。请通过 GitHub 问题报告任何错误或建议。