【问题标题】:PHPExcel + mPDF class 'Mpdf' not found未找到 PHPExcel + mPDF 类“Mpdf”
【发布时间】:2017-11-01 17:22:34
【问题描述】:

创建 tcPDF 文件后,文件大小为 800+kB,但完全为空/白色,我查看了 Composer 和 mPDF。安装在本地机器上并将文件夹“供应商”复制到我的网站空间。

我的文件结构:

/WWW/class/my-own-classes
          /PHPExcel
          /vendor/composer
          /vendor/mpdf/mpdf
    /project1/../../../executing-file.php
    /project2/

我结合了我以前的自动加载器和 composer-autoloader 类似的以下内容。

require_once '../../DomainNameClass.php';
spl_autoload_register(function($class) {
    $path = New DomainName("project","intern");
    if($class == 'PHPExcel') {
        require_once $path->classPath . $class . '.php';
    } 
    elseif ( file_exists( $path->classPath . strtolower($class) . 'Class.php' ) ) {
        require_once $path->classPath . strtolower($class) . 'Class.php';
    }
});

$path = New DomainName("dinelco","intern");
require $path -> classPath . "/vendor/autoload.php";

在我的 PHPExcel-Helper 类之外:

private function setMPDF() {
        $this->rendererName = PHPExcel_Settings::PDF_RENDERER_MPDF;
        $this->rendererLibrary = 'mpdf7.0.0';
        $this->rendererLibraryPath = dirname(__FILE__).'/vendor/mpdf/mpdf/src';
    }

如果找不到此文件,PHPExcel 中的 mPDF.php 将引发异常。 因为现在我没有遇到异常,所以我认为我的路径是正确的。

但是:来自 PHPExcel/mPDF.php 的测试回显对我来说看起来不错:

"found: /is/htdocs/something/www/class/vendor/mpdf/mpdf/src/Mpdf.php" 

然后:

Fatal error: Class 'Mpdf' not found in /is/htdocs/something/www/class/PHPExcel/Writer/PDF/mPDF.php on line 96

在 Github mPDF 上,我阅读了有关版本的信息,但我得到了最后一个稳定版本 (7.0),它应该被称为“new mPDF();”而是“新\Mpdf\Mpdf();”但这也没有成功。

现在正在寻找一些小时。 我的错在哪里?

【问题讨论】:

  • 你的 mpdf 版本是多少?

标签: phpexcel mpdf


【解决方案1】:

据我所知,你必须使用

$mpdf = new \Mpdf\Mpdf();

而不是

$mpdf = new Mpdf();

在我的情况下它有效。

【讨论】:

    【解决方案2】:

    我就是这样工作的。

        try {
            $mpdf = new Mpdf();
        } catch (MpdfException $e) {
            return $e->getMessage();
        }
    

    【讨论】:

      【解决方案3】:

      如果你使用composer安装MPDF,你需要在你的PHP代码中注明:

       use \Mpdf\Mpdf;
      

      然后,您可以使用:

      $myMpdfVar = new Mpdf();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多