【问题标题】:Display pdf on a web page using pdf stream returned from web service in angularjs使用从 angularjs 中的 Web 服务返回的 pdf 流在网页上显示 pdf
【发布时间】:2015-11-14 17:32:46
【问题描述】:

当 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) {

            }
        }

【问题讨论】:

    标签: angularjs web-services pdf jsreport


    【解决方案1】:

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

    【讨论】:

    • 我有一个来自网络服务的流。它不是 pdf 文件的 url。
    • 你是怎么得到那个流的?
    • 另外,如果您费心阅读 API,它还可以与带有文件内容的预填充 Uint8Array 一起使用。
    猜你喜欢
    • 1970-01-01
    • 2021-10-21
    • 2016-04-26
    • 1970-01-01
    • 2011-07-30
    • 1970-01-01
    • 2017-09-29
    • 2022-01-05
    • 1970-01-01
    相关资源
    最近更新 更多