示例#1
0
        private void btnCreatePresn_Click(object sender, EventArgs e)
        {
            //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides].
            IPresentation presentation = Presentation.Create();
            //Add slide with titleonly layout to presentation
            ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleOnly);
            //Get the title placeholder
            IShape titleShape = slide.Shapes[0] as IShape;

            //Set size and position of the title shape
            titleShape.Left   = 0.92 * 72;
            titleShape.Top    = 0.4 * 72;
            titleShape.Width  = 11.5 * 72;
            titleShape.Height = 1.01 * 72;

            //Add title content
            titleShape.TextBody.AddParagraph("Ole Object Demo");
            //Set the title content as bold
            titleShape.TextBody.Paragraphs[0].Font.Bold = true;
            //Set the horizontal alignment as center
            titleShape.TextBody.Paragraphs[0].HorizontalAlignment = HorizontalAlignmentType.Center;
            //Add text box of specific size and position
            IShape heading = slide.Shapes.AddTextBox(3.2 * 72, 1.51 * 72, 1.86 * 72, 0.71 * 72);

            //Add paragraph to text box
            heading.TextBody.AddParagraph("MS Excel Object");
            //Set the text content as italic
            heading.TextBody.Paragraphs[0].Font.Italic = true;
            //Set the text content as bold
            heading.TextBody.Paragraphs[0].Font.Bold = true;
            //Set the font size
            heading.TextBody.Paragraphs[0].Font.FontSize = 18;

            string excelPath = @"..\..\..\..\..\..\..\Common\Data\Presentation\OleTemplate.xlsx";
            //Get the excel file as stream
            Stream excelStream = File.Open(excelPath, FileMode.Open);
            string imagePath   = @"..\..\..\..\..\..\..\Common\Images\Presentation\OlePicture.png";
            //Image to be displayed, This can be any image
            Stream imageStream = File.Open(imagePath, FileMode.Open);
            //Add ole object to the slide
            IOleObject oleObject = slide.Shapes.AddOleObject(imageStream, "Excel.Sheet.12", excelStream);

            //Set size and position of the ole object
            oleObject.Left   = 3.29 * 72;
            oleObject.Top    = 2.01 * 72;
            oleObject.Width  = 6.94 * 72;
            oleObject.Height = 5.13 * 72;

            //Save the presentation
            presentation.Save("OleObjectSample.pptx");
            //Close the presentation
            presentation.Close();

            if (System.Windows.MessageBox.Show("Do you want to view the generated Presentation?", "Presentation Created",
                                               MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
            {
                System.Diagnostics.Process.Start("OleObjectSample.pptx");
                this.Close();
            }
        }
示例#2
0
        /// <summary>
        /// Encrypt the word document
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void protect_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(passwordBox1.Password))
                {
                    MessageBox.Show("Please enter password to protect", "Password Missing", MessageBoxButton.OK);
                }
                else
                {
                    //Creates instance for presentation
                    IPresentation presentation = Presentation.Open(textBox1.Tag.ToString());
                    //Set the write protection for presentation instance
                    presentation.SetWriteProtection(passwordBox1.Password);
                    //Saving the presentation
                    presentation.Save("WriteProtection.pptx");
                    //Closing the presentation
                    presentation.Close();

                    if (MessageBox.Show("Do you want to view the protected Presentation?", "Write Protected Presentation",
                                        MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                    {
                        System.Diagnostics.Process.Start("WriteProtection.pptx");
                    }
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show("This file could not be write protected , please contact Syncfusion Direct-Trac system at http://www.syncfusion.com/support/default.aspx for any queries. ", "OOPS..Sorry!",
                                MessageBoxButton.OK);
            }
        }
示例#3
0
 protected override void OnClosing(CancelEventArgs e)
 {
     if (presentation != null)
     {
         presentation.Close();
         presentation = null;
     }
     if (slideImageSources != null)
     {
         slideImageSources.Clear();
         slideImageSources = null;
     }
     if (thumbnailImageSource != null)
     {
         thumbnailImageSource.Clear();
         thumbnailImageSource = null;
     }
     if (printImages != null)
     {
         foreach (System.Drawing.Image image in printImages)
         {
             image.Dispose();
         }
         printImages.Clear();
         printImages = null;
     }
     base.OnClosing(e);
 }
示例#4
0
        public FileStreamResult GeneratePPT(List <ViewData> viewDataList)
        {
            //Creates a PowerPoint instance
            IPresentation pptxDoc = Presentation.Create();

            ExcelEngine  excelEngine      = new ExcelEngine();
            IApplication excelApplication = excelEngine.Excel;

            excelApplication.DefaultVersion = ExcelVersion.Excel2016;

            foreach (var item in viewDataList)
            {
                if (String.IsNullOrEmpty(item.ChartType))
                {
                    continue;
                }
                IWorkbook  wb        = excelApplication.Workbooks.Open(item.DataStream, ExcelOpenType.CSV);
                IWorksheet worksheet = wb.Worksheets[0];
                worksheet.Name = item.Name;
                DataTable dataTable = worksheet.ExportDataTable(worksheet.UsedRange, ExcelExportDataTableOptions.ColumnNames | ExcelExportDataTableOptions.DetectColumnTypes);
                if (dataTable == null)
                {
                    continue;
                }
                wb.Close();
                ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
                //Handle error here to continue after chart testing is done.
                try
                {
                    if (item.ChartType.Equals("Table"))
                    {
                        CreateTable(dataTable, slide, item);
                    }
                    else
                    {
                        CreateChart(slide, dataTable, item);
                    }
                }
                catch (Exception e)
                {
                    _logger.LogError(e.Message);
                    continue;
                }
            }

            MemoryStream stream = new MemoryStream();

            pptxDoc.Save(stream);

            //Set the position as '0'.
            stream.Position = 0;

            //Download the PowerPoint file in the browser
            FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/powerpoint");

            fileStreamResult.FileDownloadName = "Editable-" + DateTime.Now.ToString() + ".pptx";
            //WorkbookTuple.Item2.Close();
            pptxDoc.Close();
            return(fileStreamResult);
        }
示例#5
0
        private void btnCreatePowerPoint_Click(object sender, RoutedEventArgs e)
        {
            //Create a new PowerPoint presentation
            IPresentation powerpointDoc = Presentation.Create();

            //Add a blank slide to the presentation
            ISlide slide = powerpointDoc.Slides.Add(SlideLayoutType.Blank);

            //Add a textbox to the slide
            IShape shape = slide.AddTextBox(400, 100, 500, 100);

            shape.TextBody.AddParagraph(titleAreaText.Text);

            //Add a text to the textbox.
            //shape.TextBody.AddParagraph(titleAreaText.Text);
            shape.TextBody.AddParagraph(textAreaText.Text);

            //Save the PowerPoint presentation
            powerpointDoc.Save("Sample.pptx");

            //Close the PowerPoint presentation
            powerpointDoc.Close();

            //Open the PowerPoint presentation
            System.Diagnostics.Process.Start("Sample.pptx");
        }
示例#6
0
        //Create slide using SyncFusion framework
        private void btnCreateSlide_Click(object sender, EventArgs e)
        {
            user.Title     = txtTitle.Text;
            user.TextField = txtTextField.Text;

            IPresentation powerpointDoc = Presentation.Create();
            ISlide        slide         = powerpointDoc.Slides.Add(SlideLayoutType.Blank);

            IShape title = slide.AddTextBox(50, 40, 500, 100);

            title.TextBody.AddParagraph(user.Title);
            title.TextBody.Paragraphs[0].Font.FontSize = 24;


            IShape textfield = slide.AddTextBox(100, 110, 800, 300);

            textfield.TextBody.AddParagraph(user.TextField);

            for (int imgCt = 1; imgCt <= user.Images.Count; imgCt++)
            {
                var ms = new MemoryStream();
                user.Images[imgCt - 1].Save(ms, ImageFormat.Png);

                IPicture picture = slide.Pictures.AddPicture(ms, ReturnImgLength(imgCt), 350, user.Images[imgCt - 1].Width * 1.25, user.Images[imgCt - 1].Height * 1.25);
            }

            powerpointDoc.Save("GeneratedPowerpoint.pptx");
            powerpointDoc.Close();

            ResetSelection();
        }
示例#7
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            //Opens an existing PowerPoint presentation.
            Stream        file1   = new FileStream(ResolveApplicationDataPath("HeaderFooter.pptx"), FileMode.Open, FileAccess.Read, FileShare.Read);
            IPresentation pptxDoc = Presentation.Open(file1);

            //Add footers into all the PowerPoint slides.
            foreach (ISlide slide in pptxDoc.Slides)
            {
                //Enable a date and time footer in slide.
                slide.HeadersFooters.DateAndTime.Visible = true;
                //Enable a footer in slide.
                slide.HeadersFooters.Footer.Visible = true;
                //Sets the footer text.
                slide.HeadersFooters.Footer.Text = "Footer";
                //Enable a slide number footer in slide.
                slide.HeadersFooters.SlideNumber.Visible = true;
            }

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

            //Enable a header in notes slide.
            notesSlide.HeadersFooters.Header.Visible = true;
            //Sets the header text.
            notesSlide.HeadersFooters.Header.Text = "Header";

            //Saves Presentation with specified file name with extension.
            pptxDoc.Save("HeaderFooterSample.pptx", FormatType.Pptx, Response);
            //Closes the Presentation
            pptxDoc.Close();
        }
        private void Repalce_Pic()
        {
            //Opens an existing Presentation.
            IPresentation pptxDoc = Presentation.Open("Sample.pptx");

            //Retrieves the first slide from the Presentation.
            ISlide slide = pptxDoc.Slides[0];

            //Retrieves the first picture from the slide.
            IPicture picture = slide.Pictures[0];

            WebClient client = new WebClient();

            //Gets the new picture as stream.
            byte[] data = client.DownloadData(filepath);

            //Creates instance for memory stream
            MemoryStream memoryStream = new MemoryStream(data);

            //Replaces the existing image with new image.
            picture.ImageData = memoryStream.ToArray();

            //Saves the Presentation to the file system.
            pptxDoc.Save("Output.pptx");

            //Closes the Presentation
            pptxDoc.Close();
        }
        public ActionResult CreateDocument()
        {
            // create a powerpoint instance
            IPresentation pptxDoc = Presentation.Create();

            //Add slide to the the Powerpoint presentation
            ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);

            //Addd a textbox to the slide
            IShape shape = slide.AddTextBox(10, 10, 500, 100);

            //Add a textbox to the text box
            shape.TextBody.AddParagraph("Welcome to Powerpoint");

            //Save the PowerPoint Presentation

            pptxDoc.Save("Sample.pptx", FormatType.Pptx, HttpContext.ApplicationInstance.Response);

            // Close the PowerPoint presentation
            pptxDoc.Close();

            ViewBag.Message = "Create A new SlideShow.";

            return(View());
        }
        void OnButtonClicked(object sender, EventArgs e)
        {
            string resourcePath = "";

#if COMMONSB
            resourcePath = "SampleBrowser.Samples.Presentation.Samples.Templates.ShapeWithAnimation.pptx";
#else
            resourcePath = "SampleBrowser.Presentation.Samples.Templates.ShapeWithAnimation.pptx";
#endif
            Assembly assembly   = typeof(GettingStarted).GetTypeInfo().Assembly;
            Stream   fileStream = assembly.GetManifestResourceStream(resourcePath);

            //Open a PowerPoint presentation
            IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fileStream);

            //Modify the existing animation
            ModifyAppliedAnimation(presentation);

            //Save the Presentation to stream
            MemoryStream stream = new MemoryStream();
            presentation.Save(stream);
            presentation.Close();
            stream.Position = 0;
            if (Device.RuntimePlatform == Device.UWP)
            {
                Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("ModifyAnimationSample.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream);
            }
            else
            {
                Xamarin.Forms.DependencyService.Get <ISave>().Save("ModifyAnimationSample.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream);
            }
        }
示例#11
0
        void OnInsertOleButtonClicked(object sender, EventArgs e)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides].
            IPresentation presentation = Syncfusion.Presentation.Presentation.Create();

            ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleOnly);

            IShape titleShape = slide.Shapes[0] as IShape;

            titleShape.Left   = 0.65 * 72;
            titleShape.Top    = 0.24 * 72;
            titleShape.Width  = 11.5 * 72;
            titleShape.Height = 1.45 * 72;
            titleShape.TextBody.AddParagraph("Ole Object");
            titleShape.TextBody.Paragraphs[0].Font.Bold           = true;
            titleShape.TextBody.Paragraphs[0].HorizontalAlignment = HorizontalAlignmentType.Left;

            IShape heading = slide.Shapes.AddTextBox(100, 100, 100, 100);

            heading.Left   = 0.84 * 72;
            heading.Top    = 1.65 * 72;
            heading.Width  = 2.23 * 72;
            heading.Height = 0.51 * 72;
            heading.TextBody.AddParagraph("MS Word Object");
            heading.TextBody.Paragraphs[0].Font.Italic   = true;
            heading.TextBody.Paragraphs[0].Font.Bold     = true;
            heading.TextBody.Paragraphs[0].Font.FontSize = 18;

            string mswordPath = "SampleBrowser.Samples.Presentation.Templates.OleTemplate.docx";

            //Get the word file as stream
            Stream wordStream = assembly.GetManifestResourceStream(mswordPath);
            string imagePath  = "SampleBrowser.Samples.Presentation.Templates.OlePicture.png";

            //Image to be displayed, This can be any image
            Stream imageStream = assembly.GetManifestResourceStream(imagePath);

            IOleObject oleObject = slide.Shapes.AddOleObject(imageStream, "Word.Document.12", wordStream);

            //Set size and position of the ole object
            oleObject.Left   = 4.53 * 72;
            oleObject.Top    = 0.79 * 72;
            oleObject.Width  = 4.26 * 72;
            oleObject.Height = 5.92 * 72;
            //Set DisplayAsIcon as true, to open the embedded document in separate (default) application.
            oleObject.DisplayAsIcon = true;
            MemoryStream stream = new MemoryStream();

            presentation.Save(stream);
            presentation.Close();
            stream.Position = 0;

            if (stream != null)
            {
                SaveiOS iOSSave = new SaveiOS();
                iOSSave.Save("InsertOLEObject.pptx", "application/mspowerpoint", stream);
            }
        }
