在html中下载itext生成的PDF

时间:2017-03-22 18:08:53

标签: javascript java ajax rest

我正在尝试下载由itext生成的pdf文件。

在我的应用程序中,正在使用jquery,rest web服务。

截至目前,我可以在服务器端创建pdf文件,但在发送到html时遇到问题。

我尝试过以下链接但没有成功。

iTextSharp generated PDF: How to send the pdf to the client and add a prompt?

Download pdf file using jquery ajax

当我在开发人员工具中看到时,我可以看到以下数据以响应ajax请求。

  

阻止报价%PDF-1.4% 30 obj<>流x |E ...

     

阻止报价

1 个答案:

答案 0 :(得分:0)

您是在内存中创建它还是在服务器上创建文件?有很多方法可以做到这一点。您可以manipulate the headers并传递回复。在服务器上创建一个文件并传递文件URL作为响应并在新选项卡中打开它。这取决于你在做什么语言。 Handle file download from ajax post

Content-Type: application/octet-stream
Content-Disposition: attachment; filename="somefile.pdf"