我需要转换一些pdf文件为HTML。我下载了PHP版的pdftohtml,但我不知道如何使用它。我试着用下面的代码运行它:
<?php
include 'pdf-to-html-master/src/Gufy/PdfToHtml.php';
$pdf = new \Gufy\PdfToHtml;
$pdf->open('1400.pdf');
$pdf->generate();
?>这会导致一个空白的网页。
我需要修改什么?运行此脚本的正确代码是什么?
发布于 2015-07-09 15:55:16
第一个选项是使用弹出器实用程序
<?php
// if you are using composer, just use this
include 'vendor/autoload.php';
// if not, use this
include 'src/Gufy/PdfToHtml.php';
// initiate
$pdf = new \Gufy\PdfToHtml;
// opening file
$pdf->open('file.pdf');
// set different output directory for generated html files
$pdf->setOutputDirectory('/your/absolute/directory/path');
// do this if you want to convert in the same directory as file.pdf
$pdf->generate();
// you think your generated files is annoying? simple do this to remove the whole files
$pdf->clearOutputDirectory();
?>Download library from here的第二个选项可能是使用pdf.js
PDFJS.getDocument('helloworld.pdf')发布于 2015-10-28 08:00:37
我是包的维护者。程序包已更新。您已经使用最新版本了吗?而且,如果您使用的是Windows,请再次阅读文档。另外,请不要直接从github下载,请使用composer。
发布于 2020-05-10 13:14:44
include 'vendor/autoload.php';
use Gufy\PdfToHtml\Pdf;
use PHPHtmlParser\Dom;
use DateTime;公共函数parsepdf(请求$request) {
$pdf = new Pdf($request->file('csv_file'));
$html = $pdf->html();
$dom = new Dom;
$total_pages = $pdf->getPages();
if ($total_pages == 1) {
$html->goToPage(1);
$dom->load($html);
$paragraphs = $dom->find('p');
$paragraphs = collect($paragraphs);
foreach($paragraphs as $p){
$datestring = preg_replace('/\xc2\xa0/', ' ', trim($p->text));
echo $datestring;
}
}上面的代码用于在laravel中将pdf转换为html
composer需要gufy/pdftohtml-php:~2
Poppler-Utils (如果您使用的是Ubuntu发行版,只需从apt安装它) sudo apt-get install poppler-utils
https://stackoverflow.com/questions/31311004
复制相似问题