• 将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中的幻灯片转换为图片的方法

  • 相关阅读:
    第五次站立会议
    第四次站立会议
    迪杰斯特拉算法求最短路径问题
    数组课堂作业
    java2
    Java书写add函数
    《大道至简》第二章(是懒人创造了方法)读后感
    大二暑假周进度报告之四
    大二暑假周进度报告之三
    大二暑假周进度报告之二
  • 原文地址:https://www.cnblogs.com/ac1985482/p/2920244.html
Copyright © 2020-2023  润新知