Exemplo n.º 1
0
        void pdfBackroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();
                settings.ShowHiddenSlides = true;
                using (IPresentation presentation = Presentation.Open(filePath))
                {
                    using (PdfDocument doc = PresentationToPdfConverter.Convert(presentation, settings))
                    {
                        doc.Save(@"Sample.pdf");
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("This PowerPoint Presentation cannot be converted to PDF properly, please contact Syncfusion support");
                return;
            }

            if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
            {
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf")
                {
                    UseShellExecute = true
                };
                process.Start();
            }
        }
Exemplo n.º 2
0
        public ActionResult Notes(string Browser, FormCollection form)
        {
            Stream sourceFile = new FileStream(ResolveApplicationDataPath(@"..\Presentation\Images.pptx"), FileMode.Open, FileAccess.Read, FileShare.Read);

            //Opens a PowerPoint presentation
            IPresentation presentation = Presentation.Open(sourceFile);

            //  Method call to create slides
            SlideWithNotes1(presentation);
            SlideWithNotes2(presentation);
            string choice = form["File Type"];

            if (choice == "PPTX")
            {
                //  Saves the presentation
                return(new PresentationResult(presentation, "Sample.pptx", HttpContext.ApplicationInstance.Response));
            }

            else
            {
                presentation.ChartToImageConverter = new ChartToImageConverter();
                PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();
                //Select the notes pages option to convert the notes content to pdf.
                settings.PublishOptions = PublishOptions.NotesPages;
                PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation, settings);

                //Saves the pdf document
                //return new Syncfusion.Mvc.Pdf.PdfResult(pdfDocument, "PPTXToPDF.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save);
                MemoryStream stream = new MemoryStream();
                pdfDocument.Save(stream);
                stream.Position = 0;
                return(File(stream, "application/pdf", "PPTXToPDF.pdf"));
            }
        }
        public ActionResult CustomizingAppearance(string Browser, FormCollection form)
        {
            Stream        readFile     = new FileStream(ResolveApplicationDataPath(@"SmartArts.pptx"), FileMode.Open, FileAccess.Read, FileShare.Read);
            IPresentation presentation = Syncfusion.Presentation.Presentation.Open(readFile);

            //Method call to edit slides
            SmartArt5(presentation);
            SmartArt6(presentation);
            SmartArt7(presentation);

            string choice = form["File Type"];

            if (choice == "PPTX")
            {
                //  Saves the presentation
                return(new PresentationResult(presentation, "SmartArtSample.pptx", HttpContext.ApplicationInstance.Response));
            }
            else
            {
                PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();
                settings.ShowHiddenSlides = true;

                //Instance to create pdf document from presentation
                PdfDocument doc = PresentationToPdfConverter.Convert(presentation, settings);

                //Saves the pdf document
                //return new Syncfusion.Mvc.Pdf.PdfResult(doc, "PPTXToPDF.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save);
                MemoryStream stream = new MemoryStream();
                doc.Save(stream);
                stream.Position = 0;
                return(File(stream, "application/pdf", "PPTXToPDF.pdf"));
            }
        }
        private void PdfBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();

            settings.ShowHiddenSlides = true;
            IPresentation presentation = Presentation.Open(openFileDialog1.FileName);

            presentation.ChartToImageConverter             = new ChartToImageConverter();
            presentation.ChartToImageConverter.ScalingMode = Syncfusion.OfficeChart.ScalingMode.Best;
            PdfDocument doc = PresentationToPdfConverter.Convert(presentation, settings);

            doc.Save(@"Output/Sample.pdf");
            DialogResult messageBoxResult = MessageBox.Show("Do you want to view the generated pdf file ?", "File Creation", MessageBoxButtons.YesNo);

            if (messageBoxResult == DialogResult.Yes)
            {
#if !NETCORE
                System.Diagnostics.Process.Start(Path.GetFullPath(@"Output/Sample.pdf"));
#else
                ProcessStartInfo psi = new ProcessStartInfo
                {
                    FileName        = "cmd",
                    WindowStyle     = ProcessWindowStyle.Hidden,
                    UseShellExecute = false,
                    CreateNoWindow  = true,
                    Arguments       = "/c start Output/Sample.pdf"
                };
                Process.Start(psi);
#endif
            }
        }
        public string[] ConvertToPDF([FromBody] FileManagerDirectoryContent args)
        {
            string fileLocation = this.baseLocation + args.Path.Replace("/", "\\");

            // If document get open from zip file, we have maintained the extracted document path in TargetPath property.
            if (args.TargetPath != null)
            {
                fileLocation = args.TargetPath;
            }
            List <string> returnArray = new List <string>();

            using FileStream fs = new FileStream(fileLocation, FileMode.Open, FileAccess.Read);
            //Open the existing presentation
            IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fs);
            //Convert the PowerPoint document to PDF document.
            PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation);
            //Save the document as a stream and retrun the stream
            MemoryStream stream = new MemoryStream();

            //Save the created PowerPoint document to MemoryStream
            pdfDocument.Save(stream);
            stream.Position = 0;
            returnArray.Add("data:application/pdf;base64," + Convert.ToBase64String(stream.ToArray()));
            //Dispose the document objects.
            presentation.Dispose();
            pdfDocument.Dispose();
            stream.Dispose();
            return(returnArray.ToArray());
        }
