Pdf.js: Viewport does contain width or height

Created on 11 May 2019  路  1Comment  路  Source: mozilla/pdf.js

I wrote #10797 but you closed it before I had time to respond. Here's my latest on this.

After upgrading to pdfjs-2.0.943-dist things still failed and I figured it was the same issues I was having with pdfjs-1.9.426-dist. Turns out it's not.

In pdfjs-2.0.943-dist, this code:

pdf.getPage(1).then(function(page) {
var viewport = page.getViewport({ scale: 1, });
});

returns this viewport:

  1. height: NaN
  2. offsetX: 0
  3. offsetY: 0
  4. rotation: 0
  5. scale: {scale: 1}
  6. transform: (6) [NaN, NaN, NaN, NaN, NaN, NaN]
  7. viewBox: (4) [0, 0, 595.273, 841.886]
  8. width: NaN

I need the width and height so my code fails. I ran the above in a Chrome browser.

I then tried pdfjs-dist-master and things work fine in all platforms. I get this viewport:

  1. height: 841.886
  2. offsetX: 0
  3. offsetY: 0
  4. rotation: 0
  5. scale: 1
  6. transform: (6) [1, 0, 0, -1, 0, 841.886]
  7. viewBox: (4) [0, 0, 595.273, 841.886]
  8. width: 595.273

pdfjs-dist-master partially solves my problem (I get the complete viewport and it works for me in all platforms) but it doesn't contain viewer.html so I rely on pdfjs-2.0.943-dist for the viewer. Between the two I get everything I need but I'd prefer to use one package for both pdf access and viewing.

If possible, please tell me:

  1. how I can get pdfjs-2.0.943-dist to return a complete viewport.
    or
  2. how I can use viewer.html with pdfjs-dist-master.

Thank you

Most helpful comment

The method signature changed in PR #10369, hence:

  • In version 2.0.943 and earlier it takes "regular" parameters, i.e. formatted as getViewport(scale, rotate, dontFlip).
  • In version 2.1.266 and later it takes an object, i.e. formatted as getViewport({ scale, rotation, dontFlip })

(This change should probably have been done a lot earlier, but it was overlooked previously.)

>All comments

The method signature changed in PR #10369, hence:

  • In version 2.0.943 and earlier it takes "regular" parameters, i.e. formatted as getViewport(scale, rotate, dontFlip).
  • In version 2.1.266 and later it takes an object, i.e. formatted as getViewport({ scale, rotation, dontFlip })

(This change should probably have been done a lot earlier, but it was overlooked previously.)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ousia picture ousia  路  29Comments

collinanderson picture collinanderson  路  29Comments

BadFriend picture BadFriend  路  38Comments

timvandermeij picture timvandermeij  路  28Comments

StevenHarlow picture StevenHarlow  路  29Comments