PHP导出pdf文件_dompdf

 由于项目用到的导出pdf的html样式比较复杂,处于对pdf格式的考虑,放弃了fpdf.php

dompdf下载地址:http://code.google.com/p/dompdf/downloads/list 包括官方导出pdf的例子

设置配置文件 dompdf_config.inc.php    288 def("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); 

你可能感兴趣的:(dompdf,php导出pdf)