douou6696 2014-06-30 19:09
浏览 105
已采纳

PHP致命错误:第30行找不到类'DOMPDF'

I am using DOMPDF to generate PDFs from HTML. I have copied all required files from github (encoding branch). But it says class DOMPDF not error as below.

link for dompdf_config.inc.php in gitbub : https://github.com/dompdf/dompdf/tree/encoding

Here is my code :

require_once("APIs/dompdf-encoding/dompdf_config.inc.php");     
$cart_body='<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>New Order Placed</title></head><body><p>Test Printing...</p></body></html>';
        $dompdf = new DOMPDF();
        $dompdf->load_html($cart_body);//body -> html content which needs to be converted as pdf..
        $dompdf->render();
        $dompdf->stream("sample.pdf"); //To popup pdf as download

Actual Output is :

Fatal error: Class 'DOMPDF' not found in /home/web/www/test_dompdf.php on line 30

Line 30 is $dompdf = new DOMPDF();

Note: Other Master Branch is working fine. I need this encoding branch as it solves encoding font related issues.

  • 写回答

1条回答 默认 最新

  • doubi1931 2014-06-30 19:11
    关注

    I've tested your code and it works fine for me - sample.pdf file is being downloaded in browser. I've downloaded library from https://github.com/dompdf/dompdf/releases/tag/v0.6.1 url (not only the encoding branch(

    Probably you haven't moved the whole project to selected directory or you haven't downloaded the whole library. I moved the whole downloaded directory content to APIs/dompdf-encoding directory and I have here files dompdf_config.inc.php and directories lib, include and www.

    EDIT

    As you edited you want to use only encoding branch, what you have to do is adding the following code at the beginning of your file:

    use Dompdf\Adapter\CPDF;
    use Dompdf\Dompdf;
    use Dompdf\Exception;
    

    EDIT2

    The whole working code:

    <?php
    use Dompdf\Adapter\CPDF;
    use Dompdf\Dompdf;
    use Dompdf\Exception;
    
    
    
            require_once("APIs/dompdf-encoding/dompdf_config.inc.php");     
    $cart_body='<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>New Order Placed</title></head><body><p>Test Printing...</p></body></html>';
            $dompdf = new Dompdf();
            $dompdf->load_html($cart_body);//body -> html content which needs to be converted as pdf..
            $dompdf->render();
            $dompdf->stream("sample.pdf"); //To popup pdf as download
    

    I have also changed DOMPDF to Dompdf just in case (in Windows both are working)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog