简体   繁体   中英

Open a file in a print window by getting the file from the file url specified

I am trying to implement a print option in my application using jQuery . I will have the url of the file to be printed as the src attribute of an <a> tag . All I am trying to do is to get the file from the url specified and open it in the print window from where user can print it. The code i use is as follows:

<a id="print-5569" href="http://www.ibiblio.org/ebooks/Baum/Santa_Claus.pdf "><i class="fa fa-download"></i></a>

I tried many solutions found online, but noting worked for me. One of the sample I tried is the one below: https://www.sitepoint.com/load-pdf-iframe-call-print/

While I search online, i find plugins for this. But i dont want to add a plugin just for this. Is there any solution for this.

If the pdf is stored on the same domain, you can do this:

document.getElementById('print-5569').addEventListener('click', () => {
    var w = window.open('http://www.ibiblio.org/ebooks/Baum/Santa_Claus.pdf');
    w.print();
});

Otherwise, you can pair this method with a simple pdf proxy type thing running on the same domain, like google drive has. (ex. https://drive.google.com/viewerng/viewer?url=http://www.ibiblio.org/ebooks/Baum/Santa_Claus.pdf )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM