从目录中查看PDF文件 [英] View PDF file from Directory

查看:114
本文介绍了从目录中查看PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



i希望从目录中搜索和查看pdf文件

搜索我这样做的代码如下:

Hello,

i want to search and view pdf file from directory
search i have done this is the code below:

<div>
        <%--<div id="divClass"  runat="server"></div>--%>
        <asp:TextBox ID="txtFormnum" runat="server"></asp:TextBox>
        <asp:Button ID="btnsrch" runat="server" Text="Search" OnClick="btnsrch_Click1" />
        <asp:GridView ID="GVSrchfrmpdf" runat="server">
 
        </asp:GridView>
 
    </div>







public class fileinformation
    {
        public fileinformation(string org, string ext, string name, string path, long size)
        { filenameWithPath = org; fileextention = ext; filename = name; filepth = path; filesize = size; }
        public string filenameWithPath { get; set; }
        public string fileextention { get; set; }
        public string filename { get; set; }
        public string filepth { get; set; }
        public long filesize { get; set; }
    }
 

 
    public static void GetFiles(string sourceDir)
    {
        DirectoryInfo di = new DirectoryInfo(sourceDir);
        FileInfo[] subFiles = di.GetFiles("*", SearchOption.AllDirectories);
 
        if (subFiles.Length > 0)
        {
            foreach (FileInfo f in subFiles)
            {
                str.Add(new fileinformation(f.FullName, f.Extension, f.Name, f.DirectoryName, f.Length));
            }
        }
    }
 
    static List<fileinformation> str = new List<fileinformation>();
 
protected void btnsrch_Click1(object sender, EventArgs e)
    {
        //BindGridview();
        GetFiles("D:\AmakinilAnwar\FormWisePDF\");
 
        List<fileinformation> result = new List<fileinformation>();
 
        result = (from r in str where r.filename.Contains(txtFormnum.Text) select r).ToList();
 
        GVSrchfrmpdf.DataSource = result;
        GVSrchfrmpdf.DataBind();
    }





现在我想查看文件我该怎么做?



请帮助



Now i want to view file how can i do that ?

please help

推荐答案

由于PDF不是W3标准的一部分,你绝不能假设PDF可以在浏览器。它需要一个单独的查看器,可以安装或不安装为浏览器插件。这种插件是可选的。因此,最好简单地将锚点指向您的PDF文件(使用 href br mode =hold/>这样,用户将获得一个选项在浏览器中查看此文件,但仅在安装了PDF插件时才能使用默认PDF查看器查看该文件(如果已为您的系统配置),或者下载文件,这是非常合理的,因为用户始终可以稍后查看该文档。最好不要偏离这个强大的架构。



如果您不喜欢它,您可以尝试创建自己的软件在服务器端,将PDF映射到某些HTML,我不建议:PDF渲染模型太不同了;它就像纸质打印输出,是一种完全僵化的东西。当然,创建我们自己的插件是没有意义的,因为它会将情况减少到上述情况。



-SA
As PDF is not a part of W3 standards, you should never assume that PDF can be viewed in the browser. It requires a separate viewer, which may or may not be installed as a browser plug-in. Such plug-in is optional. So, it's the best to simply put an anchor pointing to your PDF file (using the hrefbr mode="hold" />This way, the user will get an option to view this file in browser, but only if a PDF plug-in is installed, to view it using a default PDF viewer, if so is configured for your system, or download the file, which is quite reasonable, because the user can always view the document later. It's the best not to deviate from this robust schema.

If you don't like, it, you could try to create your own software based on the server side, mapping PDF to some HTML, which I would not recommend: PDF rendering model it too different; it is like a paper printout, a totally rigid thing. Of course, it makes no sense to create our own plug-in, because it would reduce the situation to the one described above.

—SA


这篇关于从目录中查看PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