我想在用户单击按钮时生成并打开PDF。这是我到目前为止的代码:由TCPDF生成的保存文件
的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()组合,但它们都没有工作。
[POST到服务器的可能重复,接收PDF,交付给用户w/jQuery](http:// stackov err3.com/questions/2186562/post-to-server-receive-pdf-deliver-to-user-w-jquery) – Adeel 2013-02-20 11:05:39
不是重复。该帖未解释如何用PDF打开新窗口 – Alex 2013-02-20 11:09:20
jQuery'.ajax'不会重定向,您可能需要使用'GET'方法或创建一个虚拟表单,然后提交 – 2013-02-20 11:19:48