示例#12
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            string   resourcePath = "SampleBrowser.Samples.Presentation.Templates.EmbeddedOleObject.pptx";
            Assembly assembly     = Assembly.GetExecutingAssembly();
            Stream   fileStream   = assembly.GetManifestResourceStream(resourcePath);

            IPresentation presentation = Presentation.Open(fileStream);

            //Gets the first slide of the Presentation
            ISlide slide = presentation.Slides[0];
            //Gets the Ole Object of the slide
            IOleObject oleObject = slide.Shapes[2] as IOleObject;

            //Gets the file data of embedded Ole Object.
            byte[] array = oleObject.ObjectData;
            //Gets the file Name of OLE Object
            string outputFile = oleObject.FileName;

            MemoryStream stream = new MemoryStream(array);

            presentation.Close();
            stream.Position = 0;

            if (stream != null)
            {
                SaveiOS iOSSave = new SaveiOS();
                iOSSave.Save(outputFile, "application/msword", stream);
            }
        }
示例#13
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            string   resourcePath = "SampleBrowser.Samples.Presentation.Templates.Template.pptx";
            Assembly assembly     = Assembly.GetExecutingAssembly();
            Stream   fileStream   = assembly.GetManifestResourceStream(resourcePath);

            //Open a existing PowerPoint Presentation.
            IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fileStream);

            //Convert the PowerPoint document to PDF document.
            PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation);

            MemoryStream pdfStream = new MemoryStream();

            //Save the converted PDF document into MemoryStream.
            pdfDocument.Save(pdfStream);
            pdfStream.Position = 0;

            //Close the PDF document.
            pdfDocument.Close(true);

            //Close the PowerPoint Presentation.
            presentation.Close();
            if (pdfStream != null)
            {
                SaveAndroid androidSave = new SaveAndroid();
                androidSave.Save("PPTXToPDF.pdf", "application/pdf", pdfStream, m_context);
            }
        }
