PHP - 如何将HTML页面下载到PDF文件中

时间:2015-11-09 09:29:05

标签: php html pdf export-to-pdf

我想将html页面下载到pdf文件中。 我正在使用Codeigniter。

这是我的代码:

<?php
if($type==0)//excel
{
    $mime="vnd.ms-excel";
    $format=".xls";
}
else if($type==1)//pdf
{
    $mime="pdf";
    $format=".pdf";
}

header('Content-Type: application/'.$mime.'');
header('Content-Disposition: attachment; filename="Placeout'.$format.'"');
header("Content-Transfer-Encoding: binary");
header('Accept-Ranges: bytes');
/* The three lines below basically make the download non-cacheable */
header("Cache-control: private");
header('Pragma: private');
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
?>

<html>
<body>
..........
</body>
</html>

当我导出到excel文件时,它可以工作。但是当我导出到pdf文件时,它下载文件但我无法打开文件。当我打开文件时,它会显示一条消息: This is the message from adobe reader...

另外,你能解释最后三个标题行(不可缓存的东西)。 谢谢你的回答..

0 个答案:

没有答案