You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
NewEduCoderBuild/js/pdf/index.html

62 lines
1.7 KiB

<!DOCTYPE html>
<html>
<head>
<title>My PDF Viewer</title>
</head>
<body>
<div id="pdf-viewer" style="height: 100vh"></div>
<script>
const pattern = /(\w+)=([^\#&]*)/gi;
const parames = {};
location.href.replace(pattern, function (attr, key, value) {
parames[key] = decodeURI(value);
});
window.disabledEdit = parames.model === "view" ? true : false;
console.log("parames",parames,decodeURIComponent(parames.url || 'http://127.0.0.1:8080/pdf.pdf'))
window.addEventListener("message", (event) => {
if (event.data === "getData") {
const { data } = event.data
_x2x_.saveAsCopyAndGetBufferAndName(true)
}
}, false)
</script>
<script async type="module">
import EmbedPDF from './js/embedpdf.js';
window.aaa = EmbedPDF.init({
type: 'container',
target: document.getElementById('pdf-viewer'),
src: decodeURIComponent((parames.url.startsWith("http") ? "" : location.origin)+parames.url ),
disableEditing: true, // 如果 EmbedPDF 支持此选项
disableAnnotation: true, // 禁用注释功能
disableTextLayer: false // 保留文本层以支持搜索,但不允许修改
});
window.downloadArrayBuffer = function (buffer, filename, mimeType = 'application/octet-stream') {
const blob = new Blob([buffer], { type: mimeType });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename || "edu.pdf";
a.style.display = 'none';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
</script>
</body>
</html>