我试图在我的html页面中动态设置数据,然后我转换成pdf,然后下载它,这是我的call url:
createPDF.php?id=78
这是我在createPDF.php中的html部分:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript">
function func(){
jQuery.ajax({
url:'******************/products/78',
type:'GET',
success:function(response)
{
$.each(response,function(index,product){
jQuery("#pdfTitle").append( product.title );
jQuery("#pdfDescription").append(product.description);
jQuery("#pdfImage").append('<img class="img-responsive" src="' + product.meta_description + '" />');
console.log('title='+product.title);
});
}
});
}
</script>
</head>
<body onload="func()">
<h1 style="color:red;">Description</h1>
<p id="pdfDescription"></p>
<p>Copyright © Test</p>
</body>
</html>之后,我在一些文件中有要转换的php部分:
$content = ob_get_clean();
// convert to PDF
require_once(dirname(__FILE__).'/html2pdf/html2pdf.class.php');
$html2pdf = new HTML2PDF('P', 'A4', 'fr');
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->writeHTML($content, isset($_GET['vuehtml']));
$html2pdf->Output('Oumaya.pdf', 'D');但是我总是有一个空的pdf,这就是控制台中发生的事情:
createPDF.php?id=78:94资源被解释为文档,但使用MIME类型的应用程序/pdf传输
发布于 2016-09-08 13:11:39
您需要在文档开头添加<?php ob_start(); ?>,这样ob_get_clean()才能工作。
https://stackoverflow.com/questions/39391763
复制相似问题