PHP致命错误:第30行未找到类“ DOMPDF” [英] PHP Fatal error : Class 'DOMPDF' not found on line 30
问题描述
我正在使用DOMPDF从HTML生成PDF。
我已经从github复制了所有必需的文件(编码分支)。
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.
gitbub中dompdf_config.inc.php的链接: https://github.com/dompdf/dompdf/tree/encoding
link for dompdf_config.inc.php in gitbub : https://github.com/dompdf/dompdf/tree/encoding
此处是我的代码:
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
实际输出为:
致命错误:在第30行的/home/web/www/test_dompdf.php
中找不到类'DOMPDF'
Fatal error: Class 'DOMPDF' not found in /home/web/www/test_dompdf.php on line 30
第30行是 $ dompdf = new DOMPDF();
注意:其他主分支工作正常。我需要这个编码分支,因为它可以解决与字体有关的编码问题。
Note: Other Master Branch is working fine. I need this encoding branch as it solves encoding font related issues.
推荐答案
我已经测试了您的代码,对我来说很好-sample.pdf文件正在浏览器中下载。我已经从 https://github.com/dompdf/dompdf/releases下载了库/tag/v0.6.1 网址(不仅是编码分支(
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(
可能您没有将整个项目移至所选目录,或者您没有我下载了整个库,然后将整个下载目录内容移到了 APIs / dompdf-encoding
目录中,这里有文件 dompdf_config.inc.php
和目录 lib
, include
和 www
。
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
.
编辑
编辑时,您只想使用编码分支,您需要做的是在文件开头添加以下代码:
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
整个工作代码:
<?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
我还更改了 DOMPDF
到 Dompdf
以防万一(在Windows中都可以使用)
I have also changed DOMPDF
to Dompdf
just in case (in Windows both are working)
这篇关于PHP致命错误:第30行未找到类“ DOMPDF”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!