public void FindSlides() { const string file = "../../files/GetNotes.pptx"; Pptx pptx = new Pptx(file, FileAccess.Read); int nbSlides = pptx.SlidesCount(); Assert.AreEqual(4, nbSlides); { IEnumerable<PptxSlide> slides = pptx.FindSlides("{{comment1}}"); Assert.AreEqual(1, slides.Count()); } { IEnumerable<PptxSlide> slides = pptx.FindSlides("{{comment2}}"); Assert.AreEqual(1, slides.Count()); } { IEnumerable<PptxSlide> slides = pptx.FindSlides("{{comment3}}"); Assert.AreEqual(1, slides.Count()); } pptx.Close(); }
public void ReplaceLotsOfPicturesAndSlides() { const string srcFileName = "../../files/ReplaceLotsOfPicturesAndSlides.pptx"; const string dstFileName = "../../files/ReplaceLotsOfPicturesAndSlides_output.pptx"; File.Delete(dstFileName); File.Copy(srcFileName, dstFileName); Pptx pptx = new Pptx(dstFileName, FileAccess.ReadWrite); const string picture1_replace_png = "../../files/picture1_replace.png"; const string picture1_replace_png_contentType = "image/png"; const string picture1_replace_bmp = "../../files/picture1_replace.bmp"; const string picture1_replace_bmp_contentType = "image/bmp"; const string picture1_replace_jpeg = "../../files/picture1_replace.jpeg"; const string picture1_replace_jpeg_contentType = "image/jpeg"; byte[] picture1_replace_empty = new byte[] { }; PptxSlide slideTemplate = pptx.FindSlides("{{LotsOfPictures}}").FirstOrDefault(); int nbSlidesToGenerate = 100; for (int i = 0; i < nbSlidesToGenerate; i++) { PptxSlide slide = slideTemplate.Clone(); PptxSlide.InsertAfter(slide, slideTemplate); slide.ReplacePicture("{{picture1png}}", picture1_replace_png, picture1_replace_png_contentType); slide.ReplacePicture("{{picture1bmp}}", picture1_replace_bmp, picture1_replace_bmp_contentType); slide.ReplacePicture("{{picture1jpeg}}", picture1_replace_jpeg, picture1_replace_jpeg_contentType); slide.ReplacePicture(null, picture1_replace_png, picture1_replace_png_contentType); slide.ReplacePicture("{{picture1null}}", picture1_replace_empty, picture1_replace_png_contentType); slide.ReplacePicture("{{picture1null}}", picture1_replace_png, null); slide.ReplacePicture("{{picture1null}}", picture1_replace_empty, null); } slideTemplate.Remove(); pptx.Close(); // Sorry, you will have to manually check that the pictures have been replaced }