public static void Run()
        {
            //ExStart:CloneAnotherPresentationAtSpecifiedPosition
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Slides_Presentations_CRUD();

            // ExStart:CloneAnotherPresentationAtSpecifiedPosition
            // Instantiate Presentation class to load the source presentation file
            using (Presentation sourcePresentation = new Presentation(dataDir + "AccessSlides.pptx"))
            {
                // Instantiate Presentation class for destination presentation (where slide is to be cloned)
                using (Presentation destPres = new Presentation())
                {
                    // Clone the desired slide from the source presentation to the end of the collection of slides in destination presentation
                    ISlideCollection slideCollection = destPres.Slides;

                    // Clone the desired slide from the source presentation to the specified position in destination presentation
                    slideCollection.InsertClone(1, sourcePresentation.Slides[1]);

                    // ExEnd:CloneAnotherPresentationAtSpecifiedPosition
                    // Write the destination presentation to disk
                    destPres.Save(dataDir + "CloneAnotherPresentationAtSpecifiedPosition_out.pptx", SaveFormat.Pptx);
                }
            }
            //ExEnd:CloneAnotherPresentationAtSpecifiedPosition
        }
Example #2
0
        private void NewPPT()
        {
            Presentation     mPresentation = new Presentation(AppDomain.CurrentDomain.BaseDirectory + @"File\PPTX\20170703作业方案.ppt");
            ISlideCollection mSlideCollection = mPresentation.Slides;
            Slide            mSlide, mCopySlide;
            IShapeCollection mShapeCollection;
            IShape           mShape;

            for (int i = mSlideCollection.Count - 1; i > -1; i--)
            {
                mSlide = mSlideCollection[i] as Slide;
                if (mSlide.Name.Contains("TCZPage"))
                {
                    mCopySlide       = mPresentation.Slides.InsertClone(i, mSlide) as Slide;
                    mShapeCollection = mCopySlide.Shapes;
                    for (int j = mShapeCollection.Count - 1; j > -1; j--)
                    {
                        mShape = mShapeCollection[j] as Aspose.Slides.Shape;
                        if (mShape.Name == "GroupName")
                        {
                            if (mShape.GetType() == typeof(AutoShape))
                            {
                                ((AutoShape)mShape).Height         = 2 * ((AutoShape)mShape).Height;
                                ((AutoShape)mShape).TextFrame.Text = "克隆小组大家阿斯顿浪费净资产阿斯顿法律金钱啊我饿杰拉德";
                            }
                        }
                    }
                }
            }
            mPresentation.Save(AppDomain.CurrentDomain.BaseDirectory + @"File\PPTX\123456作业方案.ppt", Aspose.Slides.Export.SaveFormat.Pptx);
        }
        public static void ApplyThemeToPresentation(string presentationFile, string outputFile)
        {
            //Instantiate Presentation class to load the source presentation file
            Presentation srcPres = new Presentation(presentationFile);

            //Instantiate Presentation class for destination presentation (where slide is to be cloned)
            Presentation destPres = new Presentation(outputFile);

            //Instantiate ISlide from the collection of slides in source presentation along with
            //master slide
            ISlide SourceSlide = srcPres.Slides[0];

            //Clone the desired master slide from the source presentation to the collection of masters in the
            //destination presentation
            IMasterSlideCollection masters      = destPres.Masters;
            IMasterSlide           SourceMaster = SourceSlide.LayoutSlide.MasterSlide;

            //Clone the desired master slide from the source presentation to the collection of masters in the
            //destination presentation
            IMasterSlide iSlide = masters.AddClone(SourceMaster);

            //Clone the desired slide from the source presentation with the desired master to the end of the
            //collection of slides in the destination presentation
            ISlideCollection slds = destPres.Slides;

            slds.AddClone(SourceSlide, iSlide, true);

            //Clone the desired master slide from the source presentation to the collection of masters in the//destination presentation
            //Save the destination presentation to disk
            destPres.Save(outputFile, SaveFormat.Pptx);
        }
Example #4
0
        /// <summary>
        /// 合并ppt:依次合并files中的ppt文件
        /// </summary>
        /// <param name="files">要合并的文件名列表</param>
        /// <param name="desPPT">合并后的文件名</param>
        private void MergePPT(List <string> files, ref string desPPT)
        {
            using (Presentation destPres = new Presentation(dataDir + files[0]))
            {
                for (int i = 1; i < files.Count; i++)
                {
                    using (Presentation srcPres = new Presentation(dataDir + files[i]))
                    {
                        //Instantiate ISlide from the collection of slides in source presentation along with
                        //master slide
                        ISlide       SourceSlide  = srcPres.Slides[0];
                        IMasterSlide SourceMaster = SourceSlide.LayoutSlide.MasterSlide;

                        //Clone the desired master slide from the source presentation to the collection of masters in the
                        //destination presentation
                        IMasterSlideCollection masters    = destPres.Masters;
                        IMasterSlide           DestMaster = SourceSlide.LayoutSlide.MasterSlide;

                        //Clone the desired master slide from the source presentation to the collection of masters in the
                        //destination presentation
                        IMasterSlide iSlide = masters.AddClone(SourceMaster);

                        //Clone the desired slide from the source presentation with the desired master to the end of the
                        //collection of slides in the destination presentation
                        ISlideCollection slds = destPres.Slides;
                        slds.AddClone(SourceSlide, iSlide, true);
                        //Clone the desired master slide from the source presentation to the collection of masters in the //destination presentation
                        //Save the destination presentation to disk
                    }
                }
                //destPres.Slides[0].Remove();
                desPPT = DateTime.Now.ToString("yyyyMMddhhmmsss") + ".ppt";
                destPres.Save(dataDir + desPPT, SaveFormat.Ppt);
            }
        }
        public static void Run()
        {
            //ExStart:AddSlides
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Slides_Presentations_CRUD();

            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);

            if (!IsExists)
            {
                System.IO.Directory.CreateDirectory(dataDir);
            }

            // Instantiate Presentation class that represents the presentation file
            using (Presentation pres = new Presentation())
            {
                // Instantiate SlideCollection calss
                ISlideCollection slds = pres.Slides;

                for (int i = 0; i < pres.LayoutSlides.Count; i++)
                {
                    // Add an empty slide to the Slides collection
                    slds.AddEmptySlide(pres.LayoutSlides[i]);
                }

                // Save the PPTX file to the Disk
                pres.Save(dataDir + "EmptySlide_out.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
            }
            //ExEnd:AddSlides
        }
Example #6
0
        private static void GenerateVideoFromAspose(string sourcePath, string extension)
        {
            var pptPresentation     = new Aspose.Slides.Presentation();
            ISlideCollection slides = pptPresentation.Slides;

            var dirInfo     = new DirectoryInfo(sourcePath);
            var jpgFileList = new List <string>();

            if (dirInfo.Exists)
            {
                jpgFileList.AddRange(dirInfo.GetFiles().Where(f => f.Extension.Equals(extension)).OrderBy(f => f.LastWriteTime).Take(3).Select(fileToUpload => sourcePath + "\\" + fileToUpload.Name));
            }

            //Aspose.Slides.Slide slide;
            for (int i = 0; i < jpgFileList.Count; i++)
            {
                var slide = slides.AddEmptySlide(pptPresentation.LayoutSlides[i + 1]);
                //Set the background with Image
                slide.Background.Type = BackgroundType.OwnBackground;
                slide.Background.FillFormat.FillType = FillType.Picture;
                slide.Background.FillFormat.PictureFillFormat.PictureFillMode = PictureFillMode.Stretch;

                //Set the picture
                var img = (System.Drawing.Image) new Bitmap(jpgFileList[i]);

                //Add image to presentation's images collection
                IPPImage imgx = pptPresentation.Images.AddImage(img);

                slide.Background.FillFormat.PictureFillFormat.Picture.Image = imgx;
            }

            //Save the PPTX file to the Disk
            pptPresentation.Save(sourcePath + "\\EmptySlide.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
        }
        public static void CreatePresentation(string filepath)
        {
            //Instantiate a Presentation object that represents a PPT file
            using (Presentation pres = new Presentation())
            {
                //Instantiate SlideExCollection calss
                ISlideCollection slds = pres.Slides;

                //Add an empty slide to the SlidesEx collection
                slds.AddEmptySlide(pres.LayoutSlides[0]);

                //Save your presentation to a file
                pres.Save(filepath, Aspose.Slides.Export.SaveFormat.Pptx);
            }
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Slides_Presentations_CRUD();

            // Instantiate Presentation class that represents a presentation file
            using (Presentation pres = new Presentation(dataDir + "CloneWithinSamePresentationToEnd.pptx"))
            {
                // Clone the desired slide to the end of the collection of slides in the same presentation
                ISlideCollection slds = pres.Slides;

                slds.AddClone(pres.Slides[0]);

                // Write the modified presentation to disk
                pres.Save(dataDir + "Aspose_CloneWithinSamePresentationToEnd_out.pptx", SaveFormat.Pptx);
            }
        }
        public static void AddingSlidetoPresentation()
        {
            Presentation pres = new Presentation();

            //Instantiate SlideCollection class

            ISlideCollection slds = pres.Slides;

            for (int i = 0; i < pres.LayoutSlides.Count; i++)
            {
                //Add an empty slide to the Slides collection
                slds.AddEmptySlide(pres.LayoutSlides[i]);
            }

            //Save the PPTX file to the Disk
            pres.Save(MyDir + "Assemble Slides.pptx", SaveFormat.Pptx);
        }
Example #10
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Slides_Presentations();

            //Instantiate Presentation class that represents a presentation file
            using (Presentation pres = new Presentation(dataDir + "CloneWithInSamePresentation.pptx"))
            {
                //Clone the desired slide to the end of the collection of slides in the same presentation
                ISlideCollection slds = pres.Slides;

                //Clone the desired slide to the specified index in the same presentation
                slds.InsertClone(2, pres.Slides[1]);

                //Write the modified presentation to disk
                pres.Save(dataDir + "Aspose_clone.pptx", SaveFormat.Pptx);
            }
        }
