From a45a592a39c69e48d8f254824407c7977b119a54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E9=9B=84?= Date: Thu, 3 Aug 2023 07:16:00 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Depub=20=E8=B7=A8=E5=9F=9F?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98=20=E4=BF=AE=E5=A4=8Depub?= =?UTF-8?q?=20=E8=B7=A8=E5=9F=9F=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 高雄 --- server/src/main/resources/web/epub.ftl | 47 +++++++++++++++++++------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/server/src/main/resources/web/epub.ftl b/server/src/main/resources/web/epub.ftl index 85e7d1c4..14b5723a 100644 --- a/server/src/main/resources/web/epub.ftl +++ b/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) {