【发布时间】:2016-09-08 13:04:52
【问题描述】:
我正在尝试在我的 html 页面中动态设置数据,然后我转换为 pdf 并下载它,这是我的调用 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 资源解释为 Document 但 用 MIME 类型应用程序/pdf 传输
【问题讨论】:
-
可以使用jspdf jquery插件将html转成pdf文件parall.ax/products/jspdf
-
我正在尝试使用 jspdf,但我的样式和颜色有问题:(
-
var doc = new jsPDF(); // 我知道正确的拼写是 color ;) doc.setTextColor(100); doc.text(20, 20, '这是灰色的。');
-
我有我的 owen html ,这是一个相对的解决方案! ,我想用她的风格转换 hoal 页面(颜色位置,标题 ...)