繁体   English   中英

如何在ListView C#.net中显示pdf缩略图?

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

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, img1));                              
                                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)
                    {

                    }
                } 

你不能这样做

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

因为PDF不是图像格式,并且.NET无法理解。

这里是一个线程有关如何使用第三方库的PDF转换为图像

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM