php 强制下载由 TCPDF 创建的 PDF,在 Ajax post 提交后

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10962325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:27:53  来源:igfitidea点击:

Force download PDF created by TCPDF, after Ajax post submit

phpjqueryajaxdownloadtcpdf

提问by trullallero

My application allow the users to complete a form, and send it with an Ajax post call. The form si sent to the TCPDF class that create a PDF file. The class has the method "->output(...)" that permit to save the file into web server, send it to the browser, ecc... my goal is, after the form submit, create the PDF file, and force the user to download it (with no refreshing). The method doesn't work with ajax calls. The only solution I've found is create the file, seve it into web server, and than redirect the user to the location of the file to the web server; but it isn't a nice solution, I need to force the download (auto starting). I've read others similar solution on the forum, but thay aren't good form Any suggestions?

我的应用程序允许用户完成一个表单,并通过 Ajax 后调用发送它。表单 si 发送到创建 PDF 文件的 TCPDF 类。该类具有允许将文件保存到 Web 服务器,将其发送到浏览器,ecc 的方法“->output(...)”...我的目标是,在表单提交后,创建 PDF 文件,然后强制用户下载它(没有刷新)。该方法不适用于 ajax 调用。我找到的唯一解决方案是创建文件,将其发送到 Web 服务器,然后将用户重定向到文件所在的位置到 Web 服务器;但这不是一个好的解决方案,我需要强制下载(自动启动)。我在论坛上读过其他类似的解决方案,但它们不是很好的形式 有什么建议吗?

回答by Tal

$pdf->Output("filename.pdf",'D');

回答by gcivan

Try

尝试

    $pdf->Output("filename.pdf",'FD');

This will suggest client if he wants to save or open file.

这将建议客户是否要保存或打开文件。