mozilla / pdf.js

PDF Reader in JavaScript
https://mozilla.github.io/pdf.js/
Apache License 2.0
48.25k stars 9.96k forks source link

Cannot set fixed width (and height) on the pageviewer example #13989

Closed handhikadj closed 3 years ago

handhikadj commented 3 years ago

Attach (recommended) or Link to PDF file here: it's on the example

Configuration:

Steps to reproduce the problem:

  1. set the width (and height) in style property of <div id="pageContainer" class="pdfViewer singlePageView"></div>
  2. Go to: http://localhost:8888/examples/components/pageviewer.html

What is the expected behavior? (add screenshot) Can set fixed width and height

What went wrong? (add screenshot) Cannot set it

image

Notice the canvas and textLayer width and height don't get set

Snuffleupagus commented 3 years ago

set the width (and height) in style property of <div id="pageContainer" class="pdfViewer singlePageView"></div>

Sorry, but it's not expected to work like that since the scale (in the pageviewer.js file) is what controls the final size of the canvas. To work-around that, you'll need to modify the scale accordingly to enforce a particular width or height; please see the "Alternatively, if you want the canvas to render to a certain pixel size you could do the following:"-part of the example at https://mozilla.github.io/pdf.js/examples/index.html#rendering-the-page

Closing as answered (or possibly a duplicate of e.g. issue #5628).