admin管理员组

文章数量:1534206

回答:

Previous

Next

Page: /

//

// NOTE:

// Modifying the URL below to another server will likely *NOT* work. BecAuse of browser

// security restrictions, we have to use a file server with special headers

// (CORS) - most servers don't SUpport cross-origin browser requests.

//

var url = 'http://cdn.mozilla/PDFjs/tracemonkey.PDF';

//

// Disable workers to avoID yet another cross-origin isSUe (workers need the URL of

// the script to be loaded, and currently do not allow cross-origin scripts)

//

PDFJS.disableWorker = true;

var PDFDoc = null,

pageNum = 1,

scale = 0.8,

canvas = document.getElementById('the-canvas'),

ctx = canvas.getContext('2d');

//

// Get page info from document, resize canvas aCCordingly, and render page

//

function renderPage(num) {

// Using PRomise to fetch the page

PDFDoc.getPage(num).then(function(page) {

var viewport = page.getViewport(scale);

canvas.height = viewport.height;

canvas.wIDth = viewport.wIDth;

// Render PDF page into canvas context

var renderContext = {

canvasContext: ctx,

viewport: viewport

};

page.render(renderContext);

});

// Update page counters

document.getElementById('page_num').textContent = pageNum;

document.getElementById('page_count').textContent = PDFDoc.numPages;

}

//

// Go to PRevious page

//

function goPrevious() {

if (pageNum <= 1)

return;

pageNum--;

renderPage(pageNum);

}

//

// Go to next page

//

function goNext() {

if (pageNum >= PDFDoc.numPages)

return;

pageNum++;

renderPage(pageNum);

}

//

// Asynchronously download PDF as an ArrayBuffer

//

PDFJS.getDocument(url).then(function getPdfHelloWorld(_PDFDoc) {

PDFDoc = _PDFDoc;

renderPage(pageNum);

});

本文标签: 浏览器页面网页html