Loading document…
Loading document…
<script>window.pdfSrc = \'/media/uploads/your-file.pdf\';</script> '
+ 'to the content field.';
return;
}
// Wire up download button now we have a path
downloadBtn.href = PDF_URL;
downloadBtn.style.display = 'inline-block';
pdfjsLib.GlobalWorkerOptions.workerSrc =
'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.worker.min.js';
function renderPage(pdf, pageNum) {
return pdf.getPage(pageNum).then(function (page) {
var naturalViewport = page.getViewport({ scale: 1 });
var scale = (container.clientWidth / naturalViewport.width) * (window.devicePixelRatio || 1);
var viewport = page.getViewport({ scale: scale });
var canvas = document.createElement('canvas');
canvas.className = 'pdf-page-canvas';
canvas.width = viewport.width;
canvas.height = viewport.height;
canvas.style.width = container.clientWidth + 'px';
canvas.style.height = Math.round(viewport.height / (window.devicePixelRatio || 1)) + 'px';
container.appendChild(canvas);
return page.render({
canvasContext: canvas.getContext('2d'),
viewport: viewport
}).promise;
});
}
pdfjsLib.getDocument(PDF_URL).promise.then(function (pdf) {
statusEl.remove();
var chain = Promise.resolve();
for (var i = 1; i <= pdf.numPages; i++) {
chain = chain.then(renderPage.bind(null, pdf, i));
}
return chain;
}).catch(function () {
statusEl.innerHTML =
'Unable to load the document. ' +
'Download the PDF instead.';
});
}());
*
* ── HOW TO USE ──────────────────────────────────────────────────────────────
* The PDF path is supplied by the page content field. In the CMS page editor,
* paste the following snippet (update the path to match your uploaded file):
*
*
*
* Tip: use the media library to copy the file path, then paste it above.
* Any additional page copy (headings, text) can appear before or after the
* script tag — it will be rendered above the PDF viewer as normal.
* ────────────────────────────────────────────────────────────────────────────
*
* Variables available from init_page.php:
* - $page: Page object with content, title, etc.
* - $theme: Theme object with configuration
* - $site: Site configuration object
*/
// Security check
if (!defined('PLUTONIUM_CMS')) {
die('Direct access not permitted');
}
?>