示例#1
0
        /// <summary>
        /// Creates slides with simple text in a PowerPoint Presentation.
        /// </summary>
        private void BtnCreatePresn_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
        {
            //Gets the input PowerPoint Presentation file.
            Assembly assembly     = typeof(HelloWorld).GetTypeInfo().Assembly;
            string   resourcePath = "syncfusion.presentationdemos.winui.Assets.Presentation.HelloWorld.pptx";

            using Stream fileStream = assembly.GetManifestResourceStream(resourcePath);
            //Opens an existing PowerPoint Presentation file.
            using IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fileStream);
            //Creates slides in PowerPoint Presentation file.
            CreateDefaultSlide(presentation);

            //Saves the presentation to the memory stream.
            using MemoryStream stream = new();
            if (presentationdoc.IsChecked == true)
            {
                presentation.Save(stream);
                stream.Position = 0;
                //Saves the memory stream as file.
                SaveAndLaunch.Save("HelloWorld.pptx", stream);
            }
            else
            {
                //Converts the PowerPoint Presentation to PDF document.
                using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation))
                {
                    //Saves the converted PDF document to MemoryStream.
                    pdfDocument.Save(stream);
                    stream.Position = 0;
                }
                //Saves the memory stream as file.
                SaveAndLaunch.Save("HelloWorld.pdf", stream);
            }
        }
        /// <summary>
        /// Encrypts and decrypts the presentation.
        /// </summary>
        private void BtnCreatePresn_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
        {
            string fileName;
            //Gets the input PowerPoint Presentation file.
            Assembly assembly     = typeof(EncryptAndDecrypt).GetTypeInfo().Assembly;
            string   resourcePath = "syncfusion.presentationdemos.winui.Assets.Presentation.SyncfusionPresentation.pptx";

            using Stream fileStream = assembly.GetManifestResourceStream(resourcePath);
            //Opens an existing PowerPoint Presentation file.
            using IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fileStream);
            using MemoryStream ms            = new();
            if (rdEncrypt.IsChecked == true)
            {
                //Encrypts the PowerPoint Presentation file.
                presentation.Encrypt("syncfusion");
                fileName = "Encrypt.pptx";
            }
            else
            {
                //Decrypts the PowerPoint Presentation file.
                presentation.RemoveEncryption();
                fileName = "Decrypt.pptx";
            }
            //Saves the presentation to the memory stream.
            presentation.Save(ms);
            ms.Position = 0;
            //Saves the memory stream as file.
            SaveAndLaunch.Save(fileName, ms);
        }
示例#3
0
 /// <summary>
 /// Creates charts in a presentation.
 /// </summary>
 private void BtnCreatePresn_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
 {
     //Creates a new instance of the PowerPoint Presentation file.
     using IPresentation presentation = Presentation.Create();
     //Creates slides with chart.
     CreateChart(presentation);
     using MemoryStream ms = new();
     if (presentationdoc.IsChecked == true)
     {
         //Saves the presentation to the memory stream.
         presentation.Save(ms);
         ms.Position = 0;
         //Saves the memory stream as file.
         SaveAndLaunch.Save("Chart.pptx", ms);
     }
     else
     {
         //Converts the PowerPoint Presentation to PDF document.
         using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation))
         {
             //Saves the converted PDF document to MemoryStream.
             pdfDocument.Save(ms);
             ms.Position = 0;
         }
         //Saves the memory stream as file.
         SaveAndLaunch.Save("Chart.pdf", ms);
     }
 }
        /// <summary>
        /// Creates a PowerPoint Presentation file with headers and footers.
        /// </summary>
        private void BtnCreatePresn_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
        {
            //Gets the input PowerPoint Presentation file.
            Assembly assembly     = typeof(HeaderAndFooter).GetTypeInfo().Assembly;
            string   resourcePath = "syncfusion.presentationdemos.winui.Assets.Presentation.HeaderFooter.pptx";

            using Stream fileStream = assembly.GetManifestResourceStream(resourcePath);
            //Opens an existing PowerPoint Presentation file.
            using IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fileStream);
            //Adds footers into all the PowerPoint slides.
            foreach (ISlide slide in presentation.Slides)
            {
                //Enables a date and time footer in slide.
                slide.HeadersFooters.DateAndTime.Visible = true;
                //Enables a footer in slide.
                slide.HeadersFooters.Footer.Visible = true;
                //Sets the footer text.
                slide.HeadersFooters.Footer.Text = "Footer";
                //Enables a slide number footer in slide.
                slide.HeadersFooters.SlideNumber.Visible = true;
            }

            //Adds header into first slide notes page.
            //Adds a notes slide to the slide.
            INotesSlide notesSlide = presentation.Slides[0].AddNotesSlide();

            //Enables a header in notes slide.
            notesSlide.HeadersFooters.Header.Visible = true;
            //Sets the header text.
            notesSlide.HeadersFooters.Header.Text = "Syncfusion PowerPoint Library";

            //Saves the presentation to the memory stream.
            using MemoryStream stream = new();
            if (presentationdoc.IsChecked == true)
            {
                presentation.Save(stream);
                stream.Position = 0;
                //Saves the memory stream as file.
                SaveAndLaunch.Save("HeaderFooter.pptx", stream);
            }
            else
            {
                //Converts the PowerPoint Presentation to PDF document.
                using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation))
                {
                    //Saves the converted PDF document to MemoryStream.
                    pdfDocument.Save(stream);
                    stream.Position = 0;
                }
                //Saves the memory stream as file.
                SaveAndLaunch.Save("HeaderFooter.pdf", stream);
            }
        }
示例#5
0
        /// <summary>
        /// Opens the input template PowerPoint Presentation file.
        /// </summary>
        private void Open_BtnClick(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
        {
            //Gets the input PowerPoint Presentation file.
            Assembly assembly     = typeof(PPTXToPDF).GetTypeInfo().Assembly;
            string   resourcePath = "syncfusion.presentationdemos.winui.Assets.Presentation.Template.pptx";

            using Stream fileStream = assembly.GetManifestResourceStream(resourcePath);
            using MemoryStream ms   = new();
            fileStream.CopyTo(ms);
            ms.Position = 0;
            //Saves the memory stream as file.
            SaveAndLaunch.Save("Template.pptx", ms);
        }
        /// <summary>
        /// Converts the PowerPoint slide to an image.
        /// </summary>
        private void Convert_BtnClick(System.Object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
        {
            //Gets the input PowerPoint Presentation file.
            Assembly assembly     = typeof(PPTXToImage).GetTypeInfo().Assembly;
            string   resourcePath = "syncfusion.presentationdemos.winui.Assets.Presentation.Template.pptx";

            using Stream fileStream = assembly.GetManifestResourceStream(resourcePath);
            //Opens an existing PowerPoint Presentation file.
            using IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fileStream);
            //Initializes PresentationRenderer to perform image conversion.
            presentation.PresentationRenderer = new PresentationRenderer();
            //Converts PowerPoint slide to image stream.
            using MemoryStream stream = (MemoryStream)presentation.Slides[0].ConvertToImage(Syncfusion.Presentation.ExportImageFormat.Jpeg);
            stream.Position           = 0;
            //Saves the memory stream as image.
            SaveAndLaunch.Save("Slide.jpg", stream);
        }
示例#7
0
        /// <summary>
        /// Converts a PowerPoint Presentation to PDF.
        /// </summary>
        private void Convert_BtnClick(System.Object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
        {
            //Gets the input PowerPoint Presentation file.
            Assembly assembly     = typeof(PPTXToPDF).GetTypeInfo().Assembly;
            string   resourcePath = "syncfusion.presentationdemos.winui.Assets.Presentation.Template.pptx";

            using Stream fileStream = assembly.GetManifestResourceStream(resourcePath);
            //Opens an existing PowerPoint Presentation file.
            using IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fileStream);
            //Creates the MemoryStream to save the converted PDF.
            using MemoryStream pdfStream = new();
            //Converts the PowerPoint Presentation to PDF document.
            using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation))
            {
                //Saves the converted PDF document to MemoryStream.
                pdfDocument.Save(pdfStream);
                pdfStream.Position = 0;
            }
            //Saves the memory stream as file.
            SaveAndLaunch.Save("PPTXToPDF.pdf", pdfStream);
        }
示例#8
0
        /// <summary>
        /// Add table in a PowerPoint Presentation file.
        /// </summary>
        private void BtnCreatePresn_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
        {
            //Creates a new instance of the PowerPoint Presentation file.
            using IPresentation presentation = Syncfusion.Presentation.Presentation.Create();
            #region Slide1
            //Adds a slide to PowerPoint presentation.
            ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleOnly);
            //Sets the table title in a slide.
            SetTableTitle(slide);
            //Gets table data from xml file.
            DataSet  dataSet      = new();
            Assembly assembly     = typeof(Table).GetTypeInfo().Assembly;
            string   resourcePath = "syncfusion.presentationdemos.winui.Assets.Presentation.TableData.xml";
            using (Stream fileStream = assembly.GetManifestResourceStream(resourcePath))
            {
                dataSet.ReadXml(fileStream);
            }
            int columnCount = dataSet.Tables[0].Rows.Count + 1;
            int rowCount    = dataSet.Tables.Count - 1;
            //Adds a new table in slide.
            ITable table = slide.Shapes.AddTable(rowCount, columnCount, 61.92, 95.76, 856.8, 378.72);
            //Sets the style for the table.
            table.BuiltInStyle = BuiltInTableStyle.MediumStyle2Accent6;

            //Sets category title
            SetCategoryTitle(table);
            //Iterates and sets the values to the table cells.
            for (int rowIndex = 0; rowIndex < table.Rows.Count; rowIndex++)
            {
                IRow row = table.Rows[rowIndex];
                if (rowIndex == 0)
                {
                    AddHeaderRow(row, dataSet.Tables[0].Rows);
                }
                else
                {
                    AddCell(row, dataSet.Tables[rowIndex + 1]);
                }
            }
            #endregion
            //Saves the presentation to the memory stream.
            using MemoryStream stream = new();
            if (presentationdoc.IsChecked == true)
            {
                presentation.Save(stream);
                stream.Position = 0;
                //Saves the memory stream as file.
                SaveAndLaunch.Save("Table.pptx", stream);
            }
            else
            {
                //Converts the PowerPoint Presentation to PDF document.
                using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation))
                {
                    //Saves the converted PDF document to MemoryStream.
                    pdfDocument.Save(stream);
                    stream.Position = 0;
                }
                //Saves the memory stream as file.
                SaveAndLaunch.Save("Table.pdf", stream);
            }
        }