Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Printing the hidden canvas of PDF.js viewer

2,406 views
Skip to first unread message

Simon Males

unread,
Jun 12, 2015, 12:13:04 PM6/12/15
to mozilla-d...@lists.mozilla.org
Hello,

I am really interested in printing PDFs across devices. I really like viewer.html printing experience. To me it is amazing that no document metadata is included in the print output.

Up until today, I have being experimenting with printing PDFs within Iframes though it has proven difficult on Firefox, Internet Explorer and Android browsers.

I would like to silently render the PDF.js viewer within a document and trigger a print job on it.

>From what I can tell viewer.js assumes that the document doesn't include anything else.

Interested to know if other people are using PDF.js for printing.

Simon Males

unread,
Jun 15, 2015, 12:22:54 PM6/15/15
to mozilla-d...@lists.mozilla.org
This is pretty complex for me at the moment, I still cannot entirely see how canvas printing hides page metadata from the print out.

Then I uncovered this gem from the original proposal: "Using CSS it's possible to make one canvas element take up one physical page and then precisely layout content on the canvas." https://etherpad.mozilla.org/printCallbackSpec

I would love to see a reduced example of this, I fail to see in PDF.js how this is actually achieved.

ydel...@mozilla.com

unread,
Jun 15, 2015, 12:41:04 PM6/15/15
to mozilla-d...@lists.mozilla.org
On Monday, June 15, 2015 at 11:22:54 AM UTC-5, Simon Males wrote:
> Then I uncovered this gem from the original proposal: "Using CSS it's possible to make one canvas element take up one physical page and then precisely layout content on the canvas." https://etherpad.mozilla.org/printCallbackSpec
>
> I would love to see a reduced example of this, I fail to see in PDF.js how this is actually achieved.

The mozPrintCallback was implemented at https://bugzilla.mozilla.org/show_bug.cgi?id=745025 . You can find its usage in PDF.js at the https://github.com/mozilla/pdf.js/blob/c8fd9c8c06cf14ff2203a089f17c881dcdb9ca10/web/pdf_page_view.js#L519 -- the callback is invoked during printing and an argument with device-specific 2d context is passed to it. When painting is done the callee must invoke the done method to complete the asynchronous operation.

See also https://bugzilla.mozilla.org/show_bug.cgi?id=743252 about moznomarginboxes, which hides a URL and page numbers from the printed material.

Thanks.

Simon Males

unread,
Jun 15, 2015, 5:23:31 PM6/15/15
to mozilla-d...@lists.mozilla.org
Interesting thank you!

So it looks like for cross browser support @page { margin: 0; } is required.
0 new messages