示例#14
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            string   resourcePath = "SampleBrowser.Samples.Presentation.Templates.Images.pptx";
            Assembly assembly     = Assembly.GetExecutingAssembly();
            Stream   fileStream   = assembly.GetManifestResourceStream(resourcePath);

            IPresentation presentation = Presentation.Open(fileStream);

            //  Method call to create slides
            CommentsHelper.SlideWithComments1(presentation);
            CommentsHelper.SlideWithComments2(presentation);
            CommentsHelper.SlideWithComments3(presentation);

            MemoryStream stream = new MemoryStream();

            presentation.Save(stream);
            presentation.Close();
            stream.Position = 0;

            if (stream != null)
            {
                SaveiOS iOSSave = new SaveiOS();
                iOSSave.Save("CommentsPresentation.pptx", "application/mspowerpoint", stream);
            }
        }
示例#15
0
        public static void Main()
        {
            /* Take in values for numbers of slides and images to parse from HTML */
            Console.WriteLine("How many items do you need?: ");
            string input = Console.ReadLine();
            int    number;

            Int32.TryParse(input, out number);

            /* Take in user response for image content */
            Console.WriteLine("What would you like to search for?: ");
            var search = Console.ReadLine();

            /* Load Shutterstock site and create new WebClient and scrape searching for <img src> tag */
            var       document = new HtmlWeb().Load("https://www.shutterstock.com/search/" + search);
            WebClient client   = new WebClient();
            var       urls     = document.DocumentNode.Descendants("img")
                                 .Select(e => e.GetAttributeValue("src", null))
                                 .Where(s => !String.IsNullOrEmpty(s));
            int x = 0;

            /* Initialize new PPT Presentation using SyncFusion */
            IPresentation pptxDoc = Presentation.Create();

            /* Iterate over urls of images, download to local directory number of specified images */
            foreach (string item in urls)
            {
                if (x == number)
                {
                    break;
                }
                client.DownloadFile(item, search + x + ".jpg");
                Console.WriteLine(item);

                /* Create new Blank slide, take in User title text */
                ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
                Console.WriteLine("Enter title text: ");
                var title = Console.ReadLine();

                /* Open local image files scraped from web and add to slide with user defined title of each slide */
                Stream pictureStream = File.Open("./" + search + x + ".jpg", FileMode.Open);
                slide.Pictures.AddPicture(pictureStream, slide.SlideSize.Width / 2, slide.SlideSize.Height / 2, 250, 250);
                IShape     titleTextBox = slide.AddTextBox(slide.SlideSize.Width / 2, 10, 500, 500);
                IParagraph paragraph    = titleTextBox.TextBody.AddParagraph();
                ITextPart  textPart     = paragraph.AddTextPart();
                textPart.Text = title;
                pictureStream.Dispose();
                x++;
            }

            /* Save PPT project */
            pptxDoc.Save("Sample.pptx");
            pptxDoc.Close();

            Console.ReadLine();
        }
        void OnButtonClicked(object sender, EventArgs e)
        {
            string resourcePath = "";

#if COMMONSB
            resourcePath = "SampleBrowser.Samples.Presentation.Samples.Templates.Template.pptx";
#else
            resourcePath = "SampleBrowser.Presentation.Samples.Templates.Template.pptx";
#endif
            Assembly assembly   = typeof(GettingStarted).GetTypeInfo().Assembly;
            Stream   fileStream = assembly.GetManifestResourceStream(resourcePath);

            //Open a PowerPoint presentation
            IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fileStream);

            //Initialize PresentationRenderer to perform image conversion.
            presentation.PresentationRenderer = new PresentationRenderer();

            string fileName    = null;
            string contentType = null;
            Syncfusion.Presentation.ExportImageFormat imageFormat;

            if (this.jpegButton.IsChecked != null && (bool)this.jpegButton.IsChecked)
            {
                imageFormat = ExportImageFormat.Jpeg;
                fileName    = "Image.jpeg";
                contentType = "image/jpeg";
            }
            else
            {
                imageFormat = ExportImageFormat.Png;
                fileName    = "Image.png";
                contentType = "image/png";
            }

            //Convert PowerPoint slide to image stream.
            Stream stream = presentation.Slides[0].ConvertToImage(imageFormat);

            //Close the PowerPoint Presentation.
            presentation.Close();

            //Reset the stream position.
            stream.Position = 0;
            if (Device.RuntimePlatform == Device.UWP)
            {
                Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save(fileName, contentType, stream as MemoryStream);
            }
            else
            {
                Xamarin.Forms.DependencyService.Get <ISave>().Save(fileName, contentType, stream as MemoryStream);
            }
        }
