将powerpoint文件保存为图片

            string filePath = Server.MapPath("/imageCache/" + fileName + ".ppt");//上传文件路径
            string filePathCreate = Server.MapPath("/imageCache/X" + fileName + ".jpg");//单文件临时路径
            string filePathCreateImg = Server.MapPath("/imageCache/I" + fileName + ".jpg");//生成文件路径
            file.SaveAs(filePath);

            if (file != null)
            {
                PPT.Application pptApplication = new PPT.Application();

                PPT.Presentation ppt = pptApplication.Presentations.Open(filePath,
                    Microsoft.Office.Core.MsoTriState.msoCTrue,
                      Microsoft.Office.Core.MsoTriState.msoTriStateMixed,
                        Microsoft.Office.Core.MsoTriState.msoFalse);

                int count = ppt.Slides.Count;
                //(720*540);
                int pageWidth = 720;
                int pageHight = 540;
                Bitmap bitmap = new Bitmap(pageWidth, pageHight * count);

                int h = 0;
                foreach (PPT.Slide slide in ppt.Slides)
                {
                    slide.Export(filePathCreate, "JPG");
                    Image img = Image.FromFile(filePathCreate);
                    Graphics g = Graphics.FromImage(bitmap);
                    Rectangle rect = new Rectangle(0, h, 720, 540);
                    g.DrawImage(img, rect);
                    img.Dispose();
                    h += pageHight;
                }

                bitmap.Save(filePathCreateImg, System.Drawing.Imaging.ImageFormat.Jpeg);

                ViewBag.image = "I" + fileName + ".jpg";

                return View();
            }
            return null;

问题:依赖于office com,需要在服务器上安装office,不知道谁有不使用officeCom组件将ppt中的幻灯片转换为图片的方法

原文地址:https://www.cnblogs.com/ac1985482/p/2920244.html