ARTICLE AD BOX
You can load and display a remote PDF in a fully browser-independent way using pdf.js,
No need using iframe/embed/object. pdf.js can fetch a PDF directly from a URL as long as the server allows CORS.
Below is a minimal working example that loads a remote PDF, renders every page into a <canvas>, and lets you control scrolling yourself.
html & js
<div id="pdf-container" style="height:600px; overflow-y:auto;"></div> <script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.0.379/pdf.min.js"></script> pdfjsLib.GlobalWorkerOptions.workerSrc = "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.0.379/pdf.worker.min.js"; const url = "https://example.com/your.pdf"; // remote PDF URL pdfjsLib.getDocument(url).promise.then(pdf => { for (let i = 1; i <= pdf.numPages; i++) { pdf.getPage(i).then(page => { const viewport = page.getViewport({ scale: 1.2 }); const canvas = document.createElement("canvas"); const ctx = canvas.getContext("2d"); canvas.height = viewport.height; canvas.width = viewport.width; document.getElementById("pdf-container").appendChild(canvas); page.render({ canvasContext: ctx, viewport: viewport }); }); } });The only requirement is that the server hosting the PDF must send the proper CORS header,
here is like example:
Then that header is in place, pdf.js can fetch and render the PDF .
Slightly unclear but a PDF is a vector file of pages thus cannot be shown normally in a browser.
Hence the need for
An embedded frame with scrollbars controlled by a client only (Chromium's FireFox Gecko's based PDF viewers etc.) Alternative is something like PDF.JS which is an images renderer with overlays and scrollbars. A remaining possibility is (if browsers ALLOW images, not all do) then place canvas images side by side or one over the other and then the page scrolls not the images.Explore related questions
See similar questions with these tags.
