简体   繁体   中英

Download large PDF in javascript

I have a website which hosts large PDF documents, as well as some other file formats.

How can I open up a download-dialog box in javascript so that the user can save the document to their computer?

PDF always needs download (even for iframe / embed /object ) so do not use those as its then potential double overload on server, once to downlink and show then potentially a second time by the scripting (However if user selects the "save download as" button in viewer the download should be just once)

The answer is display a small image or icon to show the download content, then back that up with

<a href="file.pdf" download="filename.pdf"><Img src="cover.png"></a>

something like this:-

在此处输入图像描述

 <a href="https://africau.edu/images/default/sample.pdf" download="A Sample.pdf"><img src="https://www.freeiconspng.com/uploads/download-pdf-icon-png-icon-29.png" width="128" height="128"><a><br>right click icon to chose download options
note clicking the icon may show a blank page based on browser security, that is normal, hence the suggestion the user uses their discretion.

在此处输入图像描述

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