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)); } }
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")); }
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); }
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")); } }
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")); } }
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(); } }
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 } }
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(); } }
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 }
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); } }
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); } }
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"; } }
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); } } }
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 { } }
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)); }
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); }
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"); } }
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 } }