Skip to content

Commit

Permalink
better web app
Browse files Browse the repository at this point in the history
  • Loading branch information
paulocoutinhox committed Aug 16, 2024
1 parent 697a50f commit 792ad11
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 67 deletions.
16 changes: 9 additions & 7 deletions docs/BUILD_WASM.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@
2. Get Emscripten SDK:
```python3 make.py build-emsdk```

3. Get PDFium:
3. Execute EMSDK environment file "emsdk_env" according to your system.

4. Get PDFium:
```python3 make.py build-pdfium-wasm```

4. Patch:
5. Patch:
```python3 make.py patch-wasm```

5. PDFium Linux dependencies
6. PDFium Linux dependencies
```./build/wasm32/pdfium/build/install-build-deps.sh```

6. Compile:
7. Compile:
```python3 make.py build-wasm```

7. Install libraries:
8. Install libraries:
```python3 make.py install-wasm```

8. Test:
9. Test:
```python3 make.py test-wasm```

9. Generate javascript libraries:
10. Generate javascript libraries:
```python3 make.py generate-wasm```

Obs:
Expand Down
121 changes: 61 additions & 60 deletions extras/wasm/template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,23 @@
<meta name="viewport"
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height" />

<title>PDF Viewer</title>
<title>PDFium PDF Viewer</title>
<meta name="description"
content="Quickly view your PDF files with the PDFium PDF Viewer. Easy, fast, and secure, all within your browser.">
<meta name="keywords"
content="pdfium, pdf viewer, view pdf, pdf reader, browser, webassembly, fast pdf, secure pdf">

<meta property="og:title" content="PDFium PDF Viewer">
<meta property="og:description"
content="Quickly view your PDF files with the PDFium PDF Viewer. Easy, fast, and secure, all within your browser.">
<meta property="og:image" content="https://pdfium-lib.s3.amazonaws.com/others/logo.png">
<meta property="og:url" content="https://pdfviewer.github.io">
<meta property="og:type" content="website">

<link rel="shortcut icon"
href="data:image/x-icon;base64,UklGRtASAABXRUJQVlA4TMMSAAAv/8F/EH+HoG3blD/pSG32UxAQFPk/moCg4P/oBAJJavtDbb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elivr.net/npm/bulma@1.0.2/css/bulma.min.css">

<script src="pdfium.js?v={pdfium-branch}"></script>

Expand Down Expand Up @@ -103,7 +114,7 @@

image.id = "pageImage" + (pageIndex + 1);
image.src = '';
image.className = "is-invisible page-list-item";
image.className = "is-hidden page-list-item";

return image;
}
Expand All @@ -115,17 +126,17 @@
let pageIndex = this.index;
let image = document.getElementById("pageImage" + (pageIndex + 1));
image.src = dataUri;
image.classList.remove("is-invisible");
image.classList.remove("is-hidden");
image.onclick = function () {
openModal();
changeCurrentPageItem(pageIndex + 1);
};

const container = image.closest('.column');
const container = image.closest('.cell');
const loaderWrapper = container.querySelector('.page-loader-wrapper');

if (loaderWrapper) {
container.removeChild(loaderWrapper);
loaderWrapper.remove();
}
}

Expand Down Expand Up @@ -245,37 +256,26 @@
return page;
}

renderPages() {
async renderPages() {
const wasmBuffer = this.processor.wasmData.wasmBuffer;
const wasm = this.processor.wasmData.wasm;

doc.pages.forEach(async function (page, index) {
if (!page.loaded) {
setTimeout(function () {
const renderNextPage = async (index) => {
if (index < doc.pages.length) {
let page = doc.getPage(index);
if (!page.loaded) {
await new Promise(requestAnimationFrame);
page.render();

if (index === doc.pages.length - 1) {
Module.wasmExports.free(wasmBuffer);

FPDF.CloseDocument(wasm);
FPDF.DestroyLibrary();
}
});
}
setTimeout(() => renderNextPage(index + 1), 100);
} else {
Module.wasmExports.free(wasmBuffer);
FPDF.CloseDocument(wasm);
FPDF.DestroyLibrary();
}
})
}

setLoading(pageList) {
let images = pageList.querySelectorAll(".column img");
let width = images[0].offsetWidth + "px";
let height = images[0].offsetHeight + "px";
}

images.forEach((img) => {
if (!img.getAttribute("src")) {
img.style.width = width;
img.style.height = height;
}
})
await renderNextPage(0);
}
}

Expand Down Expand Up @@ -414,10 +414,22 @@

const image = doc.getPage(x).createImage();

// add content item
let content = document.createElement('div');
content.className = "content";
content.appendChild(image);

// add loader content
let loaderContent = document.createElement('span');
loaderContent.className = "loader";

// add loader
let loader = document.createElement('div');
loader.className = "page-loader-wrapper";
loader.appendChild(loaderContent);
content.appendChild(loader);

// add card
let cardContent = document.createElement('div');
cardContent.className = "card-content";
cardContent.appendChild(content);
Expand All @@ -426,20 +438,12 @@
card.className = "card";
card.appendChild(cardContent);

let loaderContent = document.createElement('span');
loaderContent.className = "loader";

let loader = document.createElement('div');
loader.className = "page-loader-wrapper";
loader.appendChild(loaderContent);

let column = document.createElement('div');
column.className = "column is-half-mobile is-one-third-tablet is-one-third-desktop is-one-third-widescreen is-one-quarter-fullhd";
column.style.position = "relative";
column.appendChild(card);
column.appendChild(loader);
let cell = document.createElement('div');
cell.className = "cell";
cell.style.position = "relative";
cell.appendChild(card);

pageList.appendChild(column);
pageList.appendChild(cell);

// show results
console.log('Page ' + (x + 1) + ' rendered');
Expand All @@ -448,10 +452,6 @@
let firstPage = await doc.getPage(0);
firstPage.render();

setTimeout(function () {
doc.setLoading(pageList);
})

pageListTitle.innerHTML = "Number of pages: " + pages;

pageListContainer.style.display = "block";
Expand Down Expand Up @@ -956,10 +956,6 @@
cursor: pointer;
}

.page-list-item img {
max-width: 70%;
}

/* modal */
.modal {
display: none;
Expand Down Expand Up @@ -1018,6 +1014,10 @@
padding: 0;
}

.page-loader-wrapper {
padding: 30px 10px;
}

.page-loader-wrapper .loader {
-webkit-animation: spinAround .5s infinite linear;
animation: spinAround .5s infinite linear;
Expand All @@ -1029,9 +1029,6 @@
display: block;
height: 2em;
width: 2em;
position: absolute;
left: calc(50% - 1em);
top: calc(50% - 1em);
}

/* modal */
Expand Down Expand Up @@ -1063,7 +1060,7 @@
left: 0;
height: 100%;
width: 100%;
background: #fff;
background-color: var(--bulma-box-background-color);
opacity: 0;
z-index: -1;
transition: opacity .3s;
Expand Down Expand Up @@ -1099,8 +1096,10 @@
<body>
<!-- loading -->
<div id="loadingContainer">
<div class="loader-wrapper is-active">
<div class="loader is-loading"></div>
<div class="box">
<div class="loader-wrapper is-active">
<div class="loader is-loading"></div>
</div>
</div>
</div>

Expand Down Expand Up @@ -1153,8 +1152,10 @@ <h1 id="fileTitle" class="title" style="display: none;">PDF Viewer</h1>
<div id="pageListContainer" style="display: none;">
<p style="font-weight: bold;" id="pageListTitle">Number of pages: 0</p>

<!-- page as a column -->
<div class="columns is-multiline is-mobile" id="pageList"></div>
<!-- page as a cell -->
<div class="fixed-grid has-auto-count">
<div class="grid" id="pageList"></div>
</div>

<div class="modal" id="pageModal">
<div class="modal-background" onclick="closeModal()"></div>
Expand Down
7 changes: 7 additions & 0 deletions modules/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ def run_task_build_emsdk():
command = " ".join(["source", "emsdk_env.sh"])
r.run(command, cwd=cwd, shell=True)

l.colored(
"Execute on your terminal the following file according to your system:",
l.PURPLE,
)
l.m("File: emsdk_env")
l.m("Directory: " + cwd)

l.ok()


Expand Down

0 comments on commit 792ad11

Please sign in to comment.