Print Pdf from javascript embed tag

后端 未结 4 392
星月不相逢
星月不相逢 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 19:47

    With Javascript, I am not sure we can do this. However can be achieved using script injection into the pdf file. If my understanding is correct this is what Google does.

    For example.

    1. Open the url : https://drive.google.com/viewerng/viewer?url=http://www.energy.umich.edu/sites/default/files/pdf-sample.pdf
    2. Now click on print icon.
    3. As you can see a new window with print command injected into the pdf is opened. Once the pdf is loaded the built in print command is triggered. You can see the print triggered whenever you refresh the page. That means the print behavior is attached to the document load event.

    We can use iTextSharp to simulate above behavior.

提交回复
热议问题