Example #1
0
        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;
                }
            }
        }
        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);
        }