I preloaded the PDF document onto the canvas using pdf.js.
The canvas contains only one page. So this is what worked for me on one page:
var canvas = document.getElementById('pdfPage'); var win = window.open('', '', ''); var html = "<img src='" + canvas.toDataURL() + "'>"; win.document.write(html); win.document.close(); win.focus(); win.print(); win.close();
I still need to figure out what is needed for multiple pages. If I do, I will edit this answer.
I must say that this approach is not optimal, because it does not print the PDF page "camera ready" or, in other words, in its original form. It prints a pdf page image. The difference is the fields that should not be there, and the header / footer, which should not be, since they are not in the original document. Therefore, I will look for an approach that prints it, as the pdf.js viewer does - it has an original form accurate to an orignal document.
source share