示例#17
0
        public IActionResult CreateSlide(string image, string header, string content)
        {
            WebClient webClient = new WebClient();

            webClient.DownloadFile(image, "image.jpg");

            //Create a new instance of PowerPoint Presentation file
            IPresentation pptxDoc = Presentation.Create();

            //Add a new slide to file and apply background color
            ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.TitleOnly);

            //Specify the fill type and fill color for the slide background
            slide.Background.Fill.FillType        = FillType.Solid;
            slide.Background.Fill.SolidFill.Color = ColorObject.FromArgb(232, 241, 229);

            //Add title content to the slide by accessing the title placeholder of the TitleOnly layout-slide
            IShape titleShape = slide.Shapes[0] as IShape;

            titleShape.TextBody.AddParagraph(header).HorizontalAlignment = HorizontalAlignmentType.Center;

            //Add description content to the slide by adding a new TextBox
            IShape descriptionShape = slide.AddTextBox(53.22, 141.73, 874.19, 77.70);

            descriptionShape.TextBody.Text = content;

            //Gets a picture as stream.
            FileStream pictureStream = new FileStream("image.jpg", FileMode.Open);

            //Adds the picture to a slide by specifying its size and position.
            slide.Shapes.AddPicture(pictureStream, 499.79, 238.59, 364.54, 192.16);

            //Save the PowerPoint Presentation as stream
            FileStream outputStream = new FileStream("Sample.pptx", FileMode.Create);

            pptxDoc.Save(outputStream);

            //Release all resources from stream
            outputStream.Dispose();

            //Close the PowerPoint presentation
            pptxDoc.Close();

            var displaySlide = new Result
            {
                Title   = header,
                Content = content,
                Link    = image
            };

            return(View(displaySlide));
        }
示例#18
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            string resourcePath = "";

#if COMMONSB
            resourcePath = "SampleBrowser.Samples.Presentation.Samples.Templates.HeaderFooter.pptx";
#else
            resourcePath = "SampleBrowser.Presentation.Samples.Templates.HeaderFooter.pptx";
#endif
            Assembly assembly   = typeof(WriteProtection).GetTypeInfo().Assembly;
            Stream   fileStream = assembly.GetManifestResourceStream(resourcePath);

            //Open a existing PowerPoint presentation
            IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fileStream);

            //Add footers into all the PowerPoint slides.
            foreach (ISlide slide in presentation.Slides)
            {
                //Enable a date and time footer in slide.
                slide.HeadersFooters.DateAndTime.Visible = true;
                //Enable a footer in slide.
                slide.HeadersFooters.Footer.Visible = true;
                //Sets the footer text.
                slide.HeadersFooters.Footer.Text = "Footer";
                //Enable a slide number footer in slide.
                slide.HeadersFooters.SlideNumber.Visible = true;
            }

            //Add header into first slide notes page.
            //Add a notes slide to the slide.
            INotesSlide notesSlide = presentation.Slides[0].AddNotesSlide();
            //Enable a header in notes slide.
            notesSlide.HeadersFooters.Header.Visible = true;
            //Sets the header text.
            notesSlide.HeadersFooters.Header.Text = "Header";

            MemoryStream stream = new MemoryStream();
            presentation.Save(stream);
            presentation.Close();
            stream.Position = 0;
            if (Device.RuntimePlatform == Device.UWP)
            {
                Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("HeaderFooterSample.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream);
            }
            else
            {
                Xamarin.Forms.DependencyService.Get <ISave>().Save("HeaderFooterSample.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream);
            }
        }
        public ActionResult PPTXToPDF(string Browser, string view)
        {
            string basePath = _hostingEnvironment.WebRootPath;

            if (view.Trim() == "INPUT TEMPLATE")
            {
                FileStream    fileStreamInput = new FileStream(basePath + @"/Presentation/Template.pptx", FileMode.Open, FileAccess.Read);
                IPresentation presentation    = Presentation.Open(fileStreamInput);
                MemoryStream  ms = new MemoryStream();

                //Saves the presentation to the memory stream.
                presentation.Save(ms);
                //Set the position of the stream to beginning.
                ms.Position = 0;
                return(File(ms, "application/vnd.openxmlformats-officedocument.presentationml.presentation", "InputTemplate.pptx"));
            }
            else
            {
                FileStream fileStreamInput = new FileStream(basePath + @"/Presentation/Template.pptx", FileMode.Open, FileAccess.Read);
                //Open the existing PowerPoint presentation.
                IPresentation presentation = Presentation.Open(fileStreamInput);

                // Add a custom fallback font collection for Presentation.
                AddFallbackFonts(presentation);

                //Convert the PowerPoint document to PDF document.
                PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation);

                MemoryStream pdfStream = new MemoryStream();

                //Save the converted PDF document to Memory stream.
                pdfDocument.Save(pdfStream);
                pdfStream.Position = 0;

                //Close the PDF document.
                pdfDocument.Close(true);

                //Close the PowerPoint Presentation.
                presentation.Close();

                //Initialize the file stream to download the converted PDF.
                FileStreamResult fileStreamResult = new FileStreamResult(pdfStream, "application/pdf");
                //Set the file name.
                fileStreamResult.FileDownloadName = "Sample.pdf";

                return(fileStreamResult);
            }
        }
        private void CreateInitialPPt()
        {
            String Title, TextDesc;

            Title    = Title_txtBx.Text;
            TextDesc = Txt_Blk.Text;
            string today = DateTime.Now.ToShortDateString();

            //Creates a new ppt doc
            IPresentation ppt_doc = Presentation.Create();

            //Adding a initial slide to the ppt
            ISlide slide = ppt_doc.Slides.Add(SlideLayoutType.PictureWithCaption);

            //Specify the fill type and fill color for the slide background
            slide.Background.Fill.FillType        = FillType.Solid;
            slide.Background.Fill.SolidFill.Color = ColorObject.FromArgb(232, 241, 229);

            //Add title content to the slide by accessing the title placeholder of the TitleOnly layout-slide
            IShape titleShape = slide.Shapes[0] as IShape;

            titleShape.TextBody.AddParagraph(Title).HorizontalAlignment = HorizontalAlignmentType.Center;

            //Adding a TextBox to the slide
            IShape shape = slide.AddTextBox(80, 200, 500, 100);

            shape.TextBody.AddParagraph(TextDesc);

            String imgName = GetImageName();

            imgName = staticFilePath + imgName;
            //Gets a picture as stream.
            Stream pictureStream = File.Open(imgName, FileMode.Open);

            //Adds the picture to a slide by specifying its size and position.
            slide.Shapes.AddPicture(pictureStream, 499.79, 238.59, 364.54, 192.16);

            //Save the ppt
            ppt_doc.Save(Title + ".pptx");

            //Dispose the image stream
            pictureStream.Dispose();

            //closing the ppt
            ppt_doc.Close();
        }
