mozilla / pdf.js

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

Avoid prompting print dialog on load of pdf viewer #11259

Closed mnithya closed 4 years ago

mnithya commented 4 years ago

Currently, if pdfjs finds "print" in the javascript embedded into the PDF, it prints out the PDF as soon as it loads on the page. Is it possible to add a parameter to pass into the pdf viewer so we can circumvent that feature?

Configuration:

Steps to reproduce the problem:

  1. Create a page with pdfjs viewer in rails and add the following to the view:
    %iframe{ :src => pdfjs.full_path(:file => '../source.pdf') }
  2. source.pdf must have "print" embedded in its javascript (you can do this via Acrobat reader pro and adding this.print({bUI: true,bSilent: false,bShrinkToFit: true}); to its Javascript)

Current behavior: Generating a print dialog on page load

Desired behavior: Pass a param into pdfjs viewer, ex. "print_on_load" and when set to false, will not run the following code: https://github.com/mozilla/pdf.js/blob/50573019b140153e4ab460e74a8018064c9c8f20/web/app.js#L1082-L1089

Cannot link to viewers or pdf as it contains sensitive information.

timvandermeij commented 4 years ago

This could be implemented as an app option, similar to https://github.com/mozilla/pdf.js/blob/master/web/app_options.js#L51 and others. Perhaps a more general setting like disableJavaScript is more suitable since we don't to anything else with JavaScript from PDF files right now or in the foreseeable future (given the security implications).

Snuffleupagus commented 4 years ago

This could be implemented as an app option,

Is that really necessary for the default viewer though, since it would add (unnecessary) code complication for something that's completely unused in the default viewer!? This sort of feature seems like the kind of viewer customization that would be covered by the message in https://mozilla.github.io/pdf.js/getting_started/:

The viewer is built on the display layer and is the UI for PDF viewer in Firefox and the other browser extensions within the project. It can be a good starting point for building your own viewer. However, we do ask if you plan to embed the viewer in your own site, that it not just be an unmodified version. Please re-skin it or build upon it.


Perhaps a more general setting like disableJavaScript is more

We're already not really executing any javascript, since the auto-printing is handled exactly like the user pressing the print button, so that's basically the default any way :-)

timvandermeij commented 4 years ago

Agreed. Let's close this.

rlmumford commented 10 months ago

Why was this closed? It doesn't give any information about how to solve the problem.

How can I stop the print dialog from opening automatically on a PDF?