使用PDFObject嵌入Blob

Pab*_*ada 2 html javascript pdf pdfobject

我正在使用:https : //pdfobject.com/

pdf在我的Web应用程序上显示嵌入式文件。但是我不能渲染从pdf创建的blob

这是我尝试过的:

var arrayBufferView = new Uint8Array(response.Body.data);
var file = new Blob([arrayBufferView], {
    type: response.ContentType
});
var url = window.URL.createObjectURL(file)
PDFObject.embed(url, "#my-container");
Run Code Online (Sandbox Code Playgroud)

在html上获得此结果:

<div id="my-container" class="ng-scope pdfobject-container">

    <embed class="pdfobject" src="blob:http%3A//localhost%3A4000/869a8d9a-7eaa-48dd-99aa-49bf299114aa" type="application/pdf" style="overflow: auto; width: 100%; height: 100%;" internalinstanceid="88">

</div>
Run Code Online (Sandbox Code Playgroud)

但是,嵌入容器在我的浏览器中什么也不显示。我正在使用Chrome 51.0.2704.103 m

gue*_*314 10

尝试使用<iframe>元素,将资源请求为Blob

html

<div id="my-container" class="ng-scope pdfobject-container">
    <iframe src="" type="application/pdf" width="100%" height="100%" style="overflow: auto;">
    </iframe>
</div>
Run Code Online (Sandbox Code Playgroud)

javascript

var xhr = new XMLHttpRequest();
// load `document` from `cache`
xhr.open("GET", "/path/to/file.pdf", true); 
xhr.responseType = "blob";
xhr.onload = function (e) {
    if (this.status === 200) {
        // `blob` response
        console.log(this.response);
        var file = window.URL.createObjectURL(this.response);
        document.querySelector("iframe").src = file;

    }
};
xhr.send();
Run Code Online (Sandbox Code Playgroud)

plnkr http://plnkr.co/edit/9E5sGfMhUeIWV9yodAUd?p=preview