使用从angularjs中的Web服务返回的pdf流在网页上显示pdf

时间:2015-11-14 07:22:38

标签: angularjs web-services pdf jsreport

当pdf作为流返回时,如何在angularjs中的新选项卡上显示pdf。

fiddler捕获的pdf流标题是

HTTP/1.1 200 OK
X-Powered-By: Express
Access-Control-Allow-Origin: *
Vary: Origin
Connection: close
Content-Type: application/pdf
Content-Disposition: inline; filename="report.pdf"
File-Extension: pdf
Number-Of-Pages: 1
X-XSS-Protection: 0
Content-Length: 18126

AngularJS代码

externalService.getReport(template).then(function (data, error) {
            if (data) {
                type = 'application/pdf';
                var newTab = $window.open('about:blank', '_blank');
                newTab.document.write("<object width='400' height='400' data='" + data + "' type='" + type + "' ></object>");
            }
        }), function (error) {
            if (error) {

            }
        }

1 个答案:

答案 0 :(得分:1)

你去:https://mozilla.github.io/pdf.js/examples/;只需传入URL。

相关问题