【发布时间】:2013-02-05 08:33:02
【问题描述】:
我想在用户单击按钮时生成并打开 PDF。到目前为止,这是我的代码:
index.php:
</html>
<head>
<script>
$('.cmd_butt').click(function() {
$.ajax({
url: 'create_pdf.php',
data: {id: $(this).attr('order_id'), name: $(this).attr('name')},
type: 'post'
});
}
</script>
</head>
<body>
<button class="cmd_butt" order_id="250" name="pdf_but">Download PDF</button>
</body>
</html>
create_pdf.php:
<?php
//header('Content-type: application/pdf')
header("Content-type: application-download");
//header("Content-Length: $size");
header("Content-Disposition: attachment; filename=MyPDF.pdf");
header("Content-Transfer-Encoding: binary");
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
// create new PDF document
// some code
// some code
//$pdf->Output('test.pdf', 'I');
//$pdf->Output('test.pdf', 'FD');
$pdf->Output();
?>
如何使用生成的 PDF 打开新窗口?或者通过“另存为”对话框通知用户下载此 PDF?我尝试了不同的 Output() 组合,但都没有奏效。
【问题讨论】:
-
不是重复的。该帖子没有说明如何使用 PDF 打开新窗口
-
jQuery
.ajax不会重定向,你可能需要使用GET方法,或者创建一个虚拟表单,然后提交 -
如果你想创建一个虚拟表单,你可以参考这个stackoverflow.com/a/6440159/1877620
-
感谢有用