mozilla / pdf.js

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

pdfLinkService resetting zoom when clicking an internal link #10712

Closed Jon-Murray closed 5 years ago

Jon-Murray commented 5 years ago

Hi all,

I have noticed some strange behaviour when using internal links. Basically, opening any document with the web viewer (or just in FF from the local file system) clicking a link will reset the zoom to scale in/out massively (fits to page-width). Using this random PDF i found online as an example - http://gahp.net/wp-content/uploads/2017/09/sample.pdf

I've looked over a lot, but haven't found any documentation on pdfLinkService to be able to specify how a link should be handled when clicked inside a PDF. I've ended up fixing this by removing (for me) the below line in the scrollPageIntoView function in pdf_viewer.js:

  if (scale && scale !== this._currentScale) {
        // this.currentScaleValue = scale; <-- just this line
      }

This allows any internal link clicked to scroll automatically, and be the same as what is specified in pdfViewer.currentScale. I can't say when this issue started, as i'm just upgrading pdf.js versions, but i'm 99% sure this was not the default in older versions.

Is there a way this behaviour could be made configurable in the future?

Snuffleupagus commented 5 years ago

I have noticed some strange behaviour when using internal links. Basically, opening any document with the web viewer

The "any document" part is unfortunately not correct here, since there's loads of examples where that does not happen; for example the PDF specification or the LaTeX introduction.

[...] clicking a link will reset the zoom to scale in/out massively (fits to page-width).

This will only happen when the PDF file itself actually specifies this behaviour for the relevant Destinations used by the LinkAnnotations; please refer to https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G11.2063217

I can't say when this issue started, as i'm just upgrading pdf.js versions, but i'm 99% sure this was not the default in older versions.

There's been no changes to this code and/or its behaviour lately, the more likely explanation is that you're simply opening different PDF files than before.

Is there a way this behaviour could be made configurable in the future?

Given that the PDF files behave as expected, according to the specification, there's the question if such an option is actually wanted (since it's not as simple as just disabling that line of code you're referring to, without possibly other things breaking).

timvandermeij commented 5 years ago

Closing since this is expected behavior according to the spec.