您的位置:首页 > Web前端 > HTML

wkhtmltopdf Windows下 测试demo 成功

2017-03-14 15:54 441 查看
html2pdf 转pdf 中文不换行 然后找到了wkhtmltopdf 支持中文换行 样式也支持

在PHP中生成PDF文件,可以使用 FPDF 和 TCPDF 。但是它们只能用于创建简单的表格,当涉及到需要将图像添加到表中,就无法产生所需的布局。有一个强大的工具叫wkhtmltopdf就能够实现。

Wkhtmltopdf 是一个shell工具,它使用了WebKit渲染引擎和QT,将HTML转换为PDF格式。

wkhtmltopdf 下载地址 http://www.softpedia.com/get/Office-tools/PDF/wkhtmltopdf.shtml
$pdf_tool=dirname(__FILE__).'\bin\wkhtmltopdf';
//exec("D:/xampp/htdocs/test/wkhtmltopdf/bin/wkhtmltopdf bin/ceshi2.html bin/ceshi2.pdf");
exec("$pdf_tool bin/ceshi2.html bin/ceshi2.pdf");
if(file_exists("bin/ceshi2.pdf")){
header("Content-type:application/pdf");
//直接下载
//header("Content-Disposition:attachment;filename='ceshi2.pdf'");
//	echo file_get_contents("/tmp/{$filename}.pdf");
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('bin/ceshi2.pdf'));
//pdf预览模式
header('Content-Disposition: inline; filename="ceshi2.pdf";');
echo file_get_contents('bin/ceshi2.pdf');
//readfile("bin/ceshi2.pdf");
}else{
exit;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: