开发者

PDF file doesn't display in the listview c# 2008

开发者 https://www.devze.com 2022-12-08 16:08 出处:网络
I try to display the PDF files in the Listview as LargeIcon. But it doesn\'t display. I can display the all image formats.

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 = validExt开发者_JAVA技巧ensions.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;
        }
    }
}


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/


You need to find a .Net PDF renderer.

See this question.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号