php - 保存 TCPDF 生成的文件

标签 php jquery tcpdf

我想在用户单击按钮时生成并打开 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/

相关文章:

php - 在 php/MySQL 中计算页面浏览量

PHP - Readfile 很慢,我有什么选择

javascript - 在 ng-if 中允许大写和小写

php - 在tcpdf中混合rtl和ltr

php - Laravel 收银员它不会自动创建订阅

php - 错误 : Class 'DOMDocument' not found

javascript - 仅用于 div id 的 tinymce 选择器

jQuery .on 数据或事件处理程序?

php - 如何从 TCPDF 以字符串形式返回 PDF 文档?

php - tcpdf 字体连字(英文)?