提问者:小点点

Load Blob PDF in Syncfusion JavaScript EJFdViewer


我有这个代码,我正试图加载blob pdf,然而它成功地在一个新的标签页中打开,但我希望这个pdf被加载到syncfusion ejpdfviewer中,有什么建议吗

html

javascript语言

                xhr.open('POST', '/MifosX/Reports/RunReportPDF');
                xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
                xhr.send(JSON.stringify(reportrequestviewmodel));
                xhr.responseType = "blob";
                xhr.onreadystatechange = function () {
                    let stateCode = 0;
                    console.log("readyState", this.readyState);
                    console.log("status", this.status);
                    if (this.readyState === 4) {
                        this.onreadystatechange = null;
                        if (this.status === 200) {

                            var file = new Blob([xhr.response], { type: 'application/pdf' });
                            var fileURL = URL.createObjectURL(file);
                            window.open(fileURL);
                            console.log(fileURL);

                            $("#iframe").ejPdfViewer({ serviceUrl: fileURL, interactionMode: 1 });

                            console.log(xhr.response);
                        } else {
                            alert(this.statusText);
                            stateCode = -1;
                        }
                    }
                    return stateCode;```

共1个答案

匿名用户

PDF viewer不支持直接从URL加载PDF文档。但是,您可以通过在示例级别使用客户端documentPath API将URL转换为base64字符串来加载PDF文档。

请从下面找到相同的代码段,

$("#pdfviewer").ejPdfViewer({ serviceUrl: '../api/pdfviewer/', documentpath:base64data ,pdfService: ej.PdfViewer.PdfService.Local }); 

注:

>

  • 我们可以在控件初始化时在docetPath API中提供PDF Viewer的base64string的Pdf文档名称/路径。

    我们还可以使用 load() API 在 PDF 查看器中动态加载 PDF 文档。

    我们创建了一个简单的示例来使用 documentPath 加载 PDF 文档,并在以下位置共享相同的示例,

    https://www.syncfusion.com/downloads/support/directtrac/general/ze/PdfViewerSamples_(5)1344181241

    入门UG链接:https://help.syncfusion.com/js/pdfviewer/getting-started

    请找到以下知识库以供参考, https://www.syncfusion.com/kb/8737/how-to-load-a-pdf-document-from-url-into-pdf-viewer-from-client-side

    谢谢,

    阿克沙亚