/// <summary> /// Export formatted spotlight picture as a new picture, /// then use the new pic to replace the formatted one. /// Thus when it's displayed, no need to render the effect (which's very slow) /// </summary> /// <param name="spotlightPicture"></param> private void RenderSpotlightPicture(PowerPoint.Shape spotlightPicture) { string dirOfRenderedPicture = Path.GetTempPath() + @"\rendered_" + spotlightPicture.Name; //Render process: //export formatted spotlight picture to a temp folder spotlightPicture.Export(dirOfRenderedPicture, PowerPoint.PpShapeFormat.ppShapeFormatPNG); //then add the exported new picture back var renderedPicture = PowerPointCurrentPresentationInfo.CurrentSlide.Shapes.AddPicture( dirOfRenderedPicture, Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue, spotlightPicture.Left, spotlightPicture.Top, spotlightPicture.Width, spotlightPicture.Height); renderedPicture.Name = spotlightPicture.Name + "_rendered"; spotlightPicture.Delete(); }
/// <summary> /// Create a slide model from a powerpoint slide /// </summary> /// <param name="pageSetup"></param> /// <param name="pptpm"></param> /// <param name="deck"></param> /// <param name="tempFileCollection"></param> /// <param name="dirpath"></param> /// <param name="currentSlide"></param> /// <returns></returns> private static SlideModel CreateSlide(PowerPoint.PageSetup pageSetup, PPTPaneManagement.PPTPaneManager pptpm, DeckModel deck, TempFileCollection tempFileCollection, string dirpath, PowerPoint._Slide currentSlide) { int slideWidth = (int)pageSetup.SlideWidth; //Standard = 720 => 6000 int slideHeight = (int)pageSetup.SlideHeight; //Standard = 540 => 4500 float emfWidth = slideWidth * 25 / 3; float emfHeight = slideHeight * 25 / 3; // Adding an empty textbox in the upper left corner of the the // slide before layers are exported works around a common // issue with shape positioning. Without this, text shapes often get pushed too far // to the right and down due to some extra padding that PPT inserts on // the top and left of the exported images. It doesn't pad the top left of an // empty text box, so the positioning is corrected. // This isn't perfect since the workaround should probably be applied to // every layer with text boxes. currentSlide.Shapes.AddTextbox(Core.MsoTextOrientation.msoTextOrientationHorizontal, 0, 0, 1, 1); PowerPoint.Shapes currentShapes = currentSlide.Shapes; List<TaggedShape> taggedShapeList = PPTDeckIO.BuildTaggedShapeList(currentShapes, pptpm); //Create a new SlideModel SlideModel newSlideModel = new SlideModel(Guid.NewGuid(), new LocalId(), SlideDisposition.Empty, new Rectangle(0, 0, slideWidth, slideHeight)); //Lock it using (Synchronizer.Lock(newSlideModel.SyncRoot)) { //Set the slide's title newSlideModel.Title = PPTDeckIO.FindSlideTitle(taggedShapeList, currentSlide); PPTDeckIO.MakeShapesInvisible(currentShapes); //Create the Background image //Generate a new filename string filename = PPTDeckIO.GenerateFilename(); bool bitmapMode = true; if (bitmapMode) { filename = dirpath + "\\" + filename + ".png"; currentSlide.Export(filename, "PNG", 0, 0); // Need to also export as EMF to get the size of the slide in inches currentSlide.Export(filename + "_TEMP", "EMF", 0, 0); tempFileCollection.AddFile( filename + "_TEMP", false ); } else { filename = dirpath + "\\" + filename + ".emf"; currentSlide.Export(filename, "EMF", 0, 0); } tempFileCollection.AddFile(filename, false); //Compute the MD5 of the BG FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read); MD5 md5Provider = new MD5CryptoServiceProvider(); byte[] md5 = md5Provider.ComputeHash(fs); fs.Seek(0, SeekOrigin.Begin); Image image = Image.FromStream(fs); if (bitmapMode) { image = DisassociateBitmap(image); } fs.Close(); // Open the EMF version if we used a bitmap to get the conversion if( bitmapMode ) { FileStream fsEMF = new FileStream( filename + "_TEMP", FileMode.Open, FileAccess.Read ); Image image_emf = Image.FromStream( fsEMF ); emfWidth = image_emf.Width; emfHeight = image_emf.Height; fsEMF.Close(); image_emf.Dispose(); } else { emfWidth = image.Width; emfHeight = image.Height; } //Create the ImageSheet ImageSheetModel sheet = new ImageSheetModel(deck, Guid.NewGuid(), Model.Presentation.SheetDisposition.Background, new Rectangle(0, 0, slideWidth, slideHeight), (ByteArray)md5, 1); //Add the ImageSheet to the Slide newSlideModel.ContentSheets.Add(sheet); //Add the Image+MD5 to the deck deck.AddSlideContent((ByteArray)md5, image); // Restore visibility - this makes everything visible - a bug? PPTDeckIO.MakeShapesVisible(currentShapes); List<List<TaggedShape>> layerList = PPTDeckIO.SeparateIntoLayers(taggedShapeList); int startHeight = 2; foreach (List<TaggedShape> layer in layerList) PPTDeckIO.ProcessLayer( layer, tempFileCollection, currentShapes, deck, newSlideModel, slideWidth/emfWidth, slideHeight/emfHeight, startHeight++ ); //Add SlideModel to the deck deck.InsertSlide(newSlideModel); } return newSlideModel; }
/// <summary> /// Create a slide model from a powerpoint slide /// </summary> /// <param name="pageSetup"></param> /// <param name="pptpm"></param> /// <param name="deck"></param> /// <param name="tempFileCollection"></param> /// <param name="dirpath"></param> /// <param name="currentSlide"></param> /// <returns></returns> private static SlideModel CreateSlide(PowerPoint.PageSetup pageSetup, PPTPaneManagement.PPTPaneManager pptpm, DeckModel deck, TempFileCollection tempFileCollection, string dirpath, PowerPoint._Slide currentSlide) { int slideWidth = (int)pageSetup.SlideWidth; //Standard = 720 => 6000 int slideHeight = (int)pageSetup.SlideHeight; //Standard = 540 => 4500 float emfWidth = slideWidth * 25 / 3; float emfHeight = slideHeight * 25 / 3; PowerPoint.Shapes currentShapes = currentSlide.Shapes; List<TaggedShape> taggedShapeList = PPTDeckIO.BuildTaggedShapeList(currentShapes, pptpm); //Create a new SlideModel SlideModel newSlideModel = new SlideModel(Guid.NewGuid(), new LocalId(), SlideDisposition.Empty, new Rectangle(0, 0, slideWidth, slideHeight)); //Lock it using (Synchronizer.Lock(newSlideModel.SyncRoot)) { //Set the slide's title newSlideModel.Title = PPTDeckIO.FindSlideTitle(taggedShapeList); PPTDeckIO.MakeShapesInvisible(currentShapes); //Create the Background image //Generate a new filename string filename = PPTDeckIO.GenerateFilename(); bool bitmapMode = true; if (bitmapMode) { filename = dirpath + "\\" + filename + ".JPG"; currentSlide.Export(filename, "JPG", 0, 0); // Need to also export as EMF to get the size of the slide in inches currentSlide.Export(filename + "_TEMP", "EMF", 0, 0); tempFileCollection.AddFile( filename + "_TEMP", false ); } else { filename = dirpath + "\\" + filename + ".emf"; currentSlide.Export(filename, "EMF", 0, 0); } tempFileCollection.AddFile(filename, false); //Compute the MD5 of the BG FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read); MD5 md5Provider = new MD5CryptoServiceProvider(); byte[] md5 = md5Provider.ComputeHash(fs); fs.Seek(0, SeekOrigin.Begin); Image image = Image.FromStream(fs); if (bitmapMode) { image = DisassociateBitmap(image); } fs.Close(); // Open the EMF version if we used a bitmap to get the conversion if( bitmapMode ) { FileStream fsEMF = new FileStream( filename + "_TEMP", FileMode.Open, FileAccess.Read ); Image image_emf = Image.FromStream( fsEMF ); emfWidth = image_emf.Width; emfHeight = image_emf.Height; fsEMF.Close(); image_emf.Dispose(); } else { emfWidth = image.Width; emfHeight = image.Height; } //Create the ImageSheet ImageSheetModel sheet = new ImageSheetModel(deck, Guid.NewGuid(), Model.Presentation.SheetDisposition.Background, new Rectangle(0, 0, slideWidth, slideHeight), (ByteArray)md5, 1); //Add the ImageSheet to the Slide newSlideModel.ContentSheets.Add(sheet); //Add the Image+MD5 to the deck deck.AddSlideContent((ByteArray)md5, image); // Restore visibility - this makes everything visible - a bug? PPTDeckIO.MakeShapesVisible(currentShapes); List<List<TaggedShape>> layerList = PPTDeckIO.SeparateIntoLayers(taggedShapeList); int startHeight = 2; foreach (List<TaggedShape> layer in layerList) PPTDeckIO.ProcessLayer( layer, tempFileCollection, currentShapes, deck, newSlideModel, slideWidth/emfWidth, slideHeight/emfHeight, startHeight++ ); //Add SlideModel to the deck deck.InsertSlide(newSlideModel); } return newSlideModel; }
private Image ConstructSlideImage(PowerPoint._Slide ppSlide, string imageFileName, string imageFormatString, int imageWidth, int imageHeight, ref int errorCount) { // Converting slide formats is done through exporting to a file and reading in ppSlide.Export(imageFileName, imageFormatString, imageWidth, imageHeight); Image image = Image.FromFile(imageFileName); long size1 = ImageSize(image); if (size1 <= SlideSizeCutoff(this.MaximumImageSize)) return image; // Bitmap was too big, so let's make a low res version errorCount++; Size compressedSize = CompressedImageSize(this.MaximumImageSize, imageWidth, imageHeight); ppSlide.Export(imageFileName + "x.png", ".png", compressedSize.Width, compressedSize.Height); Bitmap bitmap2 = new Bitmap(imageFileName + "x.png"); long size2 = ImageSize(bitmap2); return bitmap2; }
/// <summary> /// Export a slide to the specified image format /// </summary> /// <param name="slide">PPT.Slide object instance</param> /// <param name="filePathAndName">File and Path name for the export target</param> /// <param name="exportFormat">Format to export to</param> /// <param name="scaleWidth">Scale with of the image</param> /// <param name="scaleHeight">Scale height of the image</param> public void Export( PPT.Slide slide, string filePathAndName, ImageFormats.Formats exportFormat, int scaleWidth = 1280, int scaleHeight = 1024) { slide.Export(filePathAndName, exportFormat.ToString(), scaleWidth, scaleHeight); }