示例#21
0
        bool convertPowerpointToPDF(string source, string destination)
        {
            try
            {
                IPresentation presentation = Presentation.Open(source);

                //Creates an instance of ChartToImageConverter and assigns it to ChartToImageConverter property of Presentation
                presentation.ChartToImageConverter = new ChartToImageConverter();

                //Sets the scaling mode of the chart to best.
                presentation.ChartToImageConverter.ScalingMode = ScalingMode.Best;

                //Instantiates the Presentation to pdf converter settings instance.
                PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();

                //Sets the option for adding hidden slides to converted pdf
                settings.ShowHiddenSlides = false;

                //Sets the slide per page settings; this is optional.
                settings.SlidesPerPage           = SlidesPerPage.One;
                settings.EnablePortableRendering = true;
                //Sets the settings to enable notes pages while conversion.
                settings.PublishOptions = PublishOptions.Slides;

                //Converts the PowerPoint Presentation into PDF document
                PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation, settings);

                //Saves the PDF document
                pdfDocument.Save(destination);

                //Closes the PDF document
                pdfDocument.Close(true);

                //Closes the Presentation
                presentation.Close();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
            }
        }
示例#22
0
        /// <summary>
        /// Decrypt the word document
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void decrpt_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (textBox2.Tag == null)
                {
                    MessageBox.Show("Please browse the Presentation to decrypt", "Input Missing", MessageBoxButton.OK);
                }
                else if (string.IsNullOrEmpty(passwordBox2.Password))
                {
                    MessageBox.Show("Please enter password to decrypt", "Password Missing", MessageBoxButton.OK);
                }
                else
                {
                    //creates instance for the presentation
                    IPresentation presentation = Presentation.Open(textBox2.Tag.ToString(), passwordBox2.Password);
                    //Decrypts the presentation
                    presentation.RemoveEncryption();
                    //Saving the presentation
                    presentation.Save("Decryption.pptx");
                    //Closing the document
                    presentation.Close();

                    if (MessageBox.Show("Do you want to view the decrypted Presentation?", "Decrypted Presentation",
                                        MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                    {
#if !NETCore
                        System.Diagnostics.Process.Start("Decryption.pptx");
#else
                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo = new System.Diagnostics.ProcessStartInfo("Decryption.pptx")
                        {
                            UseShellExecute = true
                        };
                        process.Start();
#endif
                    }
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show("Please enter correct password", "Incorrect password",
                                MessageBoxButton.OK);
            }
        }
        public ActionResult PPTXToImage(string Browser, string view)
        {
            string basePath = _hostingEnvironment.WebRootPath;

            if (view.Trim() == "INPUT TEMPLATE")
            {
                FileStream    fileStreamInput = new FileStream(basePath + @"/Presentation/Template.pptx", FileMode.Open, FileAccess.Read);
                IPresentation presentation    = Presentation.Open(fileStreamInput);
                MemoryStream  ms = new MemoryStream();

                //Saves the presentation to the memory stream.
                presentation.Save(ms);
                //Set the position of the stream to beginning.
                ms.Position = 0;
                return(File(ms, "application/vnd.openxmlformats-officedocument.presentationml.presentation", "InputTemplate.pptx"));
            }
            else
            {
                FileStream fileStreamInput = new FileStream(basePath + @"/Presentation/Template.pptx", FileMode.Open, FileAccess.Read);
                //Open the existing PowerPoint  presentation.
                IPresentation presentation = Presentation.Open(fileStreamInput);

                //Initialize PresentationRenderer to perform image conversion.
                presentation.PresentationRenderer = new PresentationRenderer();

                // Add a custom fallback font collection for Presentation.
                AddFallbackFonts(presentation);

                //Convert PowerPoint slide to image stream.
                Stream stream = presentation.Slides[0].ConvertToImage(ExportImageFormat.Jpeg);

                //Reset the stream position
                stream.Position = 0;

                //Close the PowerPoint Presentation.
                presentation.Close();

                //Initialize the file stream to download the converted image.
                FileStreamResult fileStreamResult = new FileStreamResult(stream, "image/jpeg");
                //Set the file name.
                fileStreamResult.FileDownloadName = "Slide1.jpg";

                return(fileStreamResult);
            }
        }
        void OnButtonClicked(object sender, EventArgs e)
        {
            string   resourcePath = "SampleBrowser.Samples.Presentation.Templates.HeaderFooter.pptx";
            Assembly assembly     = Assembly.GetExecutingAssembly();
            Stream   fileStream   = assembly.GetManifestResourceStream(resourcePath);

            //Create an instance for PowerPoint
            IPresentation presentation = Presentation.Open(fileStream);

            //Add footers into all the PowerPoint slides.
            foreach (ISlide slide in presentation.Slides)
            {
                //Enable a date and time footer in slide.
                slide.HeadersFooters.DateAndTime.Visible = true;
                //Enable a footer in slide.
                slide.HeadersFooters.Footer.Visible = true;
                //Sets the footer text.
                slide.HeadersFooters.Footer.Text = "Footer";
                //Enable a slide number footer in slide.
                slide.HeadersFooters.SlideNumber.Visible = true;
            }

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

            //Enable a header in notes slide.
            notesSlide.HeadersFooters.Header.Visible = true;
            //Sets the header text.
            notesSlide.HeadersFooters.Header.Text = "Header";

            MemoryStream stream = new MemoryStream();

            presentation.Save(stream);
            presentation.Close();
            stream.Position = 0;

            if (stream != null)
            {
                SaveiOS iOSSave = new SaveiOS();
                iOSSave.Save("HeaderFooterPresentation.pptx", "application/mspowerpoint", stream);
            }
        }
示例#25
0
        private void GeneratePPT()
        {
            //Create a new PowerPoint presentation
            IPresentation powerpointDoc = Presentation.Create();

            ISlide slide = powerpointDoc.Slides.Add(SlideLayoutType.TitleOnly);


            IShape titleShape = slide.Shapes[0] as IShape;

            titleShape.TextBody.AddParagraph(TitleInput.Text).HorizontalAlignment = HorizontalAlignmentType.Center;

            //Add a text to the textbox.
            IShape descriptionShape = slide.AddTextBox(53.22, 141.73, 874.19, 77.70);

            descriptionShape.TextBody.Text = BodyText.Text;

            Console.WriteLine(imgListView.SelectedItems.Count);

            // Grab checked images

            int x = 170, y = 0, indx = 0;

            foreach (int i in imgListView.CheckedIndices)
            {
                slide.Shapes.AddPicture(ToStream(listImg[i + 1]), x, y, 140, 140);
                x += 140;
                if (indx % 5 == 0)
                {
                    y += 140;
                    x  = 170;
                }
                indx++;
            }

            //Save the PowerPoint presentation
            powerpointDoc.Save("Result.pptx");

            //Close the PowerPoint presentation
            powerpointDoc.Close();

            DialogResult res = MessageBox.Show("Result saved as Result.pptx");
        }
示例#26
0
        void OnConvertClicked(object sender, EventArgs e)
        {
            string   resourcePath = "SampleBrowser.Samples.Presentation.Templates.Template.pptx";
            Assembly assembly     = Assembly.GetExecutingAssembly();
            Stream   fileStream   = assembly.GetManifestResourceStream(resourcePath);
            //Open the existing PowerPoint Presentation.
            IPresentation presentation = Presentation.Open(fileStream);

            //Initialize PresentationRenderer to perform image conversion.
            presentation.PresentationRenderer = new PresentationRenderer();

            string fileName    = null;
            string ContentType = null;

            Syncfusion.Presentation.ExportImageFormat imageFormat;
            if (jpegButton != null && (bool)jpegButton.IsChecked)
            {
                imageFormat = ExportImageFormat.Jpeg;
                fileName    = "Image.jpeg";
                ContentType = "image/jpeg";
            }
            else
            {
                imageFormat = ExportImageFormat.Png;
                fileName    = "Image.png";
                ContentType = "image/png";
            }

            //Convert PowerPoint slide to image.
            Stream stream = presentation.Slides[0].ConvertToImage(imageFormat);

            //Reset the stream position
            stream.Position = 0;

            //Close the PowerPoint Presentation.
            presentation.Close();

            if (stream != null)
            {
                SaveiOS iOSSave = new SaveiOS();
                iOSSave.Save(fileName, ContentType, stream as MemoryStream);
            }
        }
        private void btnOpenEmbeddedFile_Click(object sender, EventArgs e)
        {
#if !NETCore
            string filePath = @"..\..\..\..\..\..\Common\Data\Presentation\EmbeddedOleObject.pptx";
#else
            string filePath = @"..\..\..\..\..\..\..\Common\Data\Presentation\EmbeddedOleObject.pptx";
#endif
            IPresentation pptxDoc = Presentation.Open(filePath);
            //Gets the first slide of the Presentation
            ISlide slide = pptxDoc.Slides[0];
            //Gets the Ole Object of the slide
            IOleObject oleObject = slide.Shapes[2] as IOleObject;
            //Gets the file data of embedded Ole Object
            byte[] array = oleObject.ObjectData;
            //Gets the file name of embedded Ole Object
            string outputFile = oleObject.FileName;

            //Save the extracted Ole data into file system
            MemoryStream memoryStream = new MemoryStream(array);
            FileStream   fileStream   = File.Create(outputFile);
            memoryStream.CopyTo(fileStream);
            memoryStream.Dispose();
            fileStream.Dispose();
            //Close the presentation
            pptxDoc.Close();

            if (System.Windows.MessageBox.Show("Do you want to view the extracted Embedded file?", "Extracted Embedded OLE File",
                                               MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
            {
#if !NETCore
                System.Diagnostics.Process.Start(outputFile);
#else
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo = new System.Diagnostics.ProcessStartInfo(outputFile)
                {
                    UseShellExecute = true
                };
                process.Start();
#endif
                this.Close();
            }
        }
示例#28
0
        /// <summary>
        /// Encrypt the word document
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void encrypt_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(passwordBox1.Password))
                {
                    MessageBox.Show("Please enter password to protect", "Password Missing", MessageBoxButton.OK);
                }
                else
                {
                    //Creates instance for presentation
                    IPresentation presentation = Presentation.Open(textBox1.Tag.ToString(), passwordBox1.Password);
                    //Encrypts the presentation
                    presentation.Encrypt(passwordBox1.Password);
                    //Saving the presentation
                    presentation.Save("Encryption.pptx");
                    //Closing the presentation
                    presentation.Close();

                    if (MessageBox.Show("Do you want to view the encrypted Presentation?", "Encrypted Presentation",
                                        MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                    {
#if !NETCore
                        System.Diagnostics.Process.Start("Encryption.pptx");
#else
                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo = new System.Diagnostics.ProcessStartInfo("Encryption.pptx")
                        {
                            UseShellExecute = true
                        };
                        process.Start();
#endif
                    }
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show("This file could not be encrypted , please contact Syncfusion Direct-Trac system at http://www.syncfusion.com/support/default.aspx for any queries. ", "OOPS..Sorry!",
                                MessageBoxButton.OK);
            }
        }
示例#29
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            string resourcePath = "SampleBrowser.Samples.Presentation.Templates.Animation.pptx";
			Assembly assembly = Assembly.GetExecutingAssembly();
            Stream fileStream = assembly.GetManifestResourceStream(resourcePath);

            IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fileStream);
			
           //Modify the existing animation
            CreateAnimationWithShape(presentation);

            MemoryStream stream = new MemoryStream();
            presentation.Save(stream);
            presentation.Close();
            stream.Position = 0;
			if (stream != null)
			{
				SaveAndroid androidSave = new SaveAndroid ();
				androidSave.Save ("CreateAnimationSample.pptx", "application/powerpoint", stream, m_context);
			}
        }
        public void GotoImage()
        {
            var    documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string fileDir   = Path.Combine(documents, @"AIMobileOffice/MSPowerPoint");

            Directory.CreateDirectory(fileDir);
            string filePath = Path.Combine(documents, @"AIMobileOffice/MSPowerPoint");

            int customWidth  = 5000;
            int customHeight = 2800;

            for (int j = 0; j < presentation.Slides.Count; j++)
            {
                Stream stream = presentation.Slides[j].ConvertToImage(Syncfusion.Drawing.ImageFormat.Bmp);
                Bitmap bitmap = new Bitmap(customWidth, customHeight, PixelFormat.Format32bppPArgb);

                Graphics graphic = Graphics.FromImage(bitmap);
                bitmap.SetResolution(graphic.DpiX, graphic.DpiY);

                graphic.DrawImage(System.Drawing.Image.FromStream(stream), new Rectangle(0, 0, bitmap.Width, bitmap.Height));

                bitmap.Save(filePath + j.ToString());
            }

            presentation.Close();

            // presentation.ChartToImageConverter = new ChartToImageConverter();

            //  presentation.ChartToImageConverter.ScalingMode = Syncfusion.OfficeChart.ScalingMode.Best;

            // Image[] images = presentation.RenderAsImages(Syncfusion.Drawing.ImageType.Metafile); //convert format (size)


            //int i = 0;
            //foreach (Image image in images)
            //{
            //    image.Save(filePath + i.ToString());
            //    i++;
            //}
        }