123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- var pdfjsLib = window['pdfjs-dist/build/pdf'];
- //pdfjsLib.disableWorker = true;
- pdfjsLib.getDocument(url).then(function(pdf){
- var page_num = 1;
- pdf.getPage(page_num).then(function(page){
- var scale = 1.5;
- var viewport = page.getViewport(scale);
- var canvas = $('#the-canvas')[0];
- var context = canvas.getContext('2d');
- canvas.height = viewport.height;
- canvas.width = viewport.width;
- var canvasOffset = $(canvas).offset();
- var $textLayerDiv = $('#text-layer').css({
- height : viewport.height+'px',
- width : viewport.width+'px',
- top : canvasOffset.top,
- left : canvasOffset.left
- });
- page.render({
- canvasContext : context,
- viewport : viewport
- });
- page.getTextContent().then(function(textContent){
- console.log( textContent );
- var textLayer = new TextLayerBuilder({
- textLayerDiv : $textLayerDiv.get(0),
- pageIndex : page_num - 1,
- viewport : viewport
- });
- textLayer.setTextContent(textContent);
- textLayer.render();
- });
- });
- });
- 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.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);
- });
|