Last active
December 20, 2015 07:19
-
-
Save rjcorwin/6092002 to your computer and use it in GitHub Desktop.
From pdf.js/examples/helloworld/hello.js, modify it to open display the page specified at the width of browser. We do this by looking at the width of the PDF's page and the width of the window and then setting the scale of the page's viewport accordingly (see line 5).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PDFJS.getDocument(url).then(function(pdf) { | |
// Using promise to fetch the page | |
pdf.getPage(1).then(function(page) { | |
// Scale the PDF to the width of the window | |
var scale = window.innerWidth / page.view[2] | |
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 | |
// | |
var renderContext = { | |
canvasContext: context, | |
viewport: viewport | |
}; | |
page.render(renderContext); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment