简体   繁体   English

在 javascript 中下载大 PDF

[英]Download large PDF in javascript

I have a website which hosts large PDF documents, as well as some other file formats.我有一个托管大型 PDF 文档以及其他一些文件格式的网站。

How can I open up a download-dialog box in javascript so that the user can save the document to their computer?如何在 javascript 中打开下载对话框,以便用户可以将文档保存到他们的计算机?

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) PDF 总是需要下载(即使对于 iframe / embed /object ),所以不要将它们用作服务器上潜在的双重过载,一次下行并通过脚本显示可能第二次(但是如果用户选择“另存为“查看器中的按钮下载应该只是一次)

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. 注意单击图标可能会显示基于浏览器安全性的空白页面,这是正常的,因此建议用户自行决定。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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