Browse Source

修复epub 跨域报错问题

修复epub 跨域报错问题

Signed-off-by: 高雄 <admin@cxcp.com>
pull/201/head
高雄 1 year ago committed by Gitee
parent
commit
a45a592a39
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
  1. 47
      server/src/main/resources/web/epub.ftl

47
server/src/main/resources/web/epub.ftl

@ -30,15 +30,35 @@
if (!url.startsWith(baseUrl)) {
url = baseUrl + 'getCorsFile?urlPath=' + encodeURIComponent(Base64.encode(url));
}
var currentSectionIndex = 100;
// Load the opf
var book = ePub(url);
//var rendition = book.renderTo("viewer", { flow: "scrolled-doc" });
function blobToArrayBuffer(blob) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onerror = reject;
reader.onload = () => {
resolve(reader.result);
};
reader.readAsArrayBuffer(blob);
});
}
let xhr = new XMLHttpRequest();
xhr.open('GET',url); //文件所在地址
xhr.responseType = 'blob';
xhr.onload = () => {
var currentSectionIndex = 100;
var book = ePub();
let content = xhr.response;
let blob = new Blob([content]);
var bookData = blobToArrayBuffer(blob);
book.open(bookData, "binary");
var rendition = book.renderTo("viewer", {
flow: "scrolled-doc",
width: "100%"
width: "100%",
allowScriptedContent: true
// height: 600
});
var displayed = rendition.display();
var params = URLSearchParams && new URLSearchParams(document.location.search.substring(1));
var currentSectionIndex = (params && params.get("loc")) ? params.get("loc") : undefined;
rendition.display(currentSectionIndex);
@ -116,18 +136,19 @@
docfrag.appendChild(option);
});
$select.appendChild(docfrag);
$select.onchange = function(){
var index = $select.selectedIndex,
url = $select.options[index].getAttribute("ref");
rendition.display(url);
return false;
var index = $select.selectedIndex,
url = $select.options[index].getAttribute("ref");
rendition.display(url);
return false;
};
});
}
xhr.send();
/*初始化水印*/
if (!!window.ActiveXObject || "ActiveXObject" in window)
{

Loading…
Cancel
Save