当用户单击按钮时,我想生成并打开 PDF。到目前为止,这是我的代码:
索引.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>
创建_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() 组合,但都没有奏效。