Html 从文件夹打开 PDF 的链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12728411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Link to open PDF from folder
提问by Pomster
I have some PDF's sitting in a folder on my computer, is there a way to write a link to open them on to a webpage?
我的计算机上的文件夹中有一些 PDF,有没有办法编写链接以将它们打开到网页?
The main idea is when the site goes live the link will be used to download the pdfs from the folder, but obviously at a later stage the folder will be a temp folder on my website.
主要思想是当网站上线时,链接将用于从文件夹下载 pdf,但显然在稍后阶段,该文件夹将成为我网站上的临时文件夹。
So at the moment i just want to open the pdfs from a link, and the final goal will be to have the links download them.
所以目前我只想从链接打开 pdf,最终目标是让链接下载它们。
Can any one help me?
谁能帮我?
This is the file path to get to the pdf i want to link to.
这是获取我想要链接到的 pdf 的文件路径。
C:\Users\Shaun\Documents\FormValue\CS1.pdf
C:\Users\Shaun\Documents\FormValue\CS1.pdf
How would i create the link?
我将如何创建链接?
回答by Windle
If you want to have a link to a PDF, you just have to put the relative path to the file in the href
attribute of an a
tag. So let's say you had a folder called pdfs
, with the file boom.pdf
inside it, and folder called site
sitting beside it, with the file site.html
in it. Then all you'd have to do is put this link in the html file:
如果您想要链接到 PDF,您只需将文件的相对路径放在标签的href
属性中a
。因此,假设您有一个名为pdfs
的文件夹,boom.pdf
里面有文件,site
旁边有一个名为的文件夹,里面有文件site.html
。然后你所要做的就是把这个链接放在 html 文件中:
<a href="../pdfs/boom.pdf">Link to a pdf</a>
In most (all?) browsers now a days, that will open the PDF in a new tab. To download it you would right-click it and do the Save Link As
thing. Just need to get the path in href
right.
在现在大多数(所有?)浏览器中,这将在新选项卡中打开 PDF。要下载它,您可以右键单击它并执行此操作Save Link As
。只需要找到href
正确的路径。
UPDATE
更新
If you want to use the full path to the file, you need to prefix it with file://
. Then you just put it in the href the same as with a regular link, ending up with something like:
如果要使用文件的完整路径,则需要在其前面加上file://
. 然后,您只需将它放在与常规链接相同的 href 中,最后得到如下内容:
<a href="file://C:\Users\Shaun\Documents\FormValue\CS1.pdf">Link to a pdf</a>
This should work with your set up, but if the pdf and the html files are stored near each other, relative URLs are still a good option. A little bit of Google work should show you how to write those.
这应该适用于您的设置,但如果 pdf 和 html 文件彼此靠近存储,相对 URL 仍然是一个不错的选择。谷歌的一些工作应该会告诉你如何编写这些。
回答by noel
For each PDF just do what I talk about here.
对于每个 PDF,只需执行我在此处讨论的操作。
<object height="950" data="sample-report.pdf" type="application/pdf" width="860">
<p>It appears you don't have a PDF plugin for this browser.
No biggie... you can <a href="sample-report.pdf">click here to
download the PDF file.</a>
</p>
</object>
It works with most browsers and it degrades nicely.
它适用于大多数浏览器,并且降级很好。
回答by user1
If you are using ASP.NET, you can have the link point to a handler that accepts a query string identifying the file, either by file name or a hash of the file. Then the handler can look in the folder for a file that matches the pattern, read the file as a byte array, and then write those bytes to HttpResponse.
如果您使用的是 ASP.NET,则可以让链接指向一个处理程序,该处理程序接受通过文件名或文件散列来标识文件的查询字符串。然后处理程序可以在文件夹中查找与模式匹配的文件,将该文件作为字节数组读取,然后将这些字节写入 HttpResponse。
回答by Cynthia
It sounds like youre asking if you can put a link on a web site to a PDF sitting on your computer. You can't. The files have to be either on another web site or on your site's server.
听起来您是在问是否可以在网站上放置指向计算机上 PDF 的链接。你不能。这些文件必须位于另一个网站或您站点的服务器上。