Embed a Blob using PDFObject

后端 未结 3 1170
南笙
南笙 2021-01-06 06:41

I\'m using: https://pdfobject.com/

To display an embedded pdf file on my web app. However I cannot render a pdf created from a blob

3条回答
  •  Happy的楠姐
    2021-01-06 07:28

    Try using

    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();
    

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

提交回复
热议问题