开发者

How to show thumbnail of pdf in listview C#.net?

开发者 https://www.devze.com 2022-12-08 17:15 出处:网络
ImageList imageList = new ImageList(); if (folder != null && System.IO.Directory.Exists(folder))
ImageList imageList = new ImageList();
                if (folder != null && System.IO.Directory.Exists(folder))
                {
                    try
                    {
                        string[] arrImageName=new string[1000];
                        int Count = 0;
                        string CutName;
                        DirectoryInfo dir = new DirectoryInfo(@folder);
                        foreach (FileInfo file in dir.GetFiles())
                        {
                            try
                            {

                                imageList.ImageSize = new Size(140, 140);
                                imageList.ColorDepth = ColorDepth.Depth32Bit;
                                Image img1 = Image.FromFile(file.FullName);
                                CutName = file.FullName;
                                CutName = CutName.Replace(folder, "");
                                CutName = CutName.Replace("\\", "");
                                arrImageName[Count] = CutName;
                                imageList.Images.Add(FormatImage(imageList.ImageSize.Width, img开发者_运维知识库1));                              
                                Count = Count + 1;
                            }
                            catch
                            {
                                Console.WriteLine("This is not an image file");
                            }     
                        }


                        for (int j = 0; j < imageList.Images.Count; j++)
                        {
                            this.ListView1.Items.Add((j + 1) + "/" + imageList.Images.Count + " " + "\r\n" + arrImageName[j]);                                
                            this.ListView1.Items[j].ImageIndex = j;
                        }

                        this.ListView1.View = View.LargeIcon;
                        this.ListView1.LargeImageList = imageList;
                        //import(folder);
                    }
                    catch (Exception ex)
                    {

                    }
                } 


You cant do this

 Image img1 = Image.FromFile(file.FullName);

because a PDF is not an image format and is not understood by .NET.

Here is a thread on how to convert the PDF to an image using a 3rd party library

0

精彩评论

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