zoukankan      html  css  js  c++  java
  • 将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中的幻灯片转换为图片的方法

  • 相关阅读:
    7.4 List集合
    vue学习笔记
    javaWEB中web.xml配置文件相关
    maven常用dos命令
    Oracle,sqlserver,mySQl的区别和联系:
    oracle数据库视图,序列,索引的sql语句查看
    java 异常处理
    线程专题
    package、folder和source folder的区别
    Java内存分配之堆、栈和常量池
  • 原文地址:https://www.cnblogs.com/ac1985482/p/2920244.html
Copyright © 2011-2022 走看看