public override bool Convert(string sourceFilePath, string targetPdfPath) { using (Aspose.Slides.Pptx.PresentationEx pres = new Aspose.Slides.Pptx.PresentationEx(sourceFilePath)) { pres.Save(targetPdfPath, Aspose.Slides.Export.SaveFormat.Pdf); } return(File.Exists(targetPdfPath) && new FileInfo(targetPdfPath).Length > 0); }
private static void PptxToImg(string filePath, int currentNo, int pageSize) { string filename = Path.GetFileNameWithoutExtension(filePath).ToLower(); var ppt = new Aspose.Slides.Pptx.PresentationEx(filePath); string imgpath = imageDirectoryPath + "/" + filename + ".pdf"; if (!File.Exists(imgpath)) { ppt.Save(imgpath, Aspose.Slides.Export.SaveFormat.Pdf); } PdfToImg(imgpath, currentNo, pageSize); }
public FileResult Process(PatientPortal.Models.PatientModel p) { var fs = new FileStream(Server.MapPath("../..") + "\\Content\\template.pptx", System.IO.FileMode.Open, System.IO.FileAccess.Read); var ppt = new Aspose.Slides.Pptx.PresentationEx(fs); fs.Close(); (ppt.Slides[0].Shapes[0] as Aspose.Slides.Pptx.AutoShapeEx).TextFrame.Text = p.ID; int x = 1; int fields_in_slide = 0; var unwritten_text = ""; foreach (PropertyInfo prop in typeof(PatientModel).GetProperties()) { if (prop.GetValue(p) != null) { if (fields_in_slide == 5) { ppt.Slides.AddClone(ppt.Slides[1]); fields_in_slide = 0; x++; } string title; DisplayAttribute[] attributes = (DisplayAttribute[])prop.GetCustomAttributes(typeof(DisplayAttribute), false); if ((attributes != null) && (attributes.Length > 0)) { title = attributes[0].Name; } else { title = prop.Name; } var value = prop.GetValue(p); unwritten_text = title + ":" + prop.GetValue(p).ToString() + "\n"; (ppt.Slides[x].Shapes[1] as Aspose.Slides.Pptx.AutoShapeEx).TextFrame.Text += fields_in_slide++; } } //var img = ppt.Images.AddImage(System.Drawing.Image.FromFile(Server.MapPath("../..") + "\\target\\Picture1.png")); //ppt.Slides[2].Shapes.AddPictureFrame(ShapeTypeEx.Rectangle, 100, 100, img.Width, img.Height, img); ppt.Save(Server.MapPath("../..") + "/target/casepresentation.pptx", Aspose.Slides.Export.SaveFormat.Pptx); return(new FileStreamResult(new FileStream(Server.MapPath("../..") + "/target/casepresentation.pptx", System.IO.FileMode.Open, System.IO.FileAccess.Read), "application/vnd.openxmlformats-officedocument.presentationml.presentation")); }
public static int getPptxCount(string filePath) { string filename = Path.GetFileNameWithoutExtension(filePath).ToLower(); var ppt = new Aspose.Slides.Pptx.PresentationEx(filePath); string imgpath = imageDirectoryPath + "/" + filename + ".pdf"; if (!File.Exists(imgpath)) { ppt.Save(imgpath, Aspose.Slides.Export.SaveFormat.Pdf); } int pptxCount = getPDFCount(filePath); return(pptxCount); }
/// <summary> /// PowerPoint格式转换(PowerPoint文件不能为空,默认转成PDF) /// </summary> /// <param name="sourcePath">源路径</param> /// <param name="targetPath">目标路径</param> /// <param name="targetFileType">转换类型</param> /// <returns></returns> public static bool PowerPointConvert(string sourcePath, string targetPath, Aspose.Slides.Export.SaveFormat targetFileType = Aspose.Slides.Export.SaveFormat.Pdf) { var extension = new FileInfo(sourcePath).Extension.ToLower(); if (extension == ".ppt") { var ppt = new Aspose.Slides.Presentation(@sourcePath); ppt.Save(@targetPath, targetFileType); return(true); } if (extension == ".pptx") { var pptx = new Aspose.Slides.Pptx.PresentationEx(@sourcePath); pptx.Save(@targetPath, targetFileType); return(true); } throw new IOException(sourcePath + " 非PowerPoint文件"); }
/// <summary> /// PPT文件转换 /// </summary> /// <param name="pptPath">ppt路径</param> /// <param name="imgPath">图片保存的路径</param> private int PPTToImg(string pptPath, string imgName) { string dataPath = ConfigurationManager.AppSettings["SysDataPath"].ToString(); string paramSource = Server.MapPath(dataPath + "/ppt/") + pptPath; string imgPath = dataPath + "/img/" + imgName; CheckDirect(Server.MapPath(imgPath)); string paramTarget = Server.MapPath(imgPath); var index = 0; Aspose.Slides.Pptx.PresentationEx pres = new Aspose.Slides.Pptx.PresentationEx(paramSource); foreach (Aspose.Slides.Pptx.SlideEx p in pres.Slides) { index++; //Create a full scale image Image bmp = p.GetThumbnail(1f, 1f);; //Save the image to disk in JPEG format bmp.Save(Path.Combine(paramTarget, string.Format("{0}.jpg", index)), System.Drawing.Imaging.ImageFormat.Jpeg); } return(index); }
public FileResult Process(PatientPortal.Models.PatientModel p) { var fs = new FileStream(Server.MapPath("../..") + "\\Content\\template.pptx", System.IO.FileMode.Open, System.IO.FileAccess.Read); var ppt = new Aspose.Slides.Pptx.PresentationEx(fs); fs.Close(); (ppt.Slides[0].Shapes[0] as Aspose.Slides.Pptx.AutoShapeEx).TextFrame.Text = p.ID; int x = 1; int fields_in_slide = 0; var unwritten_text = ""; foreach (PropertyInfo prop in typeof(PatientModel).GetProperties()) { if (prop.GetValue(p) != null) { if (fields_in_slide == 5) { ppt.Slides.AddClone(ppt.Slides[1]); fields_in_slide = 0; x++; } string title; DisplayAttribute[] attributes = (DisplayAttribute[])prop.GetCustomAttributes(typeof(DisplayAttribute), false); if ((attributes != null) && (attributes.Length > 0)) title = attributes[0].Name; else title = prop.Name; var value = prop.GetValue(p); unwritten_text = title + ":" + prop.GetValue(p).ToString() + "\n"; (ppt.Slides[x].Shapes[1] as Aspose.Slides.Pptx.AutoShapeEx).TextFrame.Text += fields_in_slide++; } } //var img = ppt.Images.AddImage(System.Drawing.Image.FromFile(Server.MapPath("../..") + "\\target\\Picture1.png")); //ppt.Slides[2].Shapes.AddPictureFrame(ShapeTypeEx.Rectangle, 100, 100, img.Width, img.Height, img); ppt.Save(Server.MapPath("../..") + "/target/casepresentation.pptx", Aspose.Slides.Export.SaveFormat.Pptx); return new FileStreamResult(new FileStream(Server.MapPath("../..") + "/target/casepresentation.pptx", System.IO.FileMode.Open, System.IO.FileAccess.Read), "application/vnd.openxmlformats-officedocument.presentationml.presentation"); }