【问题标题】:PDF file doesn't display in the listview c# 2008PDF 文件不显示在列表视图中 c# 2008
【发布时间】:2010-12-05 04:52:32
【问题描述】:

我尝试将Listview 中的PDF 文件显示为LargeIcon。但它不显示。

我可以显示所有图像格式。

如何在ListView中显示PDF文件?

我只试过这样,比如图像显示。

private  void import(string path)
{

    ListView1.Items.Clear();
    ImageList imageList = new ImageList();
    imageList.Images.Clear();
    imageList.ImageSize = new Size(170, 140);
    imageList.ColorDepth = ColorDepth.Depth32Bit;

    int i = 0;

    ////ArrayList to hold the files with the certain extensions
    ArrayList files1 = new ArrayList();

    if (Directory.Exists(path).Equals(true))
    {
        string validExtensions = "*.pdf";

        //create a string array of our filters by plitting the
        //string of valid filters on the delimiter
        string[] extFilter = validExtensions.Split(new char[] { ',' });

        //loop through each extension in the filter
        foreach (string extension in extFilter)
        {
            files1.AddRange(Directory.GetFiles(path, extension));
            files = (string[])files1.ToArray(typeof(String));
        }

        string[] pathes = new string[files.Length];

        foreach (string file in files)
        {
            pathes[i] = file;
            i++;
        }

        foreach (string path1 in pathes)
        {
            imageList.Images.Add(Bitmap.FromFile(path1));
            FileInfo fileInfo = new FileInfo(path1);
            String strDir = fileInfo.Name;
            ListView1.Items.Add(strDir);
            ListView1.TileSize = new System.Drawing.Size(100, 80);
        }
        for (int j = 0; j < pathes.Length; j++)
        {                
           this.ListView1.Items[j].ImageIndex = j;
        }

        this.ListView1.View = View.LargeIcon;
        this.ListView1.LargeImageList = imageList;

        ListView1.Focus();
        ListView1.Items[0].Selected = true;
        }
    }
}

【问题讨论】:

  • 您到底想显示什么?你现有的代码是什么?
  • PDF 不是图像。您是否打算在列表视图中显示 PDF 文件的图标?您只需将 PDF 图标的图像添加到列表视图即可。

标签: c#


【解决方案1】:

您将需要栅格化 PDF。我认为 ImageMagick(可能与 Ghostscript 结合使用)可以做到这一点。

免责声明:我为 Atalasoft 工作

我们有一个用于将 PDF 光栅化为图像的 .NET 库:

http://atalasoft.com/products/dotimage/pdfrasterizer/

【讨论】:

    【解决方案2】:

    您需要找到一个 .Net PDF 渲染器。

    见this question。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多