Example #11
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Slides_Presentations_CRUD();

            // Instantiate Presentation class to load the source presentation file
            using (Presentation srcPres = new Presentation(dataDir + "CloneAtEndOfAnother.pptx"))
            {
                // Instantiate Presentation class for destination PPTX (where slide is to be cloned)
                using (Presentation destPres = new Presentation())
                {
                    // Clone the desired slide from the source presentation to the end of the collection of slides in destination presentation
                    ISlideCollection slds = destPres.Slides;

                    slds.AddClone(srcPres.Slides[0]);

                    // Write the destination presentation to disk
                    destPres.Save(dataDir + "Aspose2_out.pptx", SaveFormat.Pptx);
                }
            }
        }
Example #12
0
        public static void Run()
        {
            //ExStart:CloneToAnotherPresentationWithMaster
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Slides_Presentations_CRUD();

            // Instantiate Presentation class to load the source presentation file

            using (Presentation srcPres = new Presentation(dataDir + "CloneToAnotherPresentationWithMaster.pptx"))
            {
                // Instantiate Presentation class for destination presentation (where slide is to be cloned)
                using (Presentation destPres = new Presentation())
                {
                    // Instantiate ISlide from the collection of slides in source presentation along with
                    // Master slide
                    ISlide       SourceSlide  = srcPres.Slides[0];
                    IMasterSlide SourceMaster = SourceSlide.LayoutSlide.MasterSlide;

                    // Clone the desired master slide from the source presentation to the collection of masters in the
                    // Destination presentation
                    IMasterSlideCollection masters    = destPres.Masters;
                    IMasterSlide           DestMaster = SourceSlide.LayoutSlide.MasterSlide;

                    // Clone the desired master slide from the source presentation to the collection of masters in the
                    // Destination presentation
                    IMasterSlide iSlide = masters.AddClone(SourceMaster);

                    // Clone the desired slide from the source presentation with the desired master to the end of the
                    // Collection of slides in the destination presentation
                    ISlideCollection slds = destPres.Slides;
                    slds.AddClone(SourceSlide, iSlide, true);

                    // Clone the desired master slide from the source presentation to the collection of masters in the // Destination presentation
                    // Save the destination presentation to disk
                    destPres.Save(dataDir + "CloneToAnotherPresentationWithMaster_out.pptx", SaveFormat.Pptx);
                }
            }
            //ExEnd:CloneToAnotherPresentationWithMaster
        }
