CodePen
codepen.io › tag › pdfjs
Pens tagged 'pdfjs' on CodePen
CodePen doesn't work very well without JavaScript · We're all for progressive enhancement, but CodePen is a bit unique in that it's all about writing and showing front end code, including JavaScript. It's required to use most of the features of CodePen · Need to know how to enable it?
CodePen
codepen.io › naveen_sai › pen › xxqOOgZ
pdf.js demo
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"> <script src="//mozilla.github.io/pdf.js/build/pdf.js" crossorigin="anonymous"></script> <link href="//mozilla.github.io/pdf.js/web/viewer.css" rel="stylesheet" type="text/css" /> <style type="text/css"> #the-canvas { border: 1px solid black; direction: ltr; } </style> </head> <body> <h1>PDF.js Previous/Next example</h1> <div> <button id="prev">Previous</button> <button id="next">Next</button> <span>Page: <span id="page_num"></span> / <span id="page_count"></span></span> </div> <canvas id="the-canvas"></canvas> <div class="textLayer"></div> <script> // If absolute URL from the remote server is provided, configure the CORS // header on that server.
Videos
CodePen
codepen.io › moorthi07 › pen › JeQVJx
PDFJS example
// var url = 'https://www.ftb.ca.gov/forms/2015/15_540.pdf '; // // Disable workers to avoid yet another cross-origin issue (workers need the URL of // the script to be loaded, and dynamically loading a cross-origin script does // not work) // pdfjsLib.disableWorker = true; // // Asynchronous download PDF as an ArrayBuffer // pdfjsLib.getDocument(url).then(function getPdfHelloWorld(pdf) { // // Fetch the first page // pdf.getPage(1).then(function getPageHelloWorld(page) { var scale = 1.5; var viewport = page.getViewport(scale); // // Prepare canvas using PDF page dimensions // var canvas = document.getElementById('the-canvas'); var context = canvas.getContext('2d'); canvas.height = viewport.height; canvas.width = viewport.width; // // Render PDF page into canvas context // page.render({ canvasContext: context, viewport: viewport }); }); }); </script> </body> </html>
CodePen
codepen.io › redrobot753 › pen › vYzbRda
A web component for view PDF files with PDF.js
const template = document.createElement('template'); template.innerHTML = ` <iframe frameborder="0" width="1280" height="900"> </iframe> ` class PdfViewer extends HTMLElement { constructor() { super() const shadowRoot = this.attachShadow({mode: 'open'}) shadowRoot.appendChild(template.content.cloneNode(true)) } get observedAttributes() { return ['src'] } connectedCallback() { this.updateIframeSrc() } attributeChangedCallback(name) { if (['src', 'viewerPath'].includes(name)) { this.updateIframeSrc() } } updateIframeSrc() { this.shadowRoot.querySelector('iframe').setAttribute( 'src', `https://mozilla.github.io/pdf.js/web/viewer.html?file=${this.getAttribute('src') || ''}` ) } } window.customElements.define('pdf-viewer', PdfViewer)
CodePen
codepen.io › harryheman › pen › WNxVoeb
PDF Viewer - Pdf.js
class PDFViewer { constructor(selector, url) { this.container = document.querySelector(selector); this.url = url; this.pdf = null; this.currentPage = 1; this.totalPages = 0; this.currentZoom = 1; // this.state = { // pdf = null // currentPage: 1, // totalPages: 0, // currentZoom: 1, // } this.canvas = this.container.querySelector("canvas"); this.ctx = this.canvas.getContext("2d"); this.onClick = this.onClick.bind(this); this.onChange = this.onChange.bind(this); this.container.addEventListener("click", this.onClick); this.container.addEventListener("change", this.onChange); document.addEventLis
CodePen
codepen.io › tcyrus › pen › ERJxWK
Bootstrap 4 + PDF.js
<main role="main"> <div id="carousel" class="carousel" data-ride="carousel"> <div class="carousel-inner"> <div class="carousel-item active"> <canvas id="pdf-canvas" class="d-block w-100" data-file="//mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf"></canvas> <div class="carousel-caption d-none d-md-block"> <span>Page: <span id="page-num"></span> / <span id="page-count"></span></span> </div> </div> </div> <a class="carousel-control-prev" href="#" role="button" data-slide="prev"> <i class="fas fa-chevron-left fa-2x"></i> <span class="sr-only">Previous</span> </a> <a class="carousel-control-next" href="#" role="button" data-slide="next"> <i class="fas fa-chevron-right fa-2x"></i> <span class="sr-only">Next</span> </a> </div> </main>
CodePen
codepen.io › alidz › pen › ezBxqo
PDF.js viewer
See https://github.com/adobe-type-tools/cmap-resources --> <html dir="ltr" mozdisallowselectionprint moznomarginboxes> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="google" content="notranslate"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>PDF.js viewer</title> <link rel="stylesheet" href="https://mozilla.github.io/pdf.js/web/viewer.css"> <script src="https://mozilla.github.io/pdf.js/web/compatibility.js"></script> <!-- This snippet is used in production (included from viewer.html) --> <link rel=
CodePen
codepen.io › nbenyaya › pen › GaaYgr
PDF JS display all page responvie
<head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> </head> <body> <script src="//mozilla.github.io/pdf.js/build/pdf.js"></script> <div class="container"> <div id="container" class=" row justify-content-center embed-responsive"> </div> </div> </body>
CodePen
codepen.io › fonziana › pen › MdpKVP
Render Multi-page PDF in Canvas using PDFJS
function renderPDF(url, canvasContainer, options) { options = options || { scale: 1 }; function renderPage(page) { var viewport = page.getViewport(options.scale); var wrapper = document.createElement("div"); wrapper.className = "canvas-wrapper"; var canvas = document.createElement('canvas'); var ctx = canvas.getContext('2d'); var renderContext = { canvasContext: ctx, viewport: viewport }; canvas.height = viewport.height; canvas.width = viewport.width; wrapper.appendChild(canvas) canvasContainer.appendChild(wrapper); page.render(renderContext); } function renderPages(pdfDoc) { for(var num = 1; num <= pdfDoc.numPages; num++) pdfDoc.getPage(num).then(renderPage); } PDFJS.disableWorker = true; PDFJS.getDocument(url).then(renderPages); } renderPDF('https://res.cloudinary.com/sivadass/image/upload/v1519136548/hr-sample-pdf.pdf', document.getElementById('holder'));
CodePen
codepen.io › mvmaha › pen › aXywaN
PDF.js with file input
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing. If active, Pens will autosave every 30 seconds after being saved once. If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update. If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting. ... Visit your global Editor Settings. ... document.querySelector("#pdf-upload").addEventListener("change", function(e){ var canvasElement = document.querySelector("canvas") var file = e.target.files[0] if(fi
CodePen
codepen.io › mattwalkley › pen › ZEzMdaG
Sample PDF Viewer
// pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js'; // Asynchronous download of PDF var loadingTask = pdfjsLib.getDocument(url); loadingTask.promise.then(function(pdf) { console.log('PDF loaded'); // Fetch the first page var pageNumber = 1; pdf.getPage(pageNumber).then(function(page) { console.log('Page loaded'); var scale = 1.5; var viewport = page.getViewport({scale: scale}); // Prepare canvas using PDF page dimensions var canvas = document.getElementById('the-canvas'); var context = canvas.getContext('2d'); canvas.height = viewport.height; canvas.wi
Mozilla
mozilla.github.io › pdf.js › examples
PDF.js - Examples
Remember though that PDF.js uses ... property which is resolved with the document object. var loadingTask = pdfjsLib.getDocument('helloworld.pdf'); loadingTask.promise.then(function(pdf) { // you can now use *pdf* here });...
JSFiddle
jsfiddle.net › pdfjs › wagvs9Lf
PDF.js Previous/Next example - JSFiddle - Code Playground
The Code Completion will now also have the context of all panels before suggesting code to you - so if for example you have some CSS or JS, the HTML panel will suggest code based on the other two panels.
CodeSandbox
codesandbox.io › examples › package › react-pdf-js
react-pdf-js examples - CodeSandbox
Use this online react-pdf-js playground to view and fork react-pdf-js example apps and templates on CodeSandbox.
CodePen
codepen.io › zgaur › pen › BayWOLN
PDF Viewer
<script id="sap-ui-bootstrap" type="text/javascript" src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js" data-sap-ui-theme="sap_goldreflection" data-sap-ui-libs="sap.ui.commons"></script> <script id="myXmlView" type="ui5/xmlview"> <mvc:View controllerName="gccontroller" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" height="100%"> <ScrollContainer height="100%" width="100%" horizontal="true" vertical="true"> <FlexBox direction="Column" renderType="Div" class="sapUiSmallMargin"> <FlexBox> <Button text="Correctly Displayed" press="onCorrectPathClick"/> <Button text="Loading Error" press="
CodePen
codepen.io › redrobot753 › embed › vYzbRda
CodePen Embed - A web component for view PDF files with PDF.js
const template = document.createElement('template'); template.innerHTML = ` <iframe frameborder="0" width="1280" height="900"> </iframe> ` class PdfViewer extends HTMLElement { constructor() { super() const shadowRoot = this.attachShadow({mode: 'open'}) shadowRoot.appendChild(template.content.cloneNode(true)) } get observedAttributes() { return ['src'] } connectedCallback() { this.updateIframeSrc() } attributeChangedCallback(name) { if (['src', 'viewerPath'].includes(name)) { this.updateIframeSrc() } } updateIframeSrc() { this.shadowRoot.querySelector('iframe').setAttribute( 'src', `https://mozilla.github.io/pdf.js/web/viewer.html?file=${this.getAttribute('src') || ''}` ) } } window.customElements.define('pdf-viewer', PdfViewer) This Pen is owned by Oleksandr Shevchuk on CodePen.