简体   繁体   English

无法使用Angular.js下载pdf文件

[英]Can not download pdf file using Angular.js

I have an issue while downloading some document from my webpage using Angular.js.I am explaining my code below. 使用Angular.js从网页下载某些文档时遇到问题,我在下面解释我的代码。

<tr>
<th>Document</th>
</tr>
<tr ng-repeat="sup in viewSupplierData">
<td valign="middle" align="center"><a href="upload/{{sup.company_reg_docs}}" target="_self" alt="View/Download" title="View/Download"><img src="img/download_icon.jpg" name="pro" border="0" style="border:#808080 1px solid;"  /></a></td>
</tr>

Here i am setting the document link dynamically.For any .docx file its downloading but in case of any pdf related file its opening in new page not donloading.Here i need all files should download directly.Please help me. 我在这里动态设置文档链接。对于任何.docx文件,请下载该文件,但如果有任何pdf相关文件,请不要直接在新页面中打开。这里我需要所有文件都应直接下载。请帮助我。

Cross-Browser solution, all files (pdf, jpg, docx, etc.) will be downloaded (Chrome, Firefox, IE). 跨浏览器解决方案,所有文件(pdf,jpg,docx等)将被下载(Chrome,Firefox,IE)。 I am using it and it works like charm. 我正在使用它,它的工作原理就像魅力。

$window.open(URL_WHERE_YOU_GET_THE_FILE(BINARY), '_blank');

You also have to set some things on your response in your backend (Java example): 您还必须在后端的响应中设置一些内容(Java示例):

res.setContentType("application/octet-stream");
res.addHeader("Content-Disposition", "attachment; filename=" + file.getName());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM