Download PDF file from api using javascript IE9

ぐ巨炮叔叔 提交于 2021-02-10 15:44:17

问题


I use angular 1.5 to get a PDF file from an API.

Here is my code :

$http.get('http://www.example.com/pdf.php')
    .then(function(response) {
        if (response) {
            // get pdf
            try {
                var isFileSaverSupported = !!new Blob;
                var blob = new Blob([response.data], {type: "application/pdf;charset=utf-8"});
                FileSaver.saveAs(blob, "Test file.pdf");                        
            } catch (e) {
                var w = window.open();
                var doc = w.document;
                doc.open( 'application/pdf','replace');
                doc.charset = "utf-8";
                doc.write(response.data);
                doc.close();
                doc.execCommand("SaveAs", null, "Test file IE.pdf");
            }
        }
    });

It works on Chome / FF / IE10+, but of course, IE9 is not. I have a new page opened in IE9 but it contains like :

%PDF-1.5 %��3 0 obj <>stream x���O��}�g��SvYeMe �4��(ID!k�����I e ��AȖd˘}�~�{�}��|���9ϻ��:L��� �E�YD}���݅����.U����X�

Did I miss something ? or is it really impossible to download a file using IE9 ?

来源:https://stackoverflow.com/questions/42901765/download-pdf-file-from-api-using-javascript-ie9

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!