为什么80%的码农都做不了架构师?>>>
由于项目用到的导出pdf的html样式比较复杂,处于对pdf格式的考虑,放弃了fpdf.php
dompdf下载地址:/p/dompdf/downloads/list包括官方导出pdf的例子
设置配置文件 dompdf_config.inc.php 288def("DOMPDF_ENABLE_REMOTE", true);
require(SITE_PATH.'/libs/dompdf/dompdf_config.inc.php');$content = $this->view->fetch('sample*');$contents = stripslashes($content);$html = $this->replace_html_tag($contents,'script',true);$dompdf = new DOMPDF();$dompdf->load_html($html);$dompdf->set_paper('letter', 'portrait');$dompdf->render();$dompdf->stream("sample.pdf", array("Attachment" => true));exit(0);
//删除指定的HTML标签及其中内容function replace_html_tag($string, $tagname, $clear = false){$re = $clear ? '' : '\1';$sc = '/<' . $tagname . '(?:\s[^>]*)?>([\s\S]*?)?<\/' . $tagname . '>/i';return preg_replace($sc, $re, $string);}// 去掉 style 及包含内容$string = replace_html_tag($string, 'style', true);
如果觉得《PHP导出pdf文件_dompdf》对你有帮助,请点赞、收藏,并留下你的观点哦!