Example #13
0
        private bool SpiltPPT(string file, ref string message)
        {
            //Aspose.Slides.License license = new Aspose.Slides.License();
            //license.SetLicense("Aspose.Slides.lic");
            bool result = true;

            try
            {
                using (Presentation srcPres = new Presentation(dataDir + file))
                {
                    foreach (ISlide slide in srcPres.Slides)
                    {
                        using (Presentation destPres = new Presentation())
                        {
                            for (int i = 0; i < slide.Shapes.Count; i++)
                            {
                                if (slide.Shapes[i].AsISlideComponent.GetType() == typeof(Aspose.Slides.AutoShape))
                                {
                                    if (((IAutoShape)slide.Shapes[i]).TextFrame.Text.Contains("#code#"))
                                    {
                                        string           code = ((IAutoShape)slide.Shapes[i]).TextFrame.Text.Replace("#code#", "");
                                        ISlideCollection slds = destPres.Slides;
                                        slds.AddClone(slide);
                                        destPres.Slides[0].Remove();//去掉空白页
                                        destPres.Save(dataDir + code + ".ppt", SaveFormat.Ppt);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result  = false;
                message = "拆分ppt失败:" + ex.Message;
            }
            return(result);
        }
Example #14
0
        /// <summary>
        /// 根据模板生成ppt
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        private bool CreatePPT(string code, string jclb, string wtms)
        {
            bool result = true;

            try
            {
                using (Presentation destPres = new Presentation())
                {
                    using (Presentation srcPres = new Presentation(dataDir + "问题检查模板.ppt"))
                    {
                        //Instantiate ISlide from the collection of slides in source presentation along with
                        //master slide
                        ISlide       SourceSlide  = srcPres.Slides[0];
                        IMasterSlide SourceMaster = SourceSlide.LayoutSlide.MasterSlide;

                        //Clone the desired master slide from the source presentation to the collection of masters in the
                        //destination presentation
                        IMasterSlideCollection masters    = destPres.Masters;
                        IMasterSlide           DestMaster = SourceSlide.LayoutSlide.MasterSlide;

                        //Clone the desired master slide from the source presentation to the collection of masters in the
                        //destination presentation
                        IMasterSlide iSlide = masters.AddClone(SourceMaster);

                        //Clone the desired slide from the source presentation with the desired master to the end of the
                        //collection of slides in the destination presentation
                        ISlideCollection slds = destPres.Slides;
                        slds.AddClone(SourceSlide, iSlide, true);
                        //Clone the desired master slide from the source presentation to the collection of masters in the //destination presentation
                        //Save the destination presentation to disk

                        destPres.Slides[0].Remove();

                        ISlide slide = destPres.Slides[0];

                        IAutoShape ashp = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 200, 50, 100, 50);

                        // Remove any fill style associated with the AutoShape
                        ashp.FillFormat.FillType = FillType.NoFill;
                        ashp.Hidden          = true;
                        ashp.Name            = "code";
                        ashp.AlternativeText = "hiddenfield";

                        // Access the TextFrame associated with the AutoShape
                        ITextFrame tf = ashp.TextFrame;
                        tf.Text = "#code#" + code;


                        //Iterating through all shapes inside the slide
                        for (int i = 0; i < slide.Shapes.Count; i++)
                        {
                            if (slide.Shapes[i].AsISlideComponent.GetType() == typeof(Aspose.Slides.AutoShape))
                            {
                                if (((IAutoShape)slide.Shapes[i]).TextFrame.Text == "检查类别")
                                {
                                    ((IAutoShape)slide.Shapes[i]).TextFrame.Text = jclb;
                                }
                                if (((IAutoShape)slide.Shapes[i]).TextFrame.Text == "问题描述")
                                {
                                    ((IAutoShape)slide.Shapes[i]).TextFrame.Text = wtms;
                                }

                                /*** 2003版本slide.Shapes[i]).Name值会丢失
                                 * if (((IAutoShape)slide.Shapes[i]).Name == "code")
                                 * {
                                 *
                                 *  code= ((IAutoShape)slide.Shapes[i]).TextFrame.Text;
                                 * }
                                 ****/
                                if (((IAutoShape)slide.Shapes[i]).TextFrame.Text.Contains("#code#"))
                                {
                                    code = ((IAutoShape)slide.Shapes[i]).TextFrame.Text.Replace("#code#", "");
                                }
                            }
                        }

                        destPres.Save(dataDir + code + ".ppt", SaveFormat.Ppt);
                    }
                }
            }
            catch (Exception ex)
            {
                result = false;
            }
            return(result);
        }
Example #15
0
        /**************************
         * 如模板文件如为pptx格式,生成文件为ppt,生成后的ppt中的问题描述字体颜色会发生变化,因此需要将模板文件更改为ppt格式,但ppt格式中的
         * 隐藏shape.name会在生成的ppt中丢失,采取TextFrame.Text添加标记来区分是否是隐藏元素,并将需要存储的值存于TextFrame.Text中
         ***************************/
        private void btn_singlegenarate_Click(object sender, EventArgs e)
        {
            using (Presentation destPres = new Presentation())
            {
                using (Presentation srcPres = new Presentation(dataDir + "问题检查模板.ppt"))
                {
                    //Instantiate ISlide from the collection of slides in source presentation along with
                    //master slide
                    ISlide       SourceSlide  = srcPres.Slides[0];
                    IMasterSlide SourceMaster = SourceSlide.LayoutSlide.MasterSlide;

                    //Clone the desired master slide from the source presentation to the collection of masters in the
                    //destination presentation
                    IMasterSlideCollection masters    = destPres.Masters;
                    IMasterSlide           DestMaster = SourceSlide.LayoutSlide.MasterSlide;

                    //Clone the desired master slide from the source presentation to the collection of masters in the
                    //destination presentation
                    IMasterSlide iSlide = masters.AddClone(SourceMaster);

                    //Clone the desired slide from the source presentation with the desired master to the end of the
                    //collection of slides in the destination presentation
                    ISlideCollection slds = destPres.Slides;
                    slds.AddClone(SourceSlide, iSlide, true);
                    //Clone the desired master slide from the source presentation to the collection of masters in the //destination presentation
                    //Save the destination presentation to disk

                    destPres.Slides[0].Remove();

                    foreach (ISlide slide in slds)
                    {
                        //Iterating through all shapes inside the slide
                        for (int i = 0; i < slide.Shapes.Count; i++)
                        {
                            //If the alternative text of the slide matches with the required one then
                            //return the shape
                            //if (slide.Shapes[i].AlternativeText.CompareTo(alttext) == 0)
                            //    return slide.Shapes[i];

                            //if (slide.Shapes[i].AlternativeText == "检查类别")
                            //    slide.Shapes[i].AlternativeText = "123456";

                            if (slide.Shapes[i].Placeholder != null)
                            {
                                //Change the text of each placeholder
                                ((IAutoShape)slide.Shapes[i]).TextFrame.Text = "This is Placeholder";
                            }
                        }
                    }


                    ISlide sld = destPres.Slides[0];

                    //// Add an AutoShape of Rectangle type
                    //IAutoShape ashp = sld.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 200, 50);

                    //// Remove any fill style associated with the AutoShape
                    //ashp.FillFormat.FillType = FillType.NoFill;
                    ////ashp.UseBackgroundFill = true;
                    ////ashp.LineFormat.Width = 0;
                    //ashp.LineFormat.FillFormat.FillType = FillType.NoFill;//设置无边框
                    ////ashp.LineFormat.FillFormat.SolidFillColor.Color = Color.Red;

                    //// Access the TextFrame associated with the AutoShape
                    //ITextFrame tf = ashp.TextFrame;
                    ////tf.TextFrameFormat.
                    //tf.Text = "Aspose TextBox22";

                    //// Access the Portion associated with the TextFrame
                    //IPortion port = tf.Paragraphs[0].Portions[0];

                    //// Set the Font for the Portion
                    //port.PortionFormat.LatinFont = new FontData("Times New Roman");

                    //// Set Bold property of the Font
                    //port.PortionFormat.FontBold = NullableBool.True;

                    //// Set Italic property of the Font
                    //port.PortionFormat.FontItalic = NullableBool.True;

                    //// Set Underline property of the Font
                    //port.PortionFormat.FontUnderline = TextUnderlineType.Single;

                    //// Set the Height of the Font
                    //port.PortionFormat.FontHeight = 25;

                    //// Set the color of the Font
                    //port.PortionFormat.FillFormat.FillType = FillType.Solid;
                    //port.PortionFormat.FillFormat.SolidFillColor.Color = Color.Blue;

                    // ExEnd:SetTextFontProperties
                    // Write the PPTX to disk
                    //presentation.Save(dataDir + "SetTextFontProperties.pptx", SaveFormat.Pptx);

                    IAutoShape ashp2 = sld.Shapes.AddAutoShape(ShapeType.Rectangle, 200, 50, 100, 50);

                    // Remove any fill style associated with the AutoShape
                    ashp2.FillFormat.FillType = FillType.NoFill;
                    ashp2.Hidden          = true;
                    ashp2.Name            = "code";
                    ashp2.AlternativeText = "hiddenfield";

                    // Access the TextFrame associated with the AutoShape
                    ITextFrame tf2 = ashp2.TextFrame;
                    tf2.Text = "#code#这是code值";

                    destPres.Save(dataDir + "single.ppt", SaveFormat.Ppt);
                }
            }
        }