static void Main(string[] args)
        {
            PPTLibrary.PPT ppt = new PPTLibrary.PPT();

            PPTPaneManager manager = new PPTPaneManager(ppt);
            manager.ShapeMarker = new DefaultShapeMarker(); // Not currently working b/c of PPT Shadow.Visible bug (demonstrated by HandleTestWSC above and: create two objects, select them, group them, ungroup them, unselect them, select one of them.

            ppt.App.Activate();
            Console.ReadLine();
        }
Beispiel #2
0
        private static void AddTaggedShapeToList(List <TaggedShape> tsList, ref int index, PowerPoint.Shape shape, PPTPaneManagement.PPTPaneManager pptpm)
        {
            TaggedShape ts;

            ts.shape = shape;
            ts.index = index;
            index++;
            ts.isImage = (shape.Name.StartsWith("Picture"));        // A shape is an image if its called a picture!
            string[] modes = pptpm.GetModes(shape);

            if (modes.Length == 0)
            {
                ts.disp = SheetDisposition.All;
                tsList.Add(ts);
            }
            else
            {
                foreach (string mode in modes)
                {
                    ts.disp = PPTDeckIO.Disposition(mode);            // Make a copy for each mode, and add to the list
                    tsList.Add(ts);
                }
            }
        }
Beispiel #3
0
        //TODO: Image type needs to be more dynamically chosen...
        public static DeckModel OpenPPT(FileInfo file, BackgroundWorker worker, DoWorkEventArgs progress)
        {
            //Start the progress bar
            if (worker != null)
            {
                worker.ReportProgress(0, "Initializing...");
            }

            //Make the default flat tree representation of the PPT
            //Try to detect if powerpoint is already running (powerpnt.exe)
            bool pptAlreadyRunning = false;

            Process[] processes = Process.GetProcesses();
            for (int i = 0; i < processes.Length; i++)
            {
                string currentProcess = processes[i].ProcessName.ToLower();
                if (currentProcess == "powerpnt")
                {
                    pptAlreadyRunning = true;
                    break;
                }
            }
            //Open PowerPoint + open file
            PowerPoint.Application pptapp;
            try {
                pptapp = new PowerPoint.Application();
            }
            catch (Exception e) {
                throw new PPTNotInstalledException("Failed to create PowerPoint Application.  See InnerException for details.", e);
            }

            PowerPoint._Presentation presentation;
            try {
                presentation = pptapp.Presentations.Open(file.FullName, Core.MsoTriState.msoTrue, Core.MsoTriState.msoFalse, Core.MsoTriState.msoFalse);
            }
            catch (Exception e) {
                throw new PPTFileOpenException("Failed to open PowerPoint file.  See InnerException for details.", e);
            }

            //Initialize the PPT Shape tag reader
            PPTPaneManagement.PPTPaneManager pptpm = new PPTPaneManagement.PPTPaneManager();
            //Create a new DeckModel

            DeckModel deck = new DeckModel(Guid.NewGuid(), DeckDisposition.Empty, file.Name);

            //Initialize a temporary file collection that will be where slide images are exported to
            TempFileCollection tempFileCollection = new TempFileCollection();
            string             dirpath            = tempFileCollection.BasePath;

            if (!Directory.Exists(dirpath))
            {
                Directory.CreateDirectory(dirpath);
            }
            else
            {
                Directory.Delete(dirpath, true);
                Directory.CreateDirectory(dirpath);
            }

            //Lock it
            using (Synchronizer.Lock(deck.SyncRoot)) {
                //Iterate over all slides
                for (int i = 1; i <= presentation.Slides.Count; i++)
                {
                    if (progress != null && progress.Cancel)
                    {
                        break;
                    }

                    //Get the slide
                    PowerPoint._Slide currentSlide = presentation.Slides[i];



                    SlideModel newSlideModel = CreateSlide(presentation.PageSetup, pptpm, deck, tempFileCollection, dirpath, currentSlide);

                    //Create a new Entry + reference SlideModel
                    TableOfContentsModel.Entry newEntry = new TableOfContentsModel.Entry(Guid.NewGuid(), deck.TableOfContents, newSlideModel);
                    //Lock the TOC
                    using (Synchronizer.Lock(deck.TableOfContents.SyncRoot)) {
                        //Add Entry to TOC
                        deck.TableOfContents.Entries.Add(newEntry);
                    }
                    //Increment the ProgressBarForm
                    if (worker != null)
                    {
                        worker.ReportProgress((i * 100) / presentation.Slides.Count, "Reading slide " + i + " of " + presentation.Slides.Count);
                    }
                }
            }
            //Close the presentation
            presentation.Close();
            presentation = null;
            //If PowerPoint was not open before, close PowerPoint
            if (!pptAlreadyRunning)
            {
                pptapp.Quit();
                pptapp = null;
            }
            GC.Collect();
            //Delete temp directory
            tempFileCollection.Delete();
            Directory.Delete(dirpath);

            if (worker != null)
            {
                worker.ReportProgress(100, "Done!");
            }

            //Return the deck
            if (progress != null)
            {
                progress.Result = deck;
            }
            return(deck);
        }
Beispiel #4
0
        /// <summary>
        /// Tag all the shapes with their visibility mode, index, and whether or not they are a picture
        /// </summary>
        /// <param name="shapes"></param>
        /// <param name="pptpm"></param>
        /// <returns></returns>
        private static List <TaggedShape> BuildTaggedShapeList(PowerPoint.Shapes shapes, PPTPaneManagement.PPTPaneManager pptpm)
        {
            List <TaggedShape> tsList = new List <TaggedShape>();
            int index = 1;

            for (int i = 1; i <= shapes.Count; i++)
            {
                PowerPoint.Shape shape = shapes[i];

                if (shape.Type == Microsoft.Office.Core.MsoShapeType.msoGroup)
                {
                    shape.Ungroup();
                    i--;
                    continue;
                }
                else
                {
                    AddTaggedShapeToList(tsList, ref index, shape, pptpm);
                }
            }

            return(tsList);
        }
Beispiel #5
0
        /// <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);
        }
Beispiel #6
0
        //TODO: Image type needs to be more dynamically chosen...
        public static DeckModel OpenPPT(FileInfo file, BackgroundWorker worker, DoWorkEventArgs progress)
        {
            //Start the progress bar
            if (worker != null) {
                worker.ReportProgress(0, "  Initializing...");
            }

            //Make the default flat tree representation of the PPT
            //Try to detect if powerpoint is already running (powerpnt.exe)
            bool pptAlreadyRunning = false;
            Process[] processes = Process.GetProcesses();
            for (int i = 0; i < processes.Length; i++) {
                string currentProcess = processes[i].ProcessName.ToLower();
                if (currentProcess == "powerpnt") {
                    pptAlreadyRunning = true;
                    break;
                }
            }
            //Open PowerPoint + open file
            PowerPoint.Application pptapp = null;
            try {
                pptapp = new PowerPoint.Application();
            }
            catch (Exception e) {
                throw new PPTNotInstalledException("Failed to create PowerPoint Application.  See InnerException for details.", e);
            }

            PowerPoint._Presentation presentation;
            try {
                presentation = pptapp.Presentations.Open(file.FullName, Core.MsoTriState.msoTrue, Core.MsoTriState.msoFalse, Core.MsoTriState.msoFalse);
            }
            catch (Exception e) {
                throw new PPTFileOpenException("Failed to open PowerPoint file.  See InnerException for details.", e);
            }

            //Initialize the PPT Shape tag reader
            PPTPaneManagement.PPTPaneManager pptpm = new PPTPaneManagement.PPTPaneManager();
            //Create a new DeckModel

            Guid deckGuid = Guid.Empty;
            try {
                string g = presentation.Tags["WEBEXPORTGUID"];
                if (g == "") {
                    deckGuid = Guid.NewGuid();
                }
                else {
                    deckGuid = new Guid(g);
                }
            }
            catch {
                deckGuid = Guid.NewGuid();
            }

            DeckModel deck = new DeckModel(deckGuid, DeckDisposition.Empty, file.Name);

            //Initialize a temporary file collection that will be where slide images are exported to
            TempFileCollection tempFileCollection = new TempFileCollection();
            string dirpath = tempFileCollection.BasePath;
            if (!Directory.Exists(dirpath)) {
                Directory.CreateDirectory(dirpath);
            } else {
                Directory.Delete(dirpath, true);
                Directory.CreateDirectory(dirpath);
            }

            //Lock it
            using(Synchronizer.Lock(deck.SyncRoot)) {
                //Iterate over all slides
                for (int i = 1;  i <= presentation.Slides.Count; i++) {
                    if (progress != null && progress.Cancel)
                        break;

                    //Get the slide
                    PowerPoint._Slide currentSlide= presentation.Slides[i];

                    if (currentSlide.SlideShowTransition.Hidden == Core.MsoTriState.msoTrue)
                        continue;

                    SlideModel newSlideModel = CreateSlide(presentation.PageSetup, pptpm, deck, tempFileCollection, dirpath, currentSlide);

                    //Create a new Entry + reference SlideModel
                    TableOfContentsModel.Entry newEntry = new TableOfContentsModel.Entry(Guid.NewGuid(), deck.TableOfContents, newSlideModel);
                    //Lock the TOC
                    using(Synchronizer.Lock(deck.TableOfContents.SyncRoot)) {
                        //Add Entry to TOC
                        deck.TableOfContents.Entries.Add(newEntry);
                    }
                    //Increment the ProgressBarForm
                    if (worker != null) {
                        worker.ReportProgress((i * 100) / presentation.Slides.Count, "  Reading slide " + i + " of " + presentation.Slides.Count);
                    }
                }
            }
            //Close the presentation
            presentation.Close();
            presentation = null;
            //If PowerPoint was not open before, close PowerPoint
            if (!pptAlreadyRunning) {
                pptapp.Quit();
                pptapp = null;
            }
            GC.Collect();
            //Delete temp directory
            tempFileCollection.Delete();
            Directory.Delete(dirpath);

            if (worker != null)
                worker.ReportProgress(100, " Done!");

            //Return the deck
            if (progress != null)
                progress.Result = deck;
            return deck;
        }
		/// <param name="ppt">non-null ppt library accessor</param>
		/// <param name="paneManager">pane manager or null if no pane management is to be used</param>
		public PPTSlideLoader(Size viewerSize, int commentMenuType, PPTLibrary.PPT ppt, PPTPaneManagement.PPTPaneManager paneManager) 
#endif
		{
			if (ppt == null) throw new ArgumentNullException("ppt");

			this.myPPT = ppt;
			this.myPaneManager = paneManager;
#if SIP_MODE
			this.myPropertyManager = propertyManager;
#endif

			this.myViewerSize = viewerSize;
			this.myDefaultCommentMenuType = commentMenuType;

			this.myFilesLoaded = 0;

			this.myTemporaryDirectoryPath =  Path.GetTempPath() + "\\DeckBuilderTempFiles";
			try 
			{
				if (Directory.Exists(this.myTemporaryDirectoryPath))
					Directory.Delete(this.myTemporaryDirectoryPath, true);		// Delete directory to clean up old files
				Directory.CreateDirectory(this.myTemporaryDirectoryPath);

			}
			catch (IOException e)
			{
				Console.WriteLine(e.Message);
			}

		}
		/// <param name="ppt">non-null ppt library accessor</param>
		/// <param name="paneManager">pane manager or null if no pane management is to be used</param>
		/// <param name="propertyManager">widget property manager or null if the loader should assume no widgets exist</param>
		public PPTSlideLoader(Size viewerSize, int commentMenuType, PPTLibrary.PPT ppt, 
			PPTPaneManager paneManager, PPTPropertyManager propertyManager)