@if(!defined('LOAD_PDFJS'))
	@push('scripts')
		<script type="text/javascript" src="//mozilla.github.io/pdf.js/build/pdf.js"></script>
		<script type="text/javascript">

			var pdfjsLib = window['pdfjs-dist/build/pdf'];
			var canvas = null;

			// The workerSrc property shall be specified.
			pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';

			window.initPDFViewer = function(url, container) {
				canvas = container;
				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 = 0.25;
					    var viewport = page.getViewport({scale: scale});

					    console.log(canvas);

					    // 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
					    var renderContext = {
					    	canvasContext: context,
					    	viewport: viewport
					    };
					    var renderTask = page.render(renderContext);
					    renderTask.promise.then(function () {
					    	console.log('Page rendered');
					    });
					});
				}, function (reason) {
					// PDF loading error
					console.error(reason);
				});
			};
		</script>
	@endpush
	@php(define('LOAD_PDFJS', true))
@endif