gpt4 book ai didi

javascript - 在syncfusion中加载blob pdf javascript ejpdfviewer

转载 作者:行者123 更新时间:2023-12-02 22:46:18 25 4
gpt4 key购买 nike

我有这个代码,我正在尝试加载blob pdf,无论它在新选项卡中成功打开,但我希望这个pdf加载到syncfusion ejpdfviewer中,任何建议

html <div id="iframe"></div>

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;```

最佳答案

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

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

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

注意:

  • 我们可以提供PDF文档名称/PDF的base64字符串的路径控件初始化期间 documetPath API 中的查看器。

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

  • PDF 查看器中的 serviceUrl 属性用于映射
    Controller 。(我们的 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

谢谢

阿克夏亚

关于javascript - 在syncfusion中加载blob pdf javascript ejpdfviewer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58389353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com