colincameron colincameron - 3 months ago 58
Javascript Question

Printing PDF using pdf.js

I am embedding a single page PDF in a page using pdf.js and I want to be able to print just the PDF, not the whole HTML page.

Is this possible?


I finally worked it out.

I can't post my code here, but here's what I did:

I rendered the PDF onto 2 canvases, one small for the thumbnail and one huge for printing (hidden). I then had a print button that opened a new window containing an img tag containing the contents of the huge canvas using toImageURL(). The print() function was called on the new window, followed by close() to close it automatically once printed.

This resulted in an almost-full-size print of the PDf, albeit with the usual page no and datestamp from the browser.