【发布时间】:2014-12-24 10:15:16
【问题描述】:
我正在尝试使用 Pdfparser 库来解析 PDF 文件,但在类包含方面存在一些问题。
我阅读了documentation,但它不起作用。
我使用 Windows 和 XAMPP。
- 我在
/xampp/htdocs/pdf_import中创建了一个目录 - 我安装了 Composer,并在
pdfparser-master/src中生成了/vendor/autoload.php - 我使用文档中的代码示例
例子:
<?php
require 'vendor/autoload.php';
// Parse pdf file and build necessary objects.
$parser = new \Smalot\PdfParser\Parser();
$pdf = $parser->parseFile('document.pdf');
// Retrieve all pages from the pdf file.
$pages = $pdf->getPages();
// Loop over each page to extract text.
foreach ($pages as $page) {
echo $page->getText();
}
当我运行 php 脚本时,我得到这个错误:
致命错误:在第 8 行的 C:\xampp\htdocs\pdf_import\pdfparser-master\src\import.php 中找不到类 'Smalot\PdfParser\Parser'
【问题讨论】:
-
使用
require而不是include。 - 参见Difference between “include” and “require” in php -
通过使用 require 我没有区别
-
但是您可以确定
vendor/autoload.php文件已被加载。我只是出于这个原因建议它,而不是因为您在错误的地方进行故障排除。 -
那么,为了进一步解决这个问题:您对错误消息的哪一部分有疑问?你的问题究竟是什么?
-
您在哪个目录中执行了文档中的
composer update smalot/pdfparser命令?
标签: php pdf-parsing