Embed a Blob using PDFObject

后端 未结 3 1152
南笙
南笙 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条回答
  •  心在旅途
    2021-01-06 07:36

    This is what l believe you were looking for.

    function previewPdf(billName) {
    
    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'home/download?pdfBillId=' + billName, true);
    xhr.responseType = 'arraybuffer';
    xhr.onload = function(e) {
        if (this.status == 200) {
            var file = new Blob([this.response], { type: 'application/pdf' });
            var fileURL = URL.createObjectURL(file);
            var viewer = $('#viewpdf');
            PDFObject.embed(fileURL, viewer);
        }
    };
    xhr.send(); 
    }
    

提交回复
热议问题