Print Pdf from javascript embed tag

后端 未结 4 401
星月不相逢
星月不相逢 2020-12-09 19:16

I have a PDF file and I am trying to print it via Javascript. I have tried this embed trick: Silent print a embedded PDF however, the print function never becomes available

4条回答
  •  悲哀的现实
    2020-12-09 20:01

    There is a way to render the whole pdf in a browser (instead of embedding an external application), which gives you full access to browser APIs in regard to the pdf.

    This is Mozilla's pdf implementation in JavaScript: https://github.com/mozilla/pdf.js/
    And this is the showcase: http://mozilla.github.io/pdf.js/web/viewer.html (notice the print button on upper right).

    Check out the viewer code here for the details on how it works: https://github.com/mozilla/pdf.js/blob/master/web/viewer.js

    On the minus side — it's going to be way harder, than just embedding.
    On the plus side, it will actually work.

提交回复
热议问题