在Ajax发布后,强制下载由TCPDF创建的PDF

时间:2021-08-06 00:31:23

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

2 个解决方案

#1


29  

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

#2


15  

Try

尝试

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

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

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

#1


29  

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

#2


15  

Try

尝试

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

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

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