Exemplo n.º 6
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);
            }
        }
        private static Control OpenPowerpoint(string path)
        {
            var ppt = Presentation.Open(path);

            ppt.ChartToImageConverter = new ChartToImageConverter();

            var settings = new PresentationToPdfConverterSettings
            {
                OptimizeIdenticalImages = true,
                ShowHiddenSlides        = true
            };

            var pdf = PresentationToPdfConverter.Convert(ppt, settings);

            var viewer = new PdfViewerControl();

            var tempPdf = new MemoryStream();

            pdf.Save(tempPdf);
            pdf.Close(true);
            pdf.Dispose();
            ppt.Close();
            ppt.Dispose();

            viewer.Dispatcher.BeginInvoke(new Action(() =>
            {
                viewer.LoadPdf(tempPdf);
                tempPdf.Dispose();
            }), DispatcherPriority.Loaded);

            return(viewer);
        }
        private void btnCreatePdf_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //Opens the specified presentation
                IPresentation presentation = Presentation.Open(txtFile.Tag.ToString());

                //To set each slide in a pdf page.
                PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();

                settings.ShowHiddenSlides = true;
                //Instance to create pdf document from presentation
                PdfDocument doc = PresentationToPdfConverter.Convert(presentation, settings);

                //Saves the pdf document
                doc.Save("Sample.pdf");
                if (System.Windows.MessageBox.Show("Do you want to view the PDF document?", "Pdf document created",
                                                   MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                {
                    System.Diagnostics.Process.Start("Sample.pdf");
                    this.Close();
                }
            }
            catch (Exception exception)
            {
                System.Windows.MessageBox.Show("This file could not be converted, please contact Syncfusion Direct-Trac system at http://www.syncfusion.com/support/default.aspx for any queries. ", "OOPS..Sorry!",
                                               MessageBoxButton.OKCancel);
                this.Close();
            }
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
        public ActionResult PPTXToPdf(string Browser)
        {
            string file = ResolveApplicationDataPath("Syncfusion Presentation.pptx");
            //Opens the specified presentation
            IPresentation presentation = Presentation.Open(file);

            presentation.ChartToImageConverter             = new ChartToImageConverter();
            presentation.ChartToImageConverter.ScalingMode = Syncfusion.OfficeChart.ScalingMode.Best;

            PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();

            settings.ShowHiddenSlides        = true;
            settings.EnablePortableRendering = true;

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

            //Instance to create pdf document from presentation
            PdfDocument  doc    = PresentationToPdfConverter.Convert(presentation, settings);
            MemoryStream stream = new MemoryStream();

            doc.Save(stream);
            stream.Position = 0;
            //return new Syncfusion.Mvc.Pdf.PdfResult(doc, "PPTXToPDF.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save);
            return(File(stream, "application/pdf", "PPTXToPDF.pdf"));
        }
Exemplo n.º 11
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);
     }
 }
        public ActionResult SmartArtCreation(FormCollection form)
        {
            IPresentation presentation = Presentation.Create();

            //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides].

            //Method call to edit slides
            SmartArt1(presentation);
            SmartArt2(presentation);
            SmartArt3(presentation);
            SmartArt4(presentation);
            string choice = form["File Type"];

            if (choice == "PPTX")
            {
                //  Saves the presentation
                return(new PresentationResult(presentation, "SmartArtSample.pptx", HttpContext.ApplicationInstance.Response));
            }
            else
            {
                PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();
                settings.ShowHiddenSlides = true;

                //Instance to create pdf document from presentation
                PdfDocument doc = PresentationToPdfConverter.Convert(presentation, settings);

                //Saves the pdf document
                return(new Syncfusion.Mvc.Pdf.PdfResult(doc, "PPTXToPDF.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
            }
        }
Exemplo n.º 13
0
        private void btnCreatePresn_Click(object sender, EventArgs e)
        {
            string input = @"..\..\..\..\..\..\Common\Data\Presentation\Images.pptx";

#if NETCore
            input = @"..\..\..\..\..\..\..\Common\Data\Presentation\Images.pptx";
#endif
            IPresentation presentation = Presentation.Open(input);
            CreateSlide1(presentation);
            CreateSlide2(presentation);

#if !Notes_2008
            if (btnCreatePresentation.IsChecked.Value)
#endif
            {
                presentation.Save("NotesSample.pptx");

                if (System.Windows.MessageBox.Show("Do you want to view the generated Presentation?", "Presentation Created",
                                                   MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                {
#if !NETCore
                    System.Diagnostics.Process.Start("NotesSample.pptx");
#else
                    System.Diagnostics.Process process = new System.Diagnostics.Process();
                    process.StartInfo = new System.Diagnostics.ProcessStartInfo("NotesSample.pptx")
                    {
                        UseShellExecute = true
                    };
                    process.Start();
#endif
                }
            }
#if !Notes_2008
            else if (btnPresentationToPDF.IsChecked.Value)
            {
                presentation.ChartToImageConverter = new ChartToImageConverter();
                PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();
                //Select the notes pages option to convert the notes content to pdf.
                settings.PublishOptions = PublishOptions.NotesPages;
                PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation, settings);
                pdfDocument.Save("NotesSample.pdf");
                if (System.Windows.MessageBox.Show("Do you want to view the generated Pdf?", "PDF Created",
                                                   MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                {
#if !NETCore
                    System.Diagnostics.Process.Start("NotesSample.pdf");
#else
                    System.Diagnostics.Process process = new System.Diagnostics.Process();
                    process.StartInfo = new System.Diagnostics.ProcessStartInfo("NotesSample.pdf")
                    {
                        UseShellExecute = true
                    };
                    process.Start();
#endif
                    this.Close();
                }
            }
#endif
        }
Exemplo n.º 14
0
        private void btnCreateImage_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides].
                using (IPresentation presentation = Presentation.Create())
                {
                    //Method call to create SmartArt and add it into slides.
                    CreateSlide1(presentation);
                    CreateSlide2(presentation);
                    CreateSlide3(presentation);
                    CreateSlide4(presentation);
                    if (this.radioButton.IsChecked.Value)
                    {
                        presentation.Save("SmartArtCreation.pptx");
                        if (System.Windows.MessageBox.Show("Do you want to view the generated PowerPoint Presentation?", "SmartArt Creation",
                                                           MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                        {
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("SmartArtCreation.pptx")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
                        }
                    }
                    else if (this.radioButton1.IsChecked.Value)
                    {
                        //To set each slide in a pdf page.
                        PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();

                        settings.ShowHiddenSlides = true;

                        //Instance to create pdf document from presentation
                        using (PdfDocument doc = PresentationToPdfConverter.Convert(presentation, settings))
                        {
                            //Saves the pdf document
                            doc.Save("Sample.pdf");
                        }
                        if (System.Windows.MessageBox.Show("Do you want to view the generated PDF document?", "SmartArt Creation",
                                                           MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                        {
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                System.Windows.MessageBox.Show("This file could not be converted, please contact Syncfusion Direct-Trac system at http://www.syncfusion.com/support/default.aspx for any queries. ", "OOPS..Sorry!",
                                               MessageBoxButton.OK);
            }
        }
Exemplo n.º 15
0
        /// <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);
            }
        }
Exemplo n.º 16
0
        private void btnCreatePresn_Click(object sender, EventArgs e)
        {
            try
            {
                string input = @"..\..\..\..\..\..\..\Common\Data\Presentation\SmartArts.pptx";
                IPresentation presentation = Presentation.Open(input);
                //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides].

                //Method call to edit slides
                CreateSlide1(presentation);
                CreateSlide2(presentation);
                CreateSlide3(presentation);
                if (this.radioButton1.Checked)
                {
                    //Saves the presentation as pptx format.
                    presentation.Save("SmartArtSample.pptx");

                    if (MessageBox.Show("Do you want to view the generated PowerPoint Presentation?", "PowerPoint Presentation Created",
                        MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {

                        System.Diagnostics.Process.Start("SmartArtSample.pptx");
                        this.Close();
                    }
                }
                else if (this.radioButton2.Checked)
                {
                    //To set each slide in a pdf page.
                    PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();

                    settings.ShowHiddenSlides = true;

                    //Instance to create pdf document from presentation
                    PdfDocument doc = PresentationToPdfConverter.Convert(presentation, settings);

                    //Saves the pdf document
                    doc.Save("Sample.pdf");
                    if (MessageBox.Show("Do you want to view the PDF document?", "Pdf docuemnt created",
                            MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        System.Diagnostics.Process.Start("Sample.pdf");

                    }
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show("This file could not be converted , please contact Syncfusion Direct-Trac system at http://www.syncfusion.com/support/default.aspx for any queries. ", "OOPS..Sorry!",
                        MessageBoxButtons.OK);

            }
        }
Exemplo n.º 17
0
        protected void btnDocToPdf_Click(object sender, EventArgs e)
        {
            if (this.FileUpload1.HasFile)
            {
                string fileName = Path.GetFileNameWithoutExtension(this.FileUpload1.PostedFile.FileName);
                string ext      = Path.GetExtension(this.FileUpload1.PostedFile.FileName).ToLower();
                if (ext == ".pptx")
                {
                    //Convert the input powerpoint document to a PDF file
                    # region Convert PPTX to PDF
                    Stream readFile = this.FileUpload1.PostedFile.InputStream;
                    try
                    {
                        //Opens the specified presentation
                        IPresentation presentation = Presentation.Open(readFile);
                        presentation.ChartToImageConverter             = new ChartToImageConverter();
                        presentation.ChartToImageConverter.ScalingMode = Syncfusion.OfficeChart.ScalingMode.Best;

                        //To set each slide in a pdf page.
                        PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();

                        settings.ShowHiddenSlides = true;

                        //Instance to create pdf document from presentation
                        //  presentation.ChartToImageConverter = new ChartToImageConverter();
                        PdfDocument doc = PresentationToPdfConverter.Convert(presentation, settings);

                        //Saves the pdf document
                        if (this.CheckBox1.Checked)
                        {
                            doc.Save(fileName + ".pdf", Response, HttpReadType.Open);
                        }
                        else
                        {
                            doc.Save(fileName + ".pdf", Response, HttpReadType.Save);
                        }
                        readFile.Close();
                    }
                    catch (Exception)
                    {
                        this.label1.Text = "The input document could not be processed, Could you please email the document to [email protected] for troubleshooting";
                    }
                    # endregion
                }
                else
                {
                    this.label1.Text = "Please choose pptx file to convert to PDF";
                }
            }
        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);
            }
        }
Exemplo n.º 19
0
        private void btnCreateImage_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //Opens the specified presentation
                IPresentation presentation = Presentation.Open(@"..\..\..\..\..\..\..\Common\Data\Presentation\SmartArts.pptx");

                //Method call to edit slides
                CreateSlide1(presentation);
                CreateSlide2(presentation);
                CreateSlide3(presentation);
                if (this.radioButton.IsChecked.Value)
                {
                    presentation.Save("SmartArtSample.pptx");
                    if (System.Windows.MessageBox.Show("Do you want to view the generated PowerPoint Presentation?", "SmartArt Modification",
                                                       MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                    {
                        System.Diagnostics.Process.Start("SmartArtSample.pptx");
                        this.Close();
                    }
                }
                else if (this.radioButton1.IsChecked.Value)
                {
                    //To set each slide in a pdf page.
                    PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();

                    settings.ShowHiddenSlides = true;

                    //Instance to create pdf document from presentation
                    PdfDocument doc = PresentationToPdfConverter.Convert(presentation, settings);

                    //Saves the pdf document
                    doc.Save("Sample.pdf");
                    if (System.Windows.MessageBox.Show("Do you want to view the generated PDF document?", "SmartArt Modification",
                                                       MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                    {
                        System.Diagnostics.Process.Start("Sample.pdf");
                    }
                }
            }
            catch (Exception exception)
            {
                System.Windows.MessageBox.Show("This file could not be converted, please contact Syncfusion Direct-Trac system at http://www.syncfusion.com/support/default.aspx for any queries. ", "OOPS..Sorry!",
                                               MessageBoxButton.OK);
                this.Close();
            }
        }
        /// <summary>
        /// Converts the PowerPoint presentation (PPTX) to PDF document.
        /// </summary>
        public HttpResponseMessage ConvertToPDF()
        {
            using (Stream stream = Request.Content.ReadAsStreamAsync().Result)
            {
                // Creates new MemoryStream instance for output PDF.
                MemoryStream pdfStream = new MemoryStream();
                //Opens the PowerPoint presentation (PPTX) from stream
                using (IPresentation presentation = Presentation.Open(stream))
                {
                    //Initializes the ChartToImageConverter for converting charts during PPTX to PDF conversion
                    presentation.ChartToImageConverter             = new ChartToImageConverter();
                    presentation.ChartToImageConverter.ScalingMode = Syncfusion.OfficeChart.ScalingMode.Best;

                    //Creates an instance of the PresentationToPdfConverterSettings
                    PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();
                    settings.ShowHiddenSlides = true;
                    //Converts PowerPoint presentation (PPTX) into PDF document
                    PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation, settings);
                    //Adds watermark at top left corner of first page in the generated PDF document, to denote it is generated using demo web service
                    //If you want to remove this watermark, please comment or delete the codes within below "if" statement
                    if (pdfDocument.Pages.Count > 0)
                    {
                        PdfPage pdfPage = pdfDocument.Pages[0];
                        //Create PDF font and PDF font style using Font.
                        Font    font    = new Font("Times New Roman", 12f, FontStyle.Regular);
                        PdfFont pdfFont = new PdfTrueTypeFont(font, false);
                        //Create a new pdf brush to draw the rectangle.
                        PdfBrush pdfBrush = new PdfSolidBrush(Color.White);
                        //Draw rectangle in the current page.
                        pdfPage.Graphics.DrawRectangle(pdfBrush, 0f, 0f, 228f, 20.65f);
                        //Create a new brush to draw the text.
                        pdfBrush = new PdfSolidBrush(Color.Red);
                        //Draw text in the current page.
                        pdfPage.Graphics.DrawString("Created by Syncfusion – Presentation library", pdfFont, pdfBrush, 6f, 4f);
                    }
                    // Saves the PDF document to stream.
                    pdfDocument.Save(pdfStream);
                    pdfStream.Position = 0;
                    pdfDocument.Close(true);
                    // Creates HttpResponseMessage to return result with output PDF stream.
                    HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
                    result.Content = new StreamContent(pdfStream);
                    result.Content.Headers.ContentLength = pdfStream.Length;
                    return(result);
                }
            }
        }
Exemplo n.º 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
            {
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Create a simple Presentation document
        /// </summary>
        /// <returns>Return the created Presentation document as stream</returns>
        public MemoryStream PDFConversion()
        {
            //Open the existing presentation
            FileStream    fileStreamInput = new FileStream(ResolveApplicationPath("template.pptx"), FileMode.Open, FileAccess.Read);
            IPresentation presentation    = Syncfusion.Presentation.Presentation.Open(fileStreamInput);

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

            //Save the document as a stream and retrun the stream
            using (MemoryStream stream = new MemoryStream())
            {
                //Save the created PowerPoint document to MemoryStream
                pdfDocument.Save(stream);
                stream.Position = 0;
                return(stream);
            }
        }
Exemplo n.º 23
0
        public ActionResult PPTXToPdf(string Browser)
        {
            string file = ResolveApplicationDataPath("Syncfusion Presentation.pptx");
            //Opens the specified presentation
            IPresentation presentation = Presentation.Open(file);

            presentation.ChartToImageConverter             = new ChartToImageConverter();
            presentation.ChartToImageConverter.ScalingMode = Syncfusion.OfficeChart.ScalingMode.Best;

            PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();

            settings.ShowHiddenSlides = true;

            //Instance to create pdf document from presentation
            PdfDocument doc = PresentationToPdfConverter.Convert(presentation, settings);

            //Saves the pdf document
            return(new Syncfusion.Mvc.Pdf.PdfResult(doc, "PPTXToPDF.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
        }
Exemplo n.º 24
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);
        }
Exemplo n.º 25
0
        protected void PdfExport_Click(object sender, ImageClickEventArgs e)
        {
            string filename = this.PathName;
            Stream file     = ResolvePath(filename);

            IPresentation presentation = Presentation.Open(file);

            presentation.ChartToImageConverter = new ChartToImageConverter();

            //To set each slide in a pdf page.
            PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();

            settings.ShowHiddenSlides = true;

            //Instance to create pdf document from presentation
            PdfDocument doc = PresentationToPdfConverter.Convert(presentation, settings);

            string path = Path.GetFileNameWithoutExtension(filename).Replace(" ", "_");

            //Saves the pdf document
            doc.Save(path + ".pdf", Response, HttpReadType.Save);
        }
Exemplo n.º 26
0
        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);

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

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

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

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

            if (Device.RuntimePlatform == Device.UWP)
            {
                Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("PPTXToPDF.pdf", "application/pdf", pdfStream);
            }
            else
            {
                Xamarin.Forms.DependencyService.Get <ISave>().Save("PPTXToPDF.pdf", "application/pdf", pdfStream);
            }
        }
Exemplo n.º 27
0
 public byte[] PresentationToPDF(Stream file)
 {
     _logger.LogDebug($"Start convert presentation file");
     byte[] buff;
     try
     {
         using (IPresentation presentation = Presentation.Open(file))
             using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation))
                 using (MemoryStream memoryStream = new MemoryStream())
                 {
                     pdfDocument.Save(memoryStream);
                     memoryStream.Position = 0;
                     buff = memoryStream.ToArray();
                     _logger.LogDebug("FileInfoPDFService.PresentationToPDF....OK");
                     return(buff);
                 }
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
     }
     return(null);
 }
Exemplo n.º 28
0
        void pdfBackroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();
                settings.ShowHiddenSlides = true;
                IPresentation presentation = Presentation.Open(filePath);
                presentation.ChartToImageConverter             = new ChartToImageConverter();
                presentation.ChartToImageConverter.ScalingMode = Syncfusion.OfficeChart.ScalingMode.Best;
                PdfDocument doc = PresentationToPdfConverter.Convert(presentation, settings);
                doc.Save(@"Sample.pdf");
                doc.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("This PowerPoint Presentation cannot be converted to PDF properly, please contact Syncfusion support");
                return;
            }

            if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
            {
#if !NETCORE
                Process.Start("Sample.pdf");
#else
                ProcessStartInfo psi = new ProcessStartInfo
                {
                    FileName        = "cmd",
                    WindowStyle     = ProcessWindowStyle.Hidden,
                    UseShellExecute = false,
                    CreateNoWindow  = true,
                    Arguments       = "/c start Sample.pdf"
                };
                Process.Start(psi);
#endif
            }
        }
Exemplo n.º 29
0
        void pdfBackroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();
                settings.ShowHiddenSlides = true;
                IPresentation presentation = Presentation.Open(filePath);
                presentation.ChartToImageConverter             = new ChartToImageConverter();
                presentation.ChartToImageConverter.ScalingMode = Syncfusion.OfficeChart.ScalingMode.Best;
                PdfDocument doc = PresentationToPdfConverter.Convert(presentation, settings);
                doc.Save(@"Sample.pdf");
                doc.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("This PowerPoint Presentation cannot be converted to PDF properly, please contact Syncfusion support");
                return;
            }

            if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
            {
                Process.Start("Sample.pdf");
            }
        }
Exemplo n.º 30
0
        public string GeneratePdf(string value, string type, string authKey)
        {
            if (!_authKey.Equals(authKey))
            {
                throw new AuthenticationException("AuthKey not valid");
            }
            PdfDocument  pdf;
            MemoryStream stream;

            switch (type)
            {
            // Word
            case ".doc":
            case ".docx":
            case ".docm":
            case ".dotm":
            case ".rtf":
            case ".dot":
            case ".dotx":
                // Retrieve the Blob Uri as a String
                using (WebClient webClient = new WebClient())
                {
                    try
                    {
                        // Retrive the Blob URI (Document) and convert it into a bytearray.
                        // From there it is Base-64 encoded for sending via Service call.
                        byte[] bytes = webClient.DownloadData(value);
                        logger.Info($"111 Loading Word Document with value: {value}");
                        //Loading word document
                        WordDocument document = new WordDocument(new MemoryStream(bytes));
                        logger.Info("Created Word Document");
                        DocToPDFConverter conv = new DocToPDFConverter();
                        //Converts the word document to pdf
                        pdf = conv.ConvertToPDF(document);
                        logger.Info("Converted to PDF");
                        stream = new MemoryStream();
                        //Saves the Pdf document to stream
                        pdf.Save(stream);
                        logger.Info("Saved PDF to Stream");
                        //Sets the stream position
                        stream.Position = 0;
                        pdf.Close();
                        document.Close();
                        //Returns the stream data as Base 64 string
                        string returnData = Convert.ToBase64String(stream.ToArray());
                        logger.Info($"Returing converted stream as Base 64 data: {returnData}");

                        return(returnData);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex);
                        throw;
                    }
                }
            // Clean up old files

            // Excel
            case ".xlsx":
            case ".xlsm":
            case ".xlsb":
            case ".xls":
            case ".xltx":
            case ".csv":
                // Retrieve the Blob Uri as a String
                using (WebClient webClient = new WebClient())
                {
                    try
                    {
                        // Retrive the Blob URI (Document) and convert it into a bytearray.
                        // From there it is Base-64 encoded for sending via Service call.
                        byte[] bytes = webClient.DownloadData(value);

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

                        application.ChartToImageConverter = new ChartToImageConverter();

                        IWorkbook workbook =
                            application.Workbooks.Open(new MemoryStream(bytes), ExcelOpenType.Automatic);

                        ExcelToPdfConverter convert = new ExcelToPdfConverter(workbook);
                        pdf    = convert.Convert();
                        stream = new MemoryStream();

                        //Saves the Pdf document to stream
                        pdf.Save(stream);
                        //Sets the stream position
                        stream.Position = 0;
                        pdf.Close();
                        workbook.Close();
                        //Returns the stream data as Base 64 string
                        return(Convert.ToBase64String(stream.ToArray()));
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex);
                        throw;
                    }
                }

            // PowerPoint
            case ".pptx":
            case ".pptm":
            case ".ppt":
            case ".potx":
            case ".ppsx":
            case ".potm":
            case ".pot":
            case ".ppsm":
            case ".pps":
                // Retrieve the Blob Uri as a String
                using (WebClient webClient = new WebClient())
                {
                    try
                    {
                        // Retrive the Blob URI (Document) and convert it into a bytearray.
                        // From there it is Base-64 encoded for sending via Service call.
                        byte[] bytes = webClient.DownloadData(value);
                        //Opens a PowerPoint Presentation
                        IPresentation presentation = Presentation.Open(new MemoryStream(bytes));

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

                        //Converts the PowerPoint Presentation into PDF document
                        pdf = PresentationToPdfConverter.Convert(presentation);

                        stream = new MemoryStream();
                        //Saves the PDF document
                        pdf.Save(stream);

                        //Sets the stream position
                        stream.Position = 0;
                        pdf.Close();
                        presentation.Close();
                        //Returns the stream data as Base 64 string
                        return(Convert.ToBase64String(stream.ToArray()));
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex);
                        throw;
                    }
                }
            }
            return(null);
        }