我想在用户单击按钮时生成并打开 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>
创建_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->Output('yourfilename.pdf','D');
这将提示用户选择 PDF 文件的保存位置。
关于php - 保存 TCPDF 生成的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14978191/