wbrframe / pdf-to-html
使用工具(如poppler-utils)的PHP PDF到HTML转换器
此软件包的官方仓库似乎已不存在,因此软件包已被冻结。
v2.0
2020-04-02 23:49 UTC
Requires
- php: ^7.0
- symfony/dom-crawler: ^5.0
- symfony/filesystem: ^5.0
- symfony/process: ^5.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- phpstan/phpstan: ^0.12.18
This package is auto-updated.
Last update: 2023-12-29 03:31:42 UTC
README
使用PHP和工具(如poppler-utils)的PDF到HTML转换器。目前仅支持poppler-utils。
重要
来自软件包poppler-utils的PdfToHtml总是以以下标志执行
-s
# 单个文件-i
# 无图像-noframes
# 无iframe
安装
当你处于活动目录 apps 中时,你可以运行此命令以将此软件包添加到你的应用
composer req wbrframe/pdf-to-html
要求
- Poppler-Utils(如果你使用Ubuntu发行版,只需从apt安装即可)
sudo apt-get install poppler-utils
使用方法
在此示例中,HTML文件将在系统临时文件夹中的子文件夹 output
下创建一个随机名称。例如:/tmp/output/5e8671ec8e0283.34152860.html
<?php use Wbrframe\PdfToHtml\Converter\ConverterFactory; // if you are using composer, just use this include 'vendor/autoload.php'; // initiate $converterFactory = new ConverterFactory('test.pdf'); $converter = $converterFactory->createPdfToHtml(); $html = $converter->createHtml(); // Get absolute path created HTML file $htmlFilePath = $html->getFilePath(); // or get Crawler (symfony/dom-crawler) $crawler = $html->createCrawler(); ?>
你可以更改一些选项,如 outputFolder
、outputFilePath
和 binPath
,其中选项 outputFolder
是HTML将被创建的文件夹,outputFilePath
是你想要创建的HTML文件的绝对路径,binPath
是 pdftohtml
的路径
注意:如果指定了 outputFilePath
,则选项 outputFolder
将被忽略。
<?php use Wbrframe\PdfToHtml\Converter\ConverterFactory; use Wbrframe\PdfToHtml\Converter\PopplerUtils\PdfToHtmlOptions; // if you are using composer, just use this include 'vendor/autoload.php'; $converterFactory = new ConverterFactory('test.pdf'); $options = (new PdfToHtmlOptions()) ->setBinPath('/path/pdftohtml') ->setOutputFolder('/app/output') ->setOutputFilePath('/app/output/file.html') ; $converter = $converterFactory->createPdfToHtml($options); $html = $converter->createHtml(); ?>