Skip to content

Instantly share code, notes, and snippets.

@amundo
Created October 27, 2018 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amundo/655f0be4e8abe5c5bd67d9f6dd86ea49 to your computer and use it in GitHub Desktop.
Save amundo/655f0be4e8abe5c5bd67d9f6dd86ea49 to your computer and use it in GitHub Desktop.
loading a pdf and rendering a page with pdf.js
pdfjsLib.getDocument('helloworld.pdf')
.then(pdf => pdf.getPage(1)
.then(page => {
var scale = 1.5
var viewport = page.getViewport(scale)
var canvas = document.createElement('canvas')
var context = canvas.getContext('2d')
canvas.height = viewport.height
canvas.width = viewport.width
var renderContext = {
canvasContext: context,
viewport: page.getViewport(scale)
}
page.render(renderContext)
})
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment