Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中的PDF输出包含html页眉和页脚部分。如何删除它?_Php_Jquery_Html_Pdf - Fatal编程技术网

PHP中的PDF输出包含html页眉和页脚部分。如何删除它?

PHP中的PDF输出包含html页眉和页脚部分。如何删除它?,php,jquery,html,pdf,Php,Jquery,Html,Pdf,我有一个网页,生成如下: include('header.inc.php'); include('content.php'); include('footer.inc.php'); 在content.php中,我调用标题自动下载PDF文件: header("Content-type:application/pdf"); header('Content-Disposition:attachment;filename="myFile.pdf"'); header('Pragma: no-cache

我有一个网页,生成如下:

include('header.inc.php');
include('content.php');
include('footer.inc.php');
在content.php中,我调用标题自动下载PDF文件:

header("Content-type:application/pdf");
header('Content-Disposition:attachment;filename="myFile.pdf"');
header('Pragma: no-cache');
header('Expires: 0');

$myFile = "/var/www/.../pdf/myFile.pdf"
readfile($myFile);
PDF已生成,但也包含来自页眉和页脚的所有内容

header:
<Doctype...>
<html>
...
<body>

footer:
<script ...>
...
</body>
</html>
如何从PDF中删除所有html代码

我试图通过jQuery从文档中删除所有html,但没有效果:

<script type="text/javascript">
$(document).ready(function(){
    $(document).html('').append(<?=readfile($myFile)?>);
});
</script>

您正在尝试构建html标题,以便在页面中包含pdf文件。您可以简单地创建自己的html,将pdf嵌入到页面中,而不是使用php来实现这一点。Embed将执行与您尝试执行的相同的操作,但通过这种方式,您将在不使用php的情况下生成自己的html:

<html><body><embed width="100%" height="100%" name="plugin" src="link to your pdf goes here" type="application/pdf"></body></html>

将文件名存储在变量中并替换:

header('Content-Disposition:attachment;filename="myFile.pdf"');
与:


我希望我的PDF文件不包含我的网页的全部内容,例如html页眉、html图像、html标题、html div内容、…、html页脚+PDF图像内容,而只包含PDF图像内容。如果您可以编辑您的答案并解释您显示的代码的作用,以及该代码回答问题的原因/方式,这真的很有帮助。
header('Content-Disposition: attachment; filename='.$filename);