我正在使用DOMPDF从HTML生成PDF.我已经从github(编码分支)复制了所有必需的文件.但是它说类DOMPDF没有错误,如下所示.
链接为gitbub中的dompdf_config.inc.php: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
Run Code Online (Sandbox Code Playgroud)
实际产出是:
致命错误:第30行/home/web/www/test_dompdf.php中找不到"DOMPDF"类
30号线是 $dompdf = new DOMPDF();
注意:其他Master Branch工作正常.我需要这个编码分支,因为它解决了编码字体相关的问题.
我已经测试了你的代码,它对我来说很好 - 在浏览器中下载了sample.pdf文件.我从https://github.com/dompdf/dompdf/releases/tag/v0.6.1 url 下载了库(不仅是编码分支(
可能您没有将整个项目移动到选定的目录,或者您没有下载整个库.我将整个下载的目录内容移动到APIs/dompdf-encoding目录,我在这里有文件dompdf_config.inc.php和目录lib,include和www.
编辑
在编辑时,您只想使用编码分支,您需要做的是在文件的开头添加以下代码:
use Dompdf\Adapter\CPDF;
use Dompdf\Dompdf;
use Dompdf\Exception;
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
我也改变了DOMPDF以Dompdf以防万一(在Windows两者都工作)