Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
    <main class="container-fluid">
        <div class="row">
            <div class="col"><h1 class="text-center" >Hello</h1></div>
            <div id="pdf" class="w-100 bg-secondary" style="height:300px;overflow-y:scroll;" data-pdf="https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf"></div>

        </div>
    </main>


              
            
!

CSS

              
                .pdf-container {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex !important;
  width: 100% !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px;
  overflow-y: scroll;
  flex-grow: 1;
}
        
.pdf-container *{
    align-self: center;
    margin-top: 6px;
}

.spinner-container {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex !important;
  width: 100% !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.spinner-container *{
  align-self: center;
  color: white;
}

.lds-ring {
  display: inline-block;
  position: relative;
  width: 100px;
  height: 100px;
}

.lds-ring div {
  box-sizing: border-box;
  display: block;
  position: absolute;
  width: 64px;
  height: 64px;
  margin: 8px;
  border: 8px solid #fff;
  border-radius: 50%;
  animation: lds-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
  border-color: #fff transparent transparent transparent;
}
.lds-ring div:nth-child(1) {
  animation-delay: -0.45s;
}
.lds-ring div:nth-child(2) {
  animation-delay: -0.3s;
}
.lds-ring div:nth-child(3) {
  animation-delay: -0.15s;
}

@keyframes lds-ring {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
              
            
!

JS

              
                function loadPdf(element)
{
    var spinner = `
        <div class="spinner-container">
            <div class="lds-ring">
                <div></div><div></div><div></div><div></div>
            </div>
            <span style="text-align:center;font-size:2rem;">Loading PDF...</span>
        </div>`;
    $(element).append(spinner);

    var container = document.createElement('div');
    container.className='pdf-container';
    var data = $(element).data('pdf');
    
    // Loaded via <script> tag, create shortcut to access PDF.js exports.
    var pdfjsLib = window['pdfjs-dist/build/pdf'];
    // The workerSrc property shall be specified.
    pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.6.347/pdf.worker.min.js';

    // Asynchronous download of PDF

    var loadingTask = pdfjsLib.getDocument(data);
    loadingTask.promise.then(function(pdf) {
        console.log('PDF loaded');
        renderPage(pdf,container, function(){
            $(element).html("");
            $(element).append(container);
        });
        
    }, function (reason) {
            // PDF loading error
            console.error(reason);            
    });
}

function renderPage(pdf,container,renderCompleteCallback,pageNumber)
{

    if(!pageNumber){
        pageNumber = 1;
    }

    var totalPages = pdf.numPages;           
    console.log(totalPages, pageNumber);
    if(pageNumber > totalPages){
        renderCompleteCallback();
        return;
    }

    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.createElement('canvas');
        var context   = canvas.getContext('2d');
        canvas.height = viewport.height;
        canvas.width  = viewport.width;

        // Render PDF page into canvas context
        var renderContext = {
            canvasContext: context,
            viewport: viewport
        };
        var renderTask = page.render(renderContext);
        renderTask.promise.then(function () {
            console.log('Page rendered');
            $(container).append(canvas);
            pageNumber++;
            renderPage(pdf,container,renderCompleteCallback,pageNumber);
        });
    });
}

(function ( $ ) {
    $.fn.pdf = function() {
        loadPdf(this);
        return this;
    };
}( jQuery ));

  $( document ).ready(function(){
           $("#pdf").pdf();         
  });
              
            
!
999px

Console