目前只在windows/linux测试,安装 WkHtmlToPdf/WkHtmlToImage工具,如转换过程出现乱码,请安装相应中文字体 下载地址:http://code.google.com/p/wkhtmltopdf/
function convert($type='pdf')
{
$filename=time();
$url=$this->input->get("url");
if($type=='pdf')
{
$filename="upload/tmp/".$filename.".pdf";
exec("/home/phptool/wkhtmltopdf-i386 $url $filename");
header('Content-Type: application/pdf');
}
elseif($type=='image')
{
$filename="upload/tmp/".$filename.".jpg";
exec("/home/phptool/wkhtmltoimage-i386 $url $filename");
header('Content-Type: image/jpeg');
}
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($filename));
readfile("$filename");
}
//以下测试代码
$result = exec("e:\\wkhtmltopdf\\wkhtmltopdf.exe -O Landscape \"http://127.0.0.1:89/index.php?app=detail&action=detail_pdf&id=200\" vish.pdf",$out,$status);// $result = shell_exec('"e:\\wkhtmltopdf\\wkhtmltopdf.exe" "http://127.0.0.1/?app=detail&action=detail_pdf&id=220" vish.pdf 2>> err3.txt 1>> out3.txt');echo $result;$file = "vish.pdf";$pdf = file_get_contents("vish.pdf");header('Content-Type: application/pdf');header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1header('Pragma: public');header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the pastheader('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');header('Content-Length: '.strlen($pdf));header('Content-Disposition: inline; filename="'.basename($file).'";');ob_clean(); flush(); echo $pdf;