当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) {
}
}
答案 0 :(得分:1)
你去:https://mozilla.github.io/pdf.js/examples/;只需传入URL。