- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个代码,我正在尝试加载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。
我们创建了一个简单的示例来使用 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/
我有这个代码,我正在尝试加载blob pdf,无论它在新选项卡中成功打开,但我希望这个pdf加载到syncfusion ejpdfviewer中,任何建议 html JavaScript
我是一名优秀的程序员,十分优秀!