Mercurial > hgrepos > Python2 > PyMuPDF
diff mupdf-source/platform/wasm/examples/super-simple-viewer/index.html @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mupdf-source/platform/wasm/examples/super-simple-viewer/index.html Mon Sep 15 11:43:07 2025 +0200 @@ -0,0 +1,52 @@ +<!DOCTYPE html> +<title>MuPDF Simplest Demo</title> +<meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> + +<style> +body { background-color: gainsboro; text-align: center; } +img { margin: 12px; box-shadow: 1px 1px 4px #0008; } +</style> + +<script type="module"> + +"use strict" + +import * as mupdf from "../../dist/mupdf.js" + +window.openFile = async function openFile(file) { + console.log("OPEN DOCUMENT", file.name) + + window.pageRoot.replaceChildren() + + let pdf = mupdf.Document.openDocument(await file.arrayBuffer(), file.name) + + document.title = pdf.getMetaData(mupdf.Document.META_INFO_TITLE) || file.name + + // Fire off page renders on a timer to avoid blocking the browser. + let n = pdf.countPages() + for (let i = 0; i < n; ++i) + setTimeout(() => renderPage(pdf, i), 0) +} + +function renderPage(pdf, i) { + console.log("RENDER PAGE", i+1) + let z = window.devicePixelRatio * 96 / 72 + let png = pdf.loadPage(i).toPixmap([z,0,0,z,0,0], mupdf.ColorSpace.DeviceRGB).asPNG() + let img = new Image() + img.src = URL.createObjectURL(new Blob([png], { type: "image/png" })) + img.onload = function () { + img.style.width = img.width / window.devicePixelRatio + "px" + window.pageRoot.appendChild(img) + } +} + +</script> + +<body> + <input type="file" accept=".pdf,.xps,application/pdf" onchange="openFile(event.target.files[0])"> + <div id="pageRoot"> + </div> +</body> + +</html>
