public void Chart_Test() { // Arrange var pre = new PresentationEx(Properties.Resources._021); var shapes1 = pre.Slides[0].Shapes; var shapes2 = pre.Slides[1].Shapes; var sp108 = shapes1.Single(x => x.Id == 108); var chart3 = shapes1.Single(x => x.Id == 3).Chart; var sld1Chart4 = shapes1.Single(x => x.Id == 4).Chart; var sld2Chart4 = shapes2.First(x => x.Id == 4).Chart; var lineChartSeries = sld2Chart4.SeriesCollection[1]; // Act var fill = sp108.Fill; //assert: do not throw exception var chartTypeBar = chart3.SeriesCollection[1].Type; var pValueBar = chart3.SeriesCollection[1].PointValues[0]; var chartTypeScatter = chart3.SeriesCollection[2].Type; var pValueScatter = chart3.SeriesCollection[2].PointValues[0]; var category = sld1Chart4.Categories[0]; var pv = lineChartSeries.PointValues[0]; // Assert Assert.Equal(ChartType.BarChart, chartTypeBar); Assert.Equal(56, pValueBar); Assert.Equal(ChartType.ScatterChart, chartTypeScatter); Assert.Equal(44, pValueScatter); Assert.Equal("2015", category); Assert.Equal(17.35, pv); }
static void Main(string[] args) { //Create a workbook Workbook wb = new Workbook(); //Add an excel chart int chartSheetIndex = AddExcelChartInWorkbook(wb); wb.Worksheets.SetOleSize(0, 5, 0, 5); Bitmap imgChart = wb.Worksheets[chartSheetIndex].Charts[0].ToImage(); //Save the workbook to stream MemoryStream wbStream = wb.SaveToStream(); //Create a presentation PresentationEx pres = new PresentationEx(); SlideEx sld = pres.Slides[0]; //Add the workbook on slide AddExcelChartInPresentation(pres, sld, wbStream, imgChart); //Write the output presentation on disk pres.Write("chart.pptx"); }
static void Main(string[] args) { string MyDir = @"Files\"; PresentationEx presentation = new PresentationEx(MyDir + "Sample.ppt"); presentation.Save(MyDir + "Converted.pptx", Aspose.Slides.Export.SaveFormat.Pptx); }
static void Main(string[] args) { string MyDir = @"Files\"; //Instantiate a Presentation class that represents the presentation file using (PresentationEx pres = new PresentationEx(MyDir + "Slides Test Presentation.pptx")) { //Access the first slide SlideEx sld = pres.Slides[0]; //User defined dimension int desiredX = 1200; int desiredY = 800; //Getting scaled value of X and Y float ScaleX = (float)(1.0 / pres.SlideSize.Size.Width) * desiredX; float ScaleY = (float)(1.0 / pres.SlideSize.Size.Height) * desiredY; //Create a full scale image Bitmap bmp = sld.GetThumbnail(ScaleX, ScaleY); //Save the image to disk in JPEG format bmp.Save(MyDir + "Thumbnail2.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); } }
private bool OfficeDocumentToHtml(string sourceDoc, string saveDoc) { bool result = false; //获取文件扩展名 string docExtendName = Path.GetExtension(sourceDoc).ToLower(); switch (docExtendName) { case ".doc": case ".docx": Aspose.Words.Document doc = new Aspose.Words.Document(sourceDoc); doc.Save(saveDoc, Aspose.Words.SaveFormat.Html); result = true; break; case ".xls": case ".xlsx": Workbook workbook = new Workbook(sourceDoc); workbook.Save(saveDoc, SaveFormat.Html); result = true; break; case ".ppt": case ".pptx": PresentationEx pres = new PresentationEx(sourceDoc); pres.Save(saveDoc, Aspose.Slides.Export.SaveFormat.Html); result = true; break; default: break; } return(result); }
static void Main(string[] args) { //Instantiate a Presentation class that represents the presentation file string MyDir = @"Files\"; using (PresentationEx pres = new PresentationEx(MyDir + "Slides Test Presentation.pptx")) { //Access the second slide SlideEx sld = pres.Slides[1]; //Create a memory stream object MemoryStream SvgStream = new MemoryStream(); //Generate SVG image of slide and save in memory stream sld.WriteAsSvg(SvgStream); SvgStream.Position = 0; //Save memory stream to file using (Stream fileStream = System.IO.File.OpenWrite(MyDir + "PresentatoinTemplate.svg")) { byte[] buffer = new byte[8 * 1024]; int len; while ((len = SvgStream.Read(buffer, 0, buffer.Length)) > 0) { fileStream.Write(buffer, 0, len); } } SvgStream.Close(); } }
public void Table_Row_Remove_Test() { // ARRANGE var pre = new PresentationEx(Properties.Resources._009); var sld3Shapes = pre.Slides[2].Shapes; var table3 = sld3Shapes.First(s => s.Id.Equals(3)).Table; var rows = table3.Rows; var numRowsBefore = rows.Count; // ACT rows.RemoveAt(0); var ms = new MemoryStream(); pre.SaveAs(ms); pre.Close(); pre = new PresentationEx(ms); table3 = pre.Slides[2].Shapes.First(s => s.Id.Equals(3)).Table; rows = table3.Rows; var numRowsAfter = rows.Count; // ASSERT Assert.True(numRowsBefore > numRowsAfter); }
// Get a list of the titles of all the slides in the presentation. public static IList<string> GetSlideTitles(string presentationFile) { // Create a new linked list of strings. List<string> texts = new List<string>(); //Instantiate PresentationEx class that represents PPTX using (PresentationEx pres = new PresentationEx(presentationFile)) { //Access all the slides foreach (SlideEx sld in pres.Slides) { //Iterate through shapes to find the placeholder foreach (ShapeEx shp in sld.Shapes) if (shp.Placeholder != null) { if (IsTitleShape(shp)) { //get the text of placeholder texts.Add(((AutoShapeEx)shp).TextFrame.Text); } } } } // Return an array of strings. return texts; }
static void Main(string[] args) { string MyDir = @"Files\"; //Instantiate a Presentation object that represents a Presentation file PresentationEx pres = new PresentationEx(MyDir + "Conversion.ppt"); //Instantiate the TiffOptions class Aspose.Slides.Export.TiffOptions opts = new Aspose.Slides.Export.TiffOptions(); //Setting compression type opts.CompressionType = TiffCompressionTypes.Default; //Compression Types //Default - Specifies the default compression scheme (LZW). //None - Specifies no compression. //CCITT3 //CCITT4 //LZW //RLE //Depth – depends on the compression type and cannot be set manually. //Resolution unit – is always equal to “2” (dots per inch) //Setting image DPI opts.DpiX = 200; opts.DpiY = 100; //Set Image Size opts.ImageSize = new Size(1728, 1078); //Save the presentation to TIFF with specified image size pres.Save(MyDir + "Converted.tiff", Aspose.Slides.Export.SaveFormat.Tiff, opts); }
public void Shape_XandWsetter_Test() { // ARRANGE var pre = new PresentationEx(Properties.Resources._006_1_slides); var shape2 = pre.Slides[0].Shapes.First(x => x.Id == 3); // ACT shape2.X = 4000000; shape2.Width = 6000000; var isPlaceholder = shape2.IsPlaceholder; var isGrouped = shape2.IsGrouped; var ms = new MemoryStream(); pre.SaveAs(ms); pre.Close(); ms.SeekBegin(); pre = new PresentationEx(ms); shape2 = pre.Slides[0].Shapes.First(x => x.Id == 3); pre.Close(); // ASSERT Assert.False(isPlaceholder); Assert.False(isGrouped); Assert.Equal(4000000, shape2.X); Assert.Equal(6000000, shape2.Width); }
public void TablesPropertiesTest() { // ARRANGE var pre = new PresentationEx(Properties.Resources._009); var elements = pre.Slides[2].Shapes; var tblEx = elements.Single(e => e.Id.Equals(3)); var firstRow = tblEx.Table.Rows.First(); // ACT var numRows = tblEx.Table.Rows.Count; var numCells = firstRow.Cells.Count; var numParagraphs = firstRow.Cells.First().TextBody.Paragraphs.Count; var cellTxt = firstRow.Cells.First().TextBody.Text; var prText = firstRow.Cells.First().TextBody.Paragraphs.First().Text; var portionTxt = firstRow.Cells.First().TextBody.Paragraphs.First().Portions.Single().Text; pre.Close(); // ASSERT Assert.Equal(3, numRows); Assert.Equal(3, numCells); Assert.Equal(2, numParagraphs); Assert.Equal("0:0_p1_lvl1\r\n0:0_p2_lvl2", cellTxt); Assert.Equal("0:0_p1_lvl1", prText); Assert.Equal("0:0_p1_lvl1", portionTxt); }
/// <summary> /// 根据附件ID,获取对应查看的视图URL。 /// 一般规则如果是图片文件,返回视图URL地址'/FileUpload/ViewAttach'; /// 如果是Office文件(word、PPT、Excel)等,可以通过微软的在线查看地址进行查看:'http://view.officeapps.live.com/op/view.aspx?src=', /// 也可以进行本地生成HTML文件查看。如果是其他文件,可以直接下载地址。 /// </summary> /// <param name="id">附件的ID</param> /// <returns></returns> public ActionResult GetAttachViewUrl(string id) { string viewUrl = ""; FileUploadInfo info = BLLFactory <FileUpload> .Instance.FindByID(id); if (info != null) { string ext = info.FileExtend.Trim('.').ToLower(); string filePath = GetFilePath(info); bool officeInternetView = false; //是否使用互联网在线预览 string hostName = HttpUtility.UrlPathEncode("http://www.iqidi.com/"); //可以配置一下,如果有必要 if (ext == "xls" || ext == "xlsx" || ext == "doc" || ext == "docx" || ext == "ppt" || ext == "pptx") { if (officeInternetView) { //返回一个微软在线浏览Office的地址,需要加上互联网域名或者公网IP地址 viewUrl = string.Format("http://view.officeapps.live.com/op/view.aspx?src={0}{1}", hostName, filePath); } else { #region 动态第一次生成文件 //检查本地Office文件是否存在,如不存在,先生成文件,然后返回路径供查看 string webPath = string.Format("/GenerateFiles/Office/{0}.htm", info.ID); string generateFilePath = Server.MapPath(webPath); if (!FileUtil.FileIsExist(generateFilePath)) { string templateFile = BLLFactory <FileUpload> .Instance.GetFilePath(info); templateFile = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, templateFile.Replace("\\", "/")); if (ext == "doc" || ext == "docx") { Aspose.Words.Document doc = new Aspose.Words.Document(templateFile); doc.Save(generateFilePath, Aspose.Words.SaveFormat.Html); } else if (ext == "xls" || ext == "xlsx") { Workbook workbook = new Workbook(templateFile); workbook.Save(generateFilePath, SaveFormat.Html); } else if (ext == "ppt" || ext == "pptx") { templateFile = templateFile.Replace("/", "\\"); PresentationEx pres = new PresentationEx(templateFile); pres.Save(generateFilePath, Aspose.Slides.Export.SaveFormat.Html); } } #endregion viewUrl = webPath; } } else { viewUrl = filePath; } } return(Content(viewUrl)); }
static void Main(string[] args) { //Create empty presentation using (PresentationEx pres = new PresentationEx()) { //Accessing first slide SlideEx slide = pres.Slides[0]; //Addding default chart ChartEx ppChart = slide.Shapes.AddChart(ChartTypeEx.ClusteredColumn3D, 20F, 30F, 400F, 300F); //Getting Chart data ChartDataEx chartData = ppChart.ChartData; //Removing Extra default series chartData.Series.RemoveAt(1); chartData.Series.RemoveAt(1); //Modifying chart categories names chartData.Categories[0].ChartDataCell.Value = "Bikes"; chartData.Categories[1].ChartDataCell.Value = "Accessories"; chartData.Categories[2].ChartDataCell.Value = "Repairs"; chartData.Categories[3].ChartDataCell.Value = "Clothing"; //Modifying chart series values for first category chartData.Series[0].Values[0].Value = 1000; chartData.Series[0].Values[1].Value = 2500; chartData.Series[0].Values[2].Value = 4000; chartData.Series[0].Values[3].Value = 3000; //Setting Chart title ppChart.HasTitle = true; ppChart.ChartTitle.Text.Text = "2007 Sales"; PortionFormatEx format = ppChart.ChartTitle.Text.Paragraphs[0].Portions[0].PortionFormat; format.FontItalic = NullableBool.True; format.FontHeight = 18; format.FillFormat.FillType = FillTypeEx.Solid; format.FillFormat.SolidFillColor.Color = Color.Black; //Setting Axis values ppChart.ValueAxis.IsAutomaticMaxValue = false; ppChart.ValueAxis.IsAutomaticMinValue = false; ppChart.ValueAxis.IsAutomaticMajorUnit = false; ppChart.ValueAxis.IsAutomaticMinorUnit = false; ppChart.ValueAxis.MaxValue = 4000.0F; ppChart.ValueAxis.MinValue = 0.0F; ppChart.ValueAxis.MajorUnit = 2000.0F; ppChart.ValueAxis.MinorUnit = 1000.0F; ppChart.ValueAxis.TickLabelPosition = TickLabelPositionType.NextTo; //Setting Chart rotation ppChart.Rotation3D.RotationX = 15; ppChart.Rotation3D.RotationY = 20; //Saving Presentation pres.Write("AsposeSampleChart.pptx"); } }
// Get all the text in a slide. public static List <string> GetAllTextInSlide(string presentationFile, int slideIndex) { // Create a new linked list of strings. List <string> texts = new List <string>(); //Instantiate PresentationEx class that represents PPTX using (PresentationEx pres = new PresentationEx(presentationFile)) { //Access the slide SlideEx sld = pres.Slides[slideIndex]; //Iterate through shapes to find the placeholder foreach (ShapeEx shp in sld.Shapes) { if (shp.Placeholder != null) { //get the text of each placeholder texts.Add(((AutoShapeEx)shp).TextFrame.Text); } } } // Return an array of strings. return(texts); }
// Get all the text in a slide. public static List<string> GetAllTextInSlide(string presentationFile, int slideIndex) { // Create a new linked list of strings. List<string> texts = new List<string>(); //Instantiate PresentationEx class that represents PPTX using (PresentationEx pres = new PresentationEx(presentationFile)) { //Access the slide SlideEx sld = pres.Slides[slideIndex]; //Iterate through shapes to find the placeholder foreach (ShapeEx shp in sld.Shapes) if (shp.Placeholder != null) { //get the text of each placeholder texts.Add(((AutoShapeEx)shp).TextFrame.Text); } } // Return an array of strings. return texts; }
// Get a list of the titles of all the slides in the presentation. public static IList <string> GetSlideTitles(string presentationFile) { // Create a new linked list of strings. List <string> texts = new List <string>(); //Instantiate PresentationEx class that represents PPTX using (PresentationEx pres = new PresentationEx(presentationFile)) { //Access all the slides foreach (SlideEx sld in pres.Slides) { //Iterate through shapes to find the placeholder foreach (ShapeEx shp in sld.Shapes) { if (shp.Placeholder != null) { if (IsTitleShape(shp)) { //get the text of placeholder texts.Add(((AutoShapeEx)shp).TextFrame.Text); } } } } } // Return an array of strings. return(texts); }
public static int CountSlides(string presentationFile) { //Instantiate PresentationEx class that represents PPTX using (PresentationEx pres = new PresentationEx(presentationFile)) { return(pres.Slides.Count); } }
public void SlidesCollection_Test() { // Arrange var pre = new PresentationEx(Properties.Resources._017); // Act-Assert var slides = pre.Slides; // should not throws exception }
public static int CountSlides(string presentationFile) { //Instantiate PresentationEx class that represents PPTX using (PresentationEx pres = new PresentationEx(presentationFile)) { return pres.Slides.Count; } }
public static int CountSlides(string presentationFile) { //Instantiate a PresentationEx object that represents a PPTX file using (PresentationEx pres = new PresentationEx(presentationFile)) { return(pres.Slides.Count); } }
public void Slide_Shapes_Test() { // Arrange var pre = new PresentationEx(Properties.Resources._021); // Act-Assert var sld4Shapes = pre.Slides[3].Shapes; }
public void Picture_DoNotParseStrangePicture_Test() { // Arrange var pre = new PresentationEx(Properties.Resources._019); // Act - Assert Assert.ThrowsAny <Exception>(() => pre.Slides[1].Shapes.Single(x => x.Id == 47)); }
public void Slide_Elements_Test() { // ARRANGE var pre = new PresentationEx(Properties.Resources._014); // ACT-ASSERT var elements = pre.Slides[2].Shapes; }
public static void AccessingSlidesOfPresentation() { string MyDir = @"Files\"; //Instantiate a Presentation object that represents a presentation file PresentationEx pres = new PresentationEx(MyDir + "Slides Test Presentation.pptx"); //Accessing a slide using its slide index SlideEx slide = pres.Slides[0]; }
static void Main(string[] args) { string MyDir = @"Files\"; //Instantiate a Presentation object that represents a presentation file PresentationEx pres = new PresentationEx(MyDir + "Conversion.ppt"); //Saving the presentation to TIFF document pres.Save(MyDir + "converted.xps", Aspose.Slides.Export.SaveFormat.Xps); }
static void Main(string[] args) { string MyDir = @"Files\"; //Instantiate a Presentation object that represents a presentation file PresentationEx pres = new PresentationEx(MyDir + "Conversion.ppt"); //Save the presentation to PDF with default options pres.Save(MyDir + "Converted.pdf", Aspose.Slides.Export.SaveFormat.Pdf); }
public static void PrintBySpecificPrinter() { string MyDir = @"Files\"; //Load the presentation PresentationEx asposePresentation = new PresentationEx(MyDir + "Print.pptx"); //Call the print method to print whole presentation to the desired printer asposePresentation.Print("LaserJet1100"); }
public static void PrintByDefaultPrinter() { string MyDir = @"Files\"; //Load the presentation PresentationEx asposePresentation = new PresentationEx(MyDir + "Print.pptx"); //Call the print method to print whole presentation to the default printer asposePresentation.Print(); }
static void Main(string[] args) { string MyDir = @"Files\"; //Instantiate a Presentation object that represents a PPTX file PresentationEx pres = new PresentationEx(MyDir + "Conversion.ppt"); //Saving the PPTX presentation to PPTX format pres.Save(MyDir + "Converted.pptx", SaveFormat.Pptx); }
public static void ConvertedFromOdp() { //Instantiate a Presentation object that represents a presentation file using (PresentationEx pres = new PresentationEx("OpenOfficePresentation.odp")) { //Saving the PPTX presentation to PPTX format pres.Save("ConvertedFromOdp", Aspose.Slides.Export.SaveFormat.Pptx); } }
public static void ConvertedToOdp() { //Instantiate a Presentation object that represents a presentation file using (PresentationEx pres = new PresentationEx("ConversionFromPresentation.pptx")) { //Saving the PPTX presentation to PPTX format pres.Save("ConvertedToOdp", Aspose.Slides.Export.SaveFormat.Odp); } }
static void Main(string[] args) { string MyDir = @"Files\"; //Instantiate a Presentation object that represents a presentation file PresentationEx pres = new PresentationEx(MyDir + "Conversion.pptx"); //Saving the presentation to TIFF notes pres.Save(MyDir + "Converted with Notes.tiff", SaveFormat.TiffNotes); }
public void SlideElementsDoNotThrowsExceptionTest() { // ARRANGE var pre = new PresentationEx(Properties.Resources._009); // ACT var elements = pre.Slides[0].Shapes; pre.Close(); }
public static void ConvertedFromOdp() { //Instantiate a Presentation object that represents a presentation file using(PresentationEx pres = new PresentationEx("OpenOfficePresentation.odp")) { //Saving the PPTX presentation to PPTX format pres.Save("ConvertedFromOdp",Aspose.Slides.Export.SaveFormat.Pptx); } }
private static void AddExcelChartInPresentation(PresentationEx pres, SlideEx sld, Stream wbStream, Bitmap imgChart) { float oleWidth = pres.SlideSize.Size.Width; float oleHeight = pres.SlideSize.Size.Height; int x = 0; byte[] chartOleData = new byte[wbStream.Length]; wbStream.Position = 0; wbStream.Read(chartOleData, 0, chartOleData.Length); OleObjectFrameEx oof = null; oof = sld.Shapes.AddOleObjectFrame(x, 0, oleWidth, oleHeight, "Excel.Sheet.8", chartOleData); oof.Image = pres.Images.AddImage((System.Drawing.Image)imgChart); }
// Move a slide to a different position in the slide order in the presentation. public static void MoveSlide(string presentationFile, int from, int to) { //Instantiate PresentationEx class to load the source PPTX file using (PresentationEx pres = new PresentationEx(presentationFile)) { //Get the slide whose position is to be changed SlideEx sld = pres.Slides[from]; SlideEx sld2 = pres.Slides[to]; //Set the new position for the slide sld2.SlideNumber = from; sld.SlideNumber = to; //Write the PPTX to disk pres.Write(presentationFile); } }
static void Main(string[] args) { //Instantiate the Presentation class that represents the presentation file string mypath = ""; using (PresentationEx pres = new PresentationEx()) { //Set the background color of the Master ISlide to Forest Green pres.Masters[0].Background.Type = BackgroundTypeEx.OwnBackground; pres.Masters[0].Background.FillFormat.FillType = FillTypeEx.Solid; pres.Masters[0].Background.FillFormat.SolidFillColor.Color = Color.ForestGreen; //Write the presentation to disk pres.Save(mypath + "Setting Background Color of Master Slide.pptx", SaveFormat.Pptx); } }
public static string GetSlideText(string docName, int index) { string sldText = ""; //Instantiate PresentationEx class that represents PPTX using (PresentationEx pres = new PresentationEx(docName)) { //Access the slide SlideEx sld = pres.Slides[index]; //Iterate through shapes to find the placeholder foreach (ShapeEx shp in sld.Shapes) if (shp.Placeholder != null) { //get the text of each placeholder sldText += ((AutoShapeEx)shp).TextFrame.Text; } } return sldText; }
static void Main(string[] args) { using (PresentationEx pres = new PresentationEx()) { //Adding Empty slide pres.Slides.AddEmptySlide(pres.LayoutSlides[0]); //Adding Autthor CommentAuthorEx author = pres.CommentAuthors.AddAuthor("Zeeshan", "MZ"); //Position of comments PointF point = new PointF(); point.X = 1; point.Y = 1; //Adding slide comment for an author on slide author.Comments.AddComment("Hello Zeeshan, this is slide comment", pres.Slides[0], point, DateTime.Now); pres.Write("Comments.pptx"); } }
static void RemovingProtection() { string MyDir = @"Files\"; //Open the desired presentation PresentationEx pTemplate = new PresentationEx(MyDir + "ProtectedSample.pptx"); //ISlide object for accessing the slides in the presentation SlideEx slide = pTemplate.Slides[0]; //IShape object for holding temporary shapes ShapeEx shape; //Traversing through all the slides in presentation for (int slideCount = 0; slideCount < pTemplate.Slides.Count; slideCount++) { slide = pTemplate.Slides[slideCount]; //Travesing through all the shapes in the slides for (int count = 0; count < slide.Shapes.Count; count++) { shape = slide.Shapes[count]; //if shape is autoshape if (shape is AutoShapeEx) { //Type casting to Auto shape and getting auto shape lock AutoShapeEx Ashp = shape as AutoShapeEx; AutoShapeLockEx AutoShapeLock = Ashp.ShapeLock; //Applying shapes locks AutoShapeLock.PositionLocked = false; AutoShapeLock.SelectLocked = false; AutoShapeLock.SizeLocked = false; } //if shape is group shape else if (shape is GroupShapeEx) { //Type casting to group shape and getting group shape lock GroupShapeEx Group = shape as GroupShapeEx; GroupShapeLockEx groupShapeLock = Group.ShapeLock; //Applying shapes locks groupShapeLock.GroupingLocked = false; groupShapeLock.PositionLocked = false; groupShapeLock.SelectLocked = false; groupShapeLock.SizeLocked = false; } //if shape is Connector shape else if (shape is ConnectorEx) { //Type casting to connector shape and getting connector shape lock ConnectorEx Conn = shape as ConnectorEx; ConnectorLockEx ConnLock = Conn.ShapeLock; //Applying shapes locks ConnLock.PositionMove = false; ConnLock.SelectLocked = false; ConnLock.SizeLocked = false; } //if shape is picture frame else if (shape is PictureFrameEx) { //Type casting to pitcture frame shape and getting picture frame shape lock PictureFrameEx Pic = shape as PictureFrameEx; PictureFrameLockEx PicLock = Pic.ShapeLock; //Applying shapes locks PicLock.PositionLocked = false; PicLock.SelectLocked = false; PicLock.SizeLocked = false; } } } //Saving the presentation file pTemplate.Save(MyDir+"RemoveProtectionSample.pptx", Aspose.Slides.Export.SaveFormat.Pptx); }
static void Main(string[] args) { string path = @"Files\"; //Accessing the presentation PresentationEx pres = new PresentationEx(path + "RenderImageFromShape.pptx"); ImageEx img = null; int slideIndex = 0; String ImageType = ""; bool ifImageFound = false; for (int i = 0; i < pres.Slides.Count; i++) { slideIndex++; //Accessing the first slide SlideEx sl = pres.Slides[i]; System.Drawing.Imaging.ImageFormat Format = System.Drawing.Imaging.ImageFormat.Jpeg; for (int j = 0; j < sl.Shapes.Count; j++) { // Accessing the shape with picture ShapeEx sh = sl.Shapes[j]; if (sh is AutoShapeEx) { AutoShapeEx ashp = (AutoShapeEx)sh; if (ashp.FillFormat.FillType == FillTypeEx.Picture) { img = ashp.FillFormat.PictureFillFormat.Picture.Image; ImageType = img.ContentType; ImageType = ImageType.Remove(0, ImageType.IndexOf("/") + 1); ifImageFound = true; } } else if (sh is PictureFrameEx) { PictureFrameEx pf = (PictureFrameEx)sh; if (pf.FillFormat.FillType == FillTypeEx.Picture) { img = pf.PictureFormat.Picture.Image; ImageType = img.ContentType; ImageType = ImageType.Remove(0, ImageType.IndexOf("/") + 1); ifImageFound = true; } } // //Setting the desired picture format if (ifImageFound) { switch (ImageType) { case "jpeg": Format = System.Drawing.Imaging.ImageFormat.Jpeg; break; case "emf": Format = System.Drawing.Imaging.ImageFormat.Emf; break; case "bmp": Format = System.Drawing.Imaging.ImageFormat.Bmp; break; case "png": Format = System.Drawing.Imaging.ImageFormat.Png; break; case "wmf": Format = System.Drawing.Imaging.ImageFormat.Wmf; break; case "gif": Format = System.Drawing.Imaging.ImageFormat.Gif; break; } // img.Image.Save(path+"ResultedImage"+"." + ImageType, Format); } ifImageFound = false; } } }