1.1.0

Progress Overlay

Last updated


This page covers the progress overlay that appears automatically during convert() and download(): its DOM, how progress is computed, localization, and styles.

DOM Structure


The overlay is a single element appended to the end of <body> and removed automatically when work finishes:
  1. <div class="pdf2image-loading" data-percent="66">
  2. <p>Processing 66%</p>
  3. </div>

AttributeContent
classAlways pdf2image-loading
data-percentAn integer from 0 to 100; the stylesheet sizes the bar from this value
<p> textPhase label plus percentage

Progress Sources


PhaseComputationLabel (English / Chinese)
Conversionround(finished pages / total pages × 100)Processing N% / 解析中 N%
CompressionThe percent reported by JSZip generateAsync, roundedPreparing zip N% / 準備壓縮檔 N%

The conversion overlay appears only after the PDF parses successfully; a parse failure never shows it.
  1. <script>
  2. new MutationObserver(records => {
  3. for (const r of records) {
  4. const el = r.target.closest?.(".pdf2image-loading") || [...r.addedNodes].find(n => n.classList?.contains("pdf2image-loading"));
  5. if (el && r.type === "attributes") console.log("data-percent", el.dataset.percent, "|", el.innerText);
  6. for (const n of r.addedNodes) if (n.classList?.contains("pdf2image-loading")) console.log("overlay added");
  7. for (const n of r.removedNodes) if (n.classList?.contains("pdf2image-loading")) console.log("overlay removed");
  8. }
  9. }).observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ["data-percent"] });
  10. addEventListener("load", async () => {
  11. const buffer = await (await fetch("/assets/sample.pdf")).arrayBuffer();
  12. await new pdf2image({ file: buffer, type: "png", scale: 0.5 }).convert();
  13. });
  14. </script>
Live preview · @pardnchiu/pdf2image@1.1.2

Localization


The package reads navigator.language (or navigator.userLanguage) once at load. A value starting with zh (case-insensitive) selects Chinese labels; anything else uses English. Changing the language after load has no effect.

Styles


The stylesheet is injected at load from cdn.jsdelivr.net/npm/@pardnchiu/pdf2image@latest/dist/pdf2image.css:
  • The overlay is a 240×16px rounded bar, position: absolute at top: calc(50% - 12px) and left: calc(50% - 120px)
  • The progress bar is the ::after pseudo-element, whose width maps [data-percent="N"] selectors to N%
  • position: absolute positions it relative to the document rather than the viewport (unless an ancestor of the overlay is positioned), so on a scrolled page it sits at the middle of the document's first screen; override div.pdf2image-loading in your own stylesheet (for example position: fixed) to pin it to the viewport


中文