0

I try to display the PDF files in the Listview as LargeIcon. But it doesn't display.

I can display the all image formats.

How to display the PDF file in the ListView?

I tried like this only, like image display.

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;
        }
    }
}
user178222
  • 39
  • 1
  • 5
  • What exactly are you trying to display? What is your existing code? – SLaks Oct 09 '09 at 00:22
  • 1
    A PDF is not an image. Was your intention to display the icon of a PDF file inside the listview ? You can do so by just adding the image of the PDF icon to the listview. – Andrew Keith Oct 09 '09 at 00:22

2 Answers2

1

You are going to need to rasterize the PDF. I think ImageMagick (maybe in conjunction with Ghostscript) can do this.

Disclaimer: I work for Atalasoft

We have a .NET library for Rasterizing PDF to an image available here:

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

Lou Franco
  • 87,846
  • 14
  • 132
  • 192
0

You need to find a .Net PDF renderer.

See this question.

Community
  • 1
  • 1
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964