【问题标题】:Class 'Smalot\PdfParser\Parser' not found找不到类“Smalot\PdfParser\Parser”
【发布时间】: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


【解决方案1】:

不知何故,你的道路并不适合

require 'vendor/autoload.php';

验证是否实际包含自动加载。

Codeigniter3/4 中确保将路径放在配置文件中

$config['composer_autoload'] = 'vendor/autoload.php';

然后在您的控制器/库中

    // Parse pdf file and build necessary objects.
    $parser = new \Smalot\PdfParser\Parser();
    $pdf    = $parser->parseFile(FCPATH . 'includes/temp/' . $pdf_file);
    
    return $pdf->getText();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-19
    相关资源
    最近更新 更多