Example #1
0
        protected override IEnumerable <DestinationFile> ConvertApplicableImageThenSave(
            SourceFile source,
            ImageFileKind destinationKind,
            ArgumentOptionCollection optionCollection,
            ILogger logger)
        {
            var savedImageFiles = new List <DestinationFile>();

            try
            {
                using (var powerPointApplication = new PowerPointApplication(new Application()))
                {
                    var application  = powerPointApplication.Application;
                    var presentation = application.Presentations;
                    using (var presenationFile = new PowerPointPresentation(presentation.Open(
                                                                                FileName: source.Path,
                                                                                ReadOnly: MsoTriState.msoTrue,
                                                                                Untitled: MsoTriState.msoTrue,
                                                                                WithWindow: MsoTriState.msoTrue)))
                    {
                        var file = presenationFile.Presentation;
                        foreach (var slide in EnumeratePowerPointSlides(file))
                        {
                            if (!optionCollection.PowerpointPageRange.Contains((uint)slide.SlideNumber))
                            {
                                continue;
                            }
                            slide.Select();
                            slide.Shapes.SelectAll();
                            var selection = application.ActiveWindow.Selection;
                            var shapes    = selection.ShapeRange;

                            var destinationPathForSlide = $"{Path.GetDirectoryName(source.Path)}\\{Path.GetFileNameWithoutExtension(source.Path)}{slide.SlideNumber}{destinationKind.GetExtensionWithDot()}";
                            var destinationForSlide     = new DestinationFile(destinationPathForSlide);
                            if (!DeleteExistingFileIfNecessary(destinationForSlide, optionCollection, logger))
                            {
                                continue;
                            }

                            //create emf
                            shapes.Export(destinationForSlide.Path, PpShapeFormat.ppShapeFormatEMF);
                            savedImageFiles.Add(destinationForSlide);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                logger.WriteLog($"Failed to convert powerpoint slide to emf images: {e.Message}\n{e.StackTrace}", LogLevel.Error);
            }

            return(savedImageFiles);
        }
Example #2
0
 public void close()
 {
     if (PowerPointPresentation != null)
     {
         PowerPointPresentation.Close();
     }
     PowerPointPresentation = null;
     if (PowerPointApplication == null)
     {
         return;
     }
     if (PowerPointApplication.Presentations.Count == 0)
     {
         PowerPointApplication.Quit();
     }
     PowerPointApplication = null;
 }