dompdf->渲染();不在 api class 工作
dompdf->render(); not working in api class
我在尝试使用 dompdf 将 html 呈现为 pdf 时遇到问题。
我将代码放在 class 中,在程序代码之后我希望它创建 html 的 pdf。
这是我目前的代码:
$templatefile = file_get_contents("templates/costreport.htm");
//fill headers
$templatefile = str_replace("%DATES%",stripslashes($startdate)." - ".stripslashes($enddate),$templatefile);
if ($siteid>0) {
$pdfname = "costreport-".$clientid.".pdf";
} else {
$pdfname = "costreport-".$clientid."-".$siteid.".pdf";
}
//insert into database
//Close and output PDF document
$pdfname = str_replace("/","-",$pdfname);
$pdfname = str_replace("\","-",$pdfname);
//create pdf
// unregister Yii's autoloader
spl_autoload_unregister('my_autoloader');
// register dompdf's autoloader
require_once("../system/dompdf/dompdf_config.inc.php");
// register Yii's autoloader again
spl_autoload_register('my_autoloader');
$dompdf = new DOMPDF();
$dompdf->set_paper("A4","portrait");
$dompdf->load_html($templatefile);
//set_time_limit(240);
$dompdf->render();
$pdf = $dompdf->output();
// You can now write $pdf to disk, store it in a database or stream it
// to the folder.
file_put_contents('../tmp/'.$clientid.'/'.$pdfname, $pdf);
dompdf->render(); 时代码失败是在但是一旦我取出那行代码工作并且文件被创建但是如果它没有呈现我无法打开它。
我试过调试代码并使模板 HTML 有效,但我现在不知所措。
当我 运行 脚本中包含 dompdf->render();
时,我返回的错误只是 boolen false
。
问题是我的 class 顶部有这段代码。
/set up path to new dir including dir to be created
chdir("../tmp/");
$newdirpath = getcwd()."/".$clientid;
//if an old invoice ticket pack exists unlink it so as not to get things confused with the new pack being created.
if (file_exists(getcwd()."/$clientid_$siteid_CostReport.pdf")) {
unlink(getcwd()."/$clientid_$siteid_CostReport.pdf");
}
//setup temp dir
if (!is_dir($newdirpath)) {
//create new dir if it doesn't already exist!
mkdir($newdirpath);
} else {
//dir already exists we need to empty it out first incase there's old stuff in there we don't want to duplicate data
//$this->removedirectory($newdirpath,false);
}
我在尝试使用 dompdf 将 html 呈现为 pdf 时遇到问题。
我将代码放在 class 中,在程序代码之后我希望它创建 html 的 pdf。
这是我目前的代码:
$templatefile = file_get_contents("templates/costreport.htm");
//fill headers
$templatefile = str_replace("%DATES%",stripslashes($startdate)." - ".stripslashes($enddate),$templatefile);
if ($siteid>0) {
$pdfname = "costreport-".$clientid.".pdf";
} else {
$pdfname = "costreport-".$clientid."-".$siteid.".pdf";
}
//insert into database
//Close and output PDF document
$pdfname = str_replace("/","-",$pdfname);
$pdfname = str_replace("\","-",$pdfname);
//create pdf
// unregister Yii's autoloader
spl_autoload_unregister('my_autoloader');
// register dompdf's autoloader
require_once("../system/dompdf/dompdf_config.inc.php");
// register Yii's autoloader again
spl_autoload_register('my_autoloader');
$dompdf = new DOMPDF();
$dompdf->set_paper("A4","portrait");
$dompdf->load_html($templatefile);
//set_time_limit(240);
$dompdf->render();
$pdf = $dompdf->output();
// You can now write $pdf to disk, store it in a database or stream it
// to the folder.
file_put_contents('../tmp/'.$clientid.'/'.$pdfname, $pdf);
dompdf->render(); 时代码失败是在但是一旦我取出那行代码工作并且文件被创建但是如果它没有呈现我无法打开它。
我试过调试代码并使模板 HTML 有效,但我现在不知所措。
当我 运行 脚本中包含 dompdf->render();
时,我返回的错误只是 boolen false
。
问题是我的 class 顶部有这段代码。
/set up path to new dir including dir to be created
chdir("../tmp/");
$newdirpath = getcwd()."/".$clientid;
//if an old invoice ticket pack exists unlink it so as not to get things confused with the new pack being created.
if (file_exists(getcwd()."/$clientid_$siteid_CostReport.pdf")) {
unlink(getcwd()."/$clientid_$siteid_CostReport.pdf");
}
//setup temp dir
if (!is_dir($newdirpath)) {
//create new dir if it doesn't already exist!
mkdir($newdirpath);
} else {
//dir already exists we need to empty it out first incase there's old stuff in there we don't want to duplicate data
//$this->removedirectory($newdirpath,false);
}