Closed Bug 874200 Opened 8 years ago Closed 8 months ago

Printing the contents of a pdf.js iframe fails

Categories

(Firefox :: PDF Viewer, defect, P3)

22 Branch
defect

Tracking

()

RESOLVED DUPLICATE of bug 911444

People

(Reporter: peterbe, Unassigned)

Details

(Whiteboard: [pdfjs-c-integration][pdfjs-d-printing])

This is not to be confused with https://bugzilla.mozilla.org/show_bug.cgi?id=792816 which is about permissions on the PDF file. Not about security within the browser. 

To reproduce, try http://storage.michaelaquilina.com/ff-print/ (click on "Print the PDF") and notice the "[13:34:55.653] Error: Permission denied to access property 'print' @ http://storage.michaelaquilina.com/ff-print/:10" console message. 

This means that the second example on https://developer.mozilla.org/en-US/docs/Printing is broken if the URL you load in the iframe is a PDF file. 

This used to work on Firefox 12 (the oldest I had available) but isn't working in 21, 23 or 24. (haven't tested Beta).
It also works in Chrome.
Component: General → PDF Viewer
(In reply to Peter Bengtsson [:peterbe] from comment #0)
> This used to work on Firefox 12 (the oldest I had available) but isn't
> working in 21, 23 or 24. (haven't tested Beta).
> It also works in Chrome.

FF12 didn't include PDF.js, so is the issue reproducible with a 3rd-party PDF reader loading the PDF document?

I tried with FF8, clicking on "Print the PDF" doesn't do anything.
Flags: needinfo?(peterbe)
This works fine for me with Adobe Reader on Windows 7 w/FF21, but not pdf.js

When loading with Adobe Reader, the iframe loads a PluginDocument which creates an Adobe Reader object. PluginDocument has a hook for forwarding print calls to the plugin, so Reader's print function is called.

pdf.js appears to load as a chrome document, which the content page cannot reach into. It either needs to provide a similar print hook or run its top-level document as content.
(In reply to Loic from comment #1)
> (In reply to Peter Bengtsson [:peterbe] from comment #0)
> > This used to work on Firefox 12 (the oldest I had available) but isn't
> > working in 21, 23 or 24. (haven't tested Beta).
> > It also works in Chrome.
> 
> FF12 didn't include PDF.js, so is the issue reproducible with a 3rd-party
> PDF reader loading the PDF document?
> 
Yes it's most likely ever since pdf.js was introduced. 

> I tried with FF8, clicking on "Print the PDF" doesn't do anything.

Open the Web Console and you'll see the permission error.
Flags: needinfo?(peterbe)
Priority: -- → P3
Whiteboard: [pdfjs-c-integration][pdfjs-d-printing]
Summary: Printing the contents of an iframe that loads a PDF is no longer possible → Printing the contents of a pdf.js iframe fails
Relevant comment from https://github.com/mozilla/pdf.js/issues/5397#issuecomment-100372486:

> I think I know the reason for this, at least in Firefox. In a simple example such as the above, 
> if you use the Firefox DevTools to examine document.domain in both the main page and in the 
> iframe, I found that document.domain is pdf.js for the PDF.js renderer—so the browser's cross-origin 
> restrictions are kicking in.

Similarly, I don't think this is directly a PDF.js bug, though I've no idea if there is a good fix.

> Additionally, if I built PDF.js from source, and set my iframe to web/viewer.html?file=, then calling
> telling the iframe to print (as in the OP), it worked fine.
Status: NEW → RESOLVED
Closed: 8 months ago
Resolution: --- → DUPLICATE
Duplicate of bug: 911444
You need to log in before you can comment on or make changes to this bug.