void OnButtonClicked(object sender, EventArgs e) { string resourcePath = ""; #if COMMONSB resourcePath = "SampleBrowser.Samples.Presentation.Samples.Templates.HelloWorld.pptx"; #else resourcePath = "SampleBrowser.Presentation.Samples.Templates.HelloWorld.pptx"; #endif Assembly assembly = typeof(GettingStarted).GetTypeInfo().Assembly; Stream fileStream = assembly.GetManifestResourceStream(resourcePath); //Open a PowerPoint presentation IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fileStream); #region Slide1 //Get the first slide from Presentation ISlide slide1 = presentation.Slides[0]; //Get the shape from slide and set bounds IShape titleShape = slide1.Shapes[0] as IShape; titleShape.Left = 0.33 * 72; titleShape.Top = 0.58 * 72; titleShape.Width = 12.5 * 72; titleShape.Height = 1.75 * 72; //Set a content to the text box and apply text formatting ITextBody textFrame1 = (slide1.Shapes[0] as IShape).TextBody; IParagraphs paragraphs1 = textFrame1.Paragraphs; IParagraph paragraph = paragraphs1.Add(); paragraph.HorizontalAlignment = HorizontalAlignmentType.Center; ITextPart textPart1 = paragraph.AddTextPart(); textPart1.Text = "Essential Presentation"; textPart1.Font.CapsType = TextCapsType.All; textPart1.Font.FontName = "Arial"; textPart1.Font.Bold = true; textPart1.Font.FontSize = 40; IShape subtitle = slide1.Shapes[1] as IShape; subtitle.Left = 0.5 * 72; subtitle.Top = 3 * 72; subtitle.Width = 11.8 * 72; subtitle.Height = 1.7 * 72; ITextBody textFrame2 = (slide1.Shapes[1] as IShape).TextBody; textFrame2.VerticalAlignment = VerticalAlignmentType.Top; IParagraphs paragraphs2 = textFrame2.Paragraphs; IParagraph para = paragraphs2.Add(); para.HorizontalAlignment = HorizontalAlignmentType.Left; ITextPart textPart2 = para.AddTextPart(); textPart2.Text = "Lorem ipsum dolor sit amet, lacus amet amet ultricies. Quisque mi venenatis morbi libero, orci dis, mi ut et class porta, massa ligula magna enim, aliquam orci vestibulum tempus.Turpis facilisis vitae consequat, cum a a, turpis dui consequat massa in dolor per, felis non amet."; textPart2.Font.FontName = "Arial"; textPart2.Font.FontSize = 21; para = paragraphs2.Add(); para.HorizontalAlignment = HorizontalAlignmentType.Left; textPart2 = para.AddTextPart(); textPart2.Text = "Turpis facilisis vitae consequat, cum a a, turpis dui consequat massa in dolor per, felis non amet. Auctor eleifend in omnis elit vestibulum, donec non elementum tellus est mauris, id aliquam, at lacus, arcu pretium proin lacus dolor et. Eu tortor, vel ultrices amet dignissim mauris vehicula.For more details please "; textPart2.Font.FontName = "Arial"; textPart2.Font.FontSize = 21; //Add hyperlink to the paragraph ITextPart textPart3 = para.AddTextPart(); textPart3.Font.FontName = "Arial"; textPart3.Text = "click here"; textPart3.SetHyperlink("https://msdn.microsoft.com/en-in/library/mt299001.aspx"); #endregion //Save the Presentation to stream MemoryStream stream = new MemoryStream(); presentation.Save(stream); presentation.Close(); stream.Position = 0; if (Device.RuntimePlatform == Device.WinPhone || (Device.RuntimePlatform == Device.UWP || Device.RuntimePlatform == Device.WinRT)) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("GettingStartedSample.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("GettingStartedSample.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream); } }
void OnButtonClicked(object sender, EventArgs e) { string resourcePath = "SampleBrowser.Samples.Presentation.Templates.HelloWorld.pptx"; Assembly assembly = typeof(App).GetTypeInfo().Assembly; Stream fileStream = assembly.GetManifestResourceStream(resourcePath); IPresentation presentation = Presentation.Open(fileStream); #region Slide1 ISlide slide1 = presentation.Slides[0]; IShape titleShape = slide1.Shapes[0] as IShape; titleShape.Left = 0.33 * 72; titleShape.Top = 0.58 * 72; titleShape.Width = 12.5 * 72; titleShape.Height = 1.75 * 72; ITextBody textFrame1 = (slide1.Shapes[0] as IShape).TextBody; IParagraphs paragraphs1 = textFrame1.Paragraphs; IParagraph paragraph = paragraphs1.Add(); paragraph.HorizontalAlignment = HorizontalAlignmentType.Center; ITextPart textPart1 = paragraph.AddTextPart(); textPart1.Text = "Essential Presentation"; textPart1.Font.CapsType = TextCapsType.All; textPart1.Font.FontName = "Adobe Garamond Pro"; textPart1.Font.Bold = true; textPart1.Font.FontSize = 40; IShape subtitle = slide1.Shapes[1] as IShape; subtitle.Left = 0.5 * 72; subtitle.Top = 3 * 72; subtitle.Width = 11.8 * 72; subtitle.Height = 1.7 * 72; ITextBody textFrame2 = (slide1.Shapes[1] as IShape).TextBody; textFrame2.VerticalAlignment = VerticalAlignmentType.Top; IParagraphs paragraphs2 = textFrame2.Paragraphs; IParagraph para = paragraphs2.Add(); para.HorizontalAlignment = HorizontalAlignmentType.Left; ITextPart textPart2 = para.AddTextPart(); textPart2.Text = "Lorem ipsum dolor sit amet, lacus amet amet ultricies. Quisque mi venenatis morbi libero, orci dis, mi ut et class porta, massa ligula magna enim, aliquam orci vestibulum tempus.Turpis facilisis vitae consequat, cum a a, turpis dui consequat massa in dolor per, felis non amet."; textPart2.Font.FontName = "Adobe Garamond Pro"; textPart2.Font.FontSize = 21; para = paragraphs2.Add(); para.HorizontalAlignment = HorizontalAlignmentType.Left; textPart2 = para.AddTextPart(); textPart2.Text = "Turpis facilisis vitae consequat, cum a a, turpis dui consequat massa in dolor per, felis non amet. Auctor eleifend in omnis elit vestibulum, donec non elementum tellus est mauris, id aliquam, at lacus, arcu pretium proin lacus dolor et. Eu tortor, vel ultrices amet dignissim mauris vehicula."; textPart2.Font.FontName = "Adobe Garamond Pro"; textPart2.Font.FontSize = 21; #endregion MemoryStream stream = new MemoryStream(); presentation.Save(stream); presentation.Close(); stream.Position = 0; if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("GettingStartedSample.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("GettingStartedSample.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream); } }
protected void btnMergeDocuments_Click(object sender, EventArgs e) { if (this.FileUpload1.HasFile && this.FileUpload2.HasFile) { string source = Path.GetFileNameWithoutExtension(this.FileUpload1.PostedFile.FileName); string destination = Path.GetFileNameWithoutExtension(this.FileUpload2.PostedFile.FileName); string extSource = Path.GetExtension(this.FileUpload1.PostedFile.FileName).ToLower(); string extDestination = Path.GetExtension(this.FileUpload2.PostedFile.FileName).ToLower(); if (extSource == ".pptx" && extDestination == ".pptx") { //Convert the input powerpoint document to a PDF file # region Clone Slide using Destination Theme Stream readSource = this.FileUpload1.PostedFile.InputStream; Stream readDestination = this.FileUpload2.PostedFile.InputStream; try { //Opens the specified presentation IPresentation sourcePresentation = Presentation.Open(readSource); IPresentation destinationPresentation = Presentation.Open(readDestination); ISlides slides = sourcePresentation.Slides; if (this.RadioDestination.Checked == true) { foreach (ISlide slide in slides) { destinationPresentation.Slides.Add(slide.Clone(), PasteOptions.UseDestinationTheme, sourcePresentation); } //Closing the Source presentation sourcePresentation.Close(); readSource.Close(); //Saving the Destination presentaiton. destinationPresentation.Save("MergedUsingDestination.pptx", FormatType.Pptx, Response); } else { foreach (ISlide slide in slides) { destinationPresentation.Slides.Add(slide.Clone(), PasteOptions.SourceFormatting, sourcePresentation); } //Closing the Source presentation sourcePresentation.Close(); readSource.Close(); //Saving the Destination presentaiton. destinationPresentation.Save("MergedUsingSource.pptx", FormatType.Pptx, Response); } } 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 perform merging"; } }
private void btnMergeDocument_Click(object sender, EventArgs e) { try { if (this.radioDestination.IsChecked == true) { //Creates instance for source presentation IPresentation sourcePresentation = Presentation.Open(txtFile1.Tag.ToString()); //Creates instance for destination presentation IPresentation destinationPresentation = Presentation.Open(txtFile.Tag.ToString()); ISlides slides = sourcePresentation.Slides; foreach (ISlide slide in slides) { //Clones the slides from source to destination destinationPresentation.Slides.Add(slide.Clone(), PasteOptions.UseDestinationTheme, sourcePresentation); } //Closing the Source presentation sourcePresentation.Close(); //Saving the Destination presentaiton. destinationPresentation.Save("MergedUsingDestination.pptx"); destinationPresentation.Close(); if (System.Windows.MessageBox.Show("Do you want to view the merged PowerPoint Presentation?", "Finished Merging", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { #if !NETCore System.Diagnostics.Process.Start("MergedUsingDestination.pptx"); #else System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("MergedUsingDestination.pptx") { UseShellExecute = true }; process.Start(); #endif } } else { //Creates instance for source presentation IPresentation sourcePresentation = Presentation.Open(txtFile1.Tag.ToString()); //Creates instance for destination presentation IPresentation destinationPresentation = Presentation.Open(txtFile.Tag.ToString()); ISlides slides = sourcePresentation.Slides; foreach (ISlide slide in slides) { //Clones the slides from source to destination destinationPresentation.Slides.Add(slide.Clone(), PasteOptions.SourceFormatting, sourcePresentation); } //Closing the Source presentation sourcePresentation.Close(); //Saving the Destination presentaiton. destinationPresentation.Save("MergedUsingSource.pptx"); //Closing the destination presentation destinationPresentation.Close(); if (System.Windows.MessageBox.Show("Do you want to view the merged PowerPoint Presentation?", "Finished Merging", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { #if !NETCore System.Diagnostics.Process.Start("MergedUsingSource.pptx"); #else System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("MergedUsingSource.pptx") { UseShellExecute = true }; process.Start(); #endif } } } catch (Exception exp) { MessageBox.Show("This file could not be merged, please contact Syncfusion Direct-Trac system at http://www.syncfusion.com/support/default.aspx for any queries. ", "OOPS..Sorry!", MessageBoxButton.OK); this.Close(); } }
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 = Syncfusion.Presentation.Presentation.Open(fileStream); #region Slide1 ISlide slide1 = presentation.Slides[0]; IShape shape1 = (IShape)slide1.Shapes[0]; shape1.Left = 1.27 * 72; shape1.Top = 0.56 * 72; shape1.Width = 9.55 * 72; shape1.Height = 5.4 * 72; ITextBody textFrame = shape1.TextBody; IParagraphs paragraphs = textFrame.Paragraphs; paragraphs.Add(); IParagraph paragraph = paragraphs[0]; paragraph.HorizontalAlignment = HorizontalAlignmentType.Left; ITextParts textParts = paragraph.TextParts; textParts.Add(); ITextPart textPart = textParts[0]; textPart.Text = "Essential Presentation "; textPart.Font.CapsType = TextCapsType.All; textPart.Font.FontName = "Calibri Light (Headings)"; textPart.Font.FontSize = 80; textPart.Font.Color = ColorObject.Black; #endregion #region Slide2 ISlide slide2 = presentation.Slides.Add(SlideLayoutType.ContentWithCaption); slide2.Background.Fill.FillType = FillType.Solid; slide2.Background.Fill.SolidFill.Color = ColorObject.White; //Adds shape in slide shape1 = (IShape)slide2.Shapes[0]; shape1.Left = 0.47 * 72; shape1.Top = 1.15 * 72; shape1.Width = 3.5 * 72; shape1.Height = 4.91 * 72; ITextBody textFrame1 = shape1.TextBody; //Instance to hold paragraphs in textframe IParagraphs paragraphs1 = textFrame1.Paragraphs; IParagraph paragraph1 = paragraphs1.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Left; ITextPart textpart1 = paragraph1.AddTextPart(); textpart1.Text = "Lorem ipsum dolor sit amet, lacus amet amet ultricies. Quisque mi venenatis morbi libero, orci dis, mi ut et class porta, massa ligula magna enim, aliquam orci vestibulum tempus."; textpart1.Font.Color = ColorObject.White; textpart1.Font.FontName = "Calibri (Body)"; textpart1.Font.FontSize = 15; paragraphs1.Add(); IParagraph paragraph2 = paragraphs1.Add(); paragraph2.HorizontalAlignment = HorizontalAlignmentType.Left; textpart1 = paragraph2.AddTextPart(); textpart1.Text = "Turpis facilisis vitae consequat, cum a a, turpis dui consequat massa in dolor per, felis non amet."; textpart1.Font.Color = ColorObject.White; textpart1.Font.FontName = "Calibri (Body)"; textpart1.Font.FontSize = 15; paragraphs1.Add(); IParagraph paragraph3 = paragraphs1.Add(); paragraph3.HorizontalAlignment = HorizontalAlignmentType.Left; textpart1 = paragraph3.AddTextPart(); textpart1.Text = "Auctor eleifend in omnis elit vestibulum, donec non elementum tellus est mauris, id aliquam, at lacus, arcu pretium proin lacus dolor et. Eu tortor, vel ultrices amet dignissim mauris vehicula."; textpart1.Font.Color = ColorObject.White; textpart1.Font.FontName = "Calibri (Body)"; textpart1.Font.FontSize = 15; paragraphs1.Add(); IParagraph paragraph4 = paragraphs1.Add(); paragraph4.HorizontalAlignment = HorizontalAlignmentType.Left; textpart1 = paragraph4.AddTextPart(); textpart1.Text = "Lorem tortor neque, purus taciti quis id. Elementum integer orci accumsan minim phasellus vel."; textpart1.Font.Color = ColorObject.White; textpart1.Font.FontName = "Calibri (Body)"; textpart1.Font.FontSize = 15; paragraphs1.Add(); slide2.Shapes.RemoveAt(1); slide2.Shapes.RemoveAt(1); //Adds picture in the shape resourcePath = "SampleBrowser.Samples.Presentation.Templates.tablet.jpg"; assembly = Assembly.GetExecutingAssembly(); fileStream = assembly.GetManifestResourceStream(resourcePath); slide2.Shapes.AddPicture(fileStream, 5.18 * 72, 1.15 * 72, 7.3 * 72, 5.31 * 72); fileStream.Close(); #endregion MemoryStream stream = new MemoryStream(); presentation.Save(stream); presentation.Close(); stream.Position = 0; if (stream != null) { SaveAndroid androidSave = new SaveAndroid(); androidSave.Save("Images.pptx", "application/powerpoint", stream, m_context); } }
void OnButtonClicked(object sender, EventArgs e) { string resourcePath = "SampleBrowser.Samples.Presentation.Templates.HelloWorld.pptx"; Assembly assembly = Assembly.GetExecutingAssembly(); Stream fileStream = assembly.GetManifestResourceStream(resourcePath); IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fileStream); #region Slide1 ISlide slide1 = presentation.Slides[0]; IShape titleShape = slide1.Shapes[0] as IShape; titleShape.Left = 0.33 * 72; titleShape.Top = 0.58 * 72; titleShape.Width = 12.5 * 72; titleShape.Height = 1.75 * 72; ITextBody textFrame1 = (slide1.Shapes[0] as IShape).TextBody; IParagraphs paragraphs1 = textFrame1.Paragraphs; IParagraph paragraph = paragraphs1.Add(); paragraph.HorizontalAlignment = HorizontalAlignmentType.Center; ITextPart textPart1 = paragraph.AddTextPart(); textPart1.Text = "Essential Presentation"; textPart1.Font.CapsType = TextCapsType.All; textPart1.Font.FontName = "Arial"; textPart1.Font.Bold = true; textPart1.Font.FontSize = 40; IShape subtitle = slide1.Shapes[1] as IShape; subtitle.Left = 0.5 * 72; subtitle.Top = 3 * 72; subtitle.Width = 11.8 * 72; subtitle.Height = 1.7 * 72; ITextBody textFrame2 = (slide1.Shapes[1] as IShape).TextBody; textFrame2.VerticalAlignment = VerticalAlignmentType.Top; IParagraphs paragraphs2 = textFrame2.Paragraphs; IParagraph para = paragraphs2.Add(); para.HorizontalAlignment = HorizontalAlignmentType.Left; ITextPart textPart2 = para.AddTextPart(); textPart2.Text = "Lorem ipsum dolor sit amet, lacus amet amet ultricies. Quisque mi venenatis morbi libero, orci dis, mi ut et class porta, massa ligula magna enim, aliquam orci vestibulum tempus.Turpis facilisis vitae consequat, cum a a, turpis dui consequat massa in dolor per, felis non amet."; textPart2.Font.FontName = "Arial"; textPart2.Font.FontSize = 21; para = paragraphs2.Add(); para.HorizontalAlignment = HorizontalAlignmentType.Left; textPart2 = para.AddTextPart(); textPart2.Text = "Turpis facilisis vitae consequat, cum a a, turpis dui consequat massa in dolor per, felis non amet. Auctor eleifend in omnis elit vestibulum, donec non elementum tellus est mauris, id aliquam, at lacus, arcu pretium proin lacus dolor et. Eu tortor, vel ultrices amet dignissim mauris vehicula."; textPart2.Font.FontName = "Arial"; textPart2.Font.FontSize = 21; //Add hyperlink to the paragraph ITextPart textPart3 = para.AddTextPart(); textPart3.Text = "click here"; textPart3.Font.FontName = "Arial"; textPart3.SetHyperlink("https://msdn.microsoft.com/en-in/library/mt299001.aspx"); #endregion MemoryStream stream = new MemoryStream(); presentation.Save(stream); presentation.Close(); stream.Position = 0; if (stream != null) { SaveAndroid androidSave = new SaveAndroid(); androidSave.Save("GettingStarted.pptx", "application/powerpoint", stream, m_context); } }
private void btnCreateImage_Click(object sender, RoutedEventArgs e) { try { string inputPath = @"..\..\..\..\..\..\Common\Data\Presentation\SmartArts.pptx"; #if NETCore inputPath = @"..\..\..\..\..\..\..\Common\Data\Presentation\SmartArts.pptx"; #endif //Opens the specified presentation IPresentation presentation = Presentation.Open(inputPath); //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) { #if !NETCore System.Diagnostics.Process.Start("SmartArtSample.pptx"); #else System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("SmartArtSample.pptx") { UseShellExecute = true }; process.Start(); #endif 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) { #if !NETCore System.Diagnostics.Process.Start("Sample.pdf"); #else System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf") { UseShellExecute = true }; process.Start(); #endif } } } 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> /// Add table in a PowerPoint Presentation file. /// </summary> private void BtnCreatePresn_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) { //Creates a new instance of the PowerPoint Presentation file. using IPresentation presentation = Syncfusion.Presentation.Presentation.Create(); #region Slide1 //Adds a slide to PowerPoint presentation. ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleOnly); //Sets the table title in a slide. SetTableTitle(slide); //Gets table data from xml file. DataSet dataSet = new(); Assembly assembly = typeof(Table).GetTypeInfo().Assembly; string resourcePath = "syncfusion.presentationdemos.winui.Assets.Presentation.TableData.xml"; using (Stream fileStream = assembly.GetManifestResourceStream(resourcePath)) { dataSet.ReadXml(fileStream); } int columnCount = dataSet.Tables[0].Rows.Count + 1; int rowCount = dataSet.Tables.Count - 1; //Adds a new table in slide. ITable table = slide.Shapes.AddTable(rowCount, columnCount, 61.92, 95.76, 856.8, 378.72); //Sets the style for the table. table.BuiltInStyle = BuiltInTableStyle.MediumStyle2Accent6; //Sets category title SetCategoryTitle(table); //Iterates and sets the values to the table cells. for (int rowIndex = 0; rowIndex < table.Rows.Count; rowIndex++) { IRow row = table.Rows[rowIndex]; if (rowIndex == 0) { AddHeaderRow(row, dataSet.Tables[0].Rows); } else { AddCell(row, dataSet.Tables[rowIndex + 1]); } } #endregion //Saves the presentation to the memory stream. using MemoryStream stream = new(); if (presentationdoc.IsChecked == true) { presentation.Save(stream); stream.Position = 0; //Saves the memory stream as file. SaveAndLaunch.Save("Table.pptx", stream); } else { //Converts the PowerPoint Presentation to PDF document. using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation)) { //Saves the converted PDF document to MemoryStream. pdfDocument.Save(stream); stream.Position = 0; } //Saves the memory stream as file. SaveAndLaunch.Save("Table.pdf", stream); } }
public ActionResult Connector(string Browser) { //Create an instance for PowerPoint IPresentation presentation = Presentation.Create(); //Add a blank slide to Presentation ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank); //Add header shape IShape headerTextBox = slide.Shapes.AddTextBox(58.44, 53.85, 221.93, 81.20); //Add a paragraph into the text box IParagraph paragraph = headerTextBox.TextBody.AddParagraph("Flow chart with "); //Add a textPart ITextPart textPart = paragraph.AddTextPart("Connector"); //Change the color of the font textPart.Font.Color = ColorObject.FromArgb(44, 115, 230); //Make the textpart bold textPart.Font.Bold = true; //Set the font size of the paragraph paragraph.Font.FontSize = 28; //Add start shape to slide IShape startShape = slide.Shapes.AddShape(AutoShapeType.FlowChartTerminator, 420.45, 36.35, 133.93, 50.39); //Add a paragraph into the start shape text body AddParagraph(startShape, "Start", ColorObject.FromArgb(255, 149, 34)); //Add alarm shape to slide IShape alarmShape = slide.Shapes.AddShape(AutoShapeType.FlowChartProcess, 420.45, 126.72, 133.93, 50.39); //Add a paragraph into the alarm shape text body AddParagraph(alarmShape, "Alarm Rings", ColorObject.FromArgb(255, 149, 34)); //Add condition shape to slide IShape conditionShape = slide.Shapes.AddShape(AutoShapeType.FlowChartDecision, 420.45, 222.42, 133.93, 97.77); //Add a paragraph into the condition shape text body AddParagraph(conditionShape, "Ready to Get Up ?", ColorObject.FromArgb(44, 115, 213)); //Add wake up shape to slide IShape wakeUpShape = slide.Shapes.AddShape(AutoShapeType.FlowChartProcess, 420.45, 361.52, 133.93, 50.39); //Add a paragraph into the wake up shape text body AddParagraph(wakeUpShape, "Wake Up", ColorObject.FromArgb(44, 115, 213)); //Add end shape to slide IShape endShape = slide.Shapes.AddShape(AutoShapeType.FlowChartTerminator, 420.45, 453.27, 133.93, 50.39); //Add a paragraph into the end shape text body AddParagraph(endShape, "End", ColorObject.FromArgb(44, 115, 213)); //Add snooze shape to slide IShape snoozeShape = slide.Shapes.AddShape(AutoShapeType.FlowChartProcess, 624.85, 245.79, 159.76, 50.02); //Add a paragraph into the snooze shape text body AddParagraph(snoozeShape, "Hit Snooze button", ColorObject.FromArgb(255, 149, 34)); //Add relay shape to slide IShape relayShape = slide.Shapes.AddShape(AutoShapeType.FlowChartDelay, 624.85, 127.12, 159.76, 49.59); //Add a paragraph into the relay shape text body AddParagraph(relayShape, "Relay", ColorObject.FromArgb(255, 149, 34)); //Connect the start shape with alarm shape using connector IConnector connector1 = slide.Shapes.AddConnector(ConnectorType.Straight, startShape, 2, alarmShape, 0); //Set the arrow style for the connector connector1.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Connect the alarm shape with condition shape using connector IConnector connector2 = slide.Shapes.AddConnector(ConnectorType.Straight, alarmShape, 2, conditionShape, 0); //Set the arrow style for the connector connector2.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Connect the condition shape with snooze shape using connector IConnector connector3 = slide.Shapes.AddConnector(ConnectorType.Straight, conditionShape, 3, snoozeShape, 1); //Set the arrow style for the connector connector3.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Connect the snooze shape with relay shape using connector IConnector connector4 = slide.Shapes.AddConnector(ConnectorType.Straight, snoozeShape, 0, relayShape, 2); //Set the arrow style for the connector connector4.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Connect the relay shape with alarm shape using connector IConnector connector5 = slide.Shapes.AddConnector(ConnectorType.Straight, relayShape, 1, alarmShape, 3); //Set the arrow style for the connector connector5.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Connect the condition shape with wake up shape using connector IConnector connector6 = slide.Shapes.AddConnector(ConnectorType.Straight, conditionShape, 2, wakeUpShape, 0); //Set the arrow style for the connector connector6.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Connect the wake up shape with end shape using connector IConnector connector7 = slide.Shapes.AddConnector(ConnectorType.Straight, wakeUpShape, 2, endShape, 0); //Set the arrow style for the connector connector7.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Add No textbox to slide IShape noTextBox = slide.Shapes.AddTextBox(564.02, 245.43, 51.32, 26.22); //Add a paragraph into the text box noTextBox.TextBody.AddParagraph("No"); //Add Yes textbox to slide IShape yesTextBox = slide.Shapes.AddTextBox(487.21, 327.99, 50.09, 26.23); //Add a paragraph into the text box yesTextBox.TextBody.AddParagraph("Yes"); 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; //Initialize the file stream to download the presentation. FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/vnd.openxmlformats-officedocument.presentationml.presentation"); //Set the file name. fileStreamResult.FileDownloadName = "Connector.pptx"; return(fileStreamResult); }
public void GenratepptxUsingExistingPpt(string sText) { try { IPresentation pptxDoc = Presentation.Open("C:\\Project-Result\\PPTx-Project\\PPTCreationApp\\DataFile\\DemoPPT.pptx"); ILayoutSlide layoutSlide = pptxDoc.Masters[1].LayoutSlides.Add(SlideLayoutType.Blank, "CustomLayout"); IShape shape = layoutSlide.Shapes.AddShape(AutoShapeType.Diamond, 30, 20, 400, 300); layoutSlide.Background.Fill.SolidFill.Color = ColorObject.FromArgb(78, 89, 90); ISlide slide = pptxDoc.Slides.Add(layoutSlide); ITable table = slide.Shapes.AddTable(1, 3, 100, 120, 600, 50); Syncfusion.Drawing.Image image = Syncfusion.Drawing.Image.FromFile("C:\\Project-Result\\PPTx-Project\\PPTCreationApp\\DataFile\\Ninja.jpg"); ICell cell1 = table.Rows[0].Cells[0] as ICell; cell1.Fill.FillType = FillType.Picture; cell1.Fill.PictureFill.ImageBytes = image.ImageData; ICell cell2 = table.Rows[0].Cells[1] as ICell; cell2.Fill.FillType = FillType.Solid; cell2.Fill.SolidFill.Color.SystemColor = Color.BlueViolet; cell2.TextBody.Text = sText.ToString(); ICell cell3 = table.Rows[0].Cells[2] as ICell; Stream txtStream = File.Open("C:\\Project-Result\\PPTx-Project\\PPTCreationApp\\DataFile\\Ornament-CodeFlow.pdf", FileMode.Open); //Stream imageStream = File.Open("D:\\PPTxExamplesConsoleApps\\PPTConsole\\PPTCreationApp\\Images\\TextFile.png", FileMode.Open); byte[] file = File.ReadAllBytes("C:\\Project-Result\\PPTx-Project\\PPTCreationApp\\DataFile\\logopdf.png"); Stream imageStream = new MemoryStream(file); cell3.Fill.FillType = FillType.Picture; cell3.Fill.PictureFill.ImageBytes = file; IOleObject oleObject = slide.Shapes.AddOleObject(imageStream, "Excel.Sheet.12", txtStream); //Set size and position of the OLE object oleObject.Left = 80; oleObject.Top = 30; oleObject.Width = 40; oleObject.Height = 30; int rowIndex = 0, colIndex; //Iterate row-wise cells and add text to it foreach (IRow rows in table.Rows) { colIndex = 0; foreach (ICell cell in rows.Cells) { //cell.TextBody.AddParagraph("(" + rowIndex.ToString() + " , " + colIndex.ToString() + ")"); //colIndex++; } rowIndex++; } pptxDoc.Save("C:\\Project-Result\\PPTx-Project\\PPTCreationApp\\DataFile\\DemoPPT.pptx"); pptxDoc.Close(); } catch (Exception ex) { throw; } }
void OnButtonClicked(object sender, EventArgs e) { //Create an instance for PowerPoint IPresentation presentation = Presentation.Create(); //Add a blank slide to Presentation ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank); //Add header shape IShape headerTextBox = slide.Shapes.AddTextBox(255.60, 11.35, 315.33, 41.20); //Add a paragraph into the text box IParagraph paragraph = headerTextBox.TextBody.AddParagraph("Flow chart with connector"); //Set the font size of the paragraph paragraph.Font.FontSize = 28; //Add start shape to slide IShape startShape = slide.Shapes.AddShape(AutoShapeType.FlowChartTerminator, 343.69, 79.22, 101.34, 35.86); //Add a paragraph into the start shape text body AddParagraph(startShape, "Start"); //Add alarm shape to slide IShape alarmShape = slide.Shapes.AddShape(AutoShapeType.FlowChartProcess, 343.69, 151.35, 101.34, 44.93); //Add a paragraph into the alarm shape text body AddParagraph(alarmShape, "Alarm Rings"); //Add condition shape to slide IShape conditionShape = slide.Shapes.AddShape(AutoShapeType.FlowChartDecision, 343.69, 239.22, 101.34, 73.98); //Add a paragraph into the condition shape text body AddParagraph(conditionShape, "Ready to Get Up ?"); //Change font size of the paragraph conditionShape.TextBody.Paragraphs[0].Font.FontSize = 12; //Add wake up shape to slide IShape wakeUpShape = slide.Shapes.AddShape(AutoShapeType.FlowChartProcess, 343.69, 356.15, 101.34, 44.93); //Add a paragraph into the wake up shape text body AddParagraph(wakeUpShape, "Wake Up"); //Add end shape to slide IShape endShape = slide.Shapes.AddShape(AutoShapeType.FlowChartTerminator, 343.69, 447.93, 101.34, 35.86); //Add a paragraph into the end shape text body AddParagraph(endShape, "End"); //Add snooze shape to slide IShape snoozeShape = slide.Shapes.AddShape(AutoShapeType.FlowChartProcess, 545.09, 239.22, 101.34, 73.98); //Add a paragraph into the snooze shape text body AddParagraph(snoozeShape, "Hit Snooze button"); //Add relay shape to slide IShape relayShape = slide.Shapes.AddShape(AutoShapeType.FlowChartDelay, 545.09, 151.35, 101.34, 44.93); //Add a paragraph into the relay shape text body AddParagraph(relayShape, "Relay"); //Connect the start shape with alarm shape using connector IConnector connector1 = slide.Shapes.AddConnector(ConnectorType.Straight, startShape, 2, alarmShape, 0); //Set the arrow style for the connector connector1.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Connect the alarm shape with condition shape using connector IConnector connector2 = slide.Shapes.AddConnector(ConnectorType.Straight, alarmShape, 2, conditionShape, 0); //Set the arrow style for the connector connector2.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Connect the condition shape with snooze shape using connector IConnector connector3 = slide.Shapes.AddConnector(ConnectorType.Straight, conditionShape, 3, snoozeShape, 1); //Set the arrow style for the connector connector3.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Connect the snooze shape with relay shape using connector IConnector connector4 = slide.Shapes.AddConnector(ConnectorType.Straight, snoozeShape, 0, relayShape, 2); //Set the arrow style for the connector connector4.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Connect the relay shape with alarm shape using connector IConnector connector5 = slide.Shapes.AddConnector(ConnectorType.Straight, relayShape, 1, alarmShape, 3); //Set the arrow style for the connector connector5.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Connect the condition shape with wake up shape using connector IConnector connector6 = slide.Shapes.AddConnector(ConnectorType.Straight, conditionShape, 2, wakeUpShape, 0); //Set the arrow style for the connector connector6.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Connect the wake up shape with end shape using connector IConnector connector7 = slide.Shapes.AddConnector(ConnectorType.Straight, wakeUpShape, 2, endShape, 0); //Set the arrow style for the connector connector7.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Add No textbox to slide IShape noTextBox = slide.Shapes.AddTextBox(470.97, 250.34, 35.67, 29.08); //Add a paragraph into the text box noTextBox.TextBody.AddParagraph("No"); //Add Yes textbox to slide IShape yesTextBox = slide.Shapes.AddTextBox(394.15, 314.92, 38.23, 29.08); //Add a paragraph into the text box yesTextBox.TextBody.AddParagraph("Yes"); MemoryStream stream = new MemoryStream(); presentation.Save(stream); presentation.Close(); stream.Position = 0; if (stream != null) { SaveiOS iOSSave = new SaveiOS(); iOSSave.Save("ConnectorsPresentation.pptx", "application/mspowerpoint", stream); } }
public ActionResult OLEObject(string Browser, string view) { string basePath = _hostingEnvironment.WebRootPath; if (view.Trim() == "Create Presentation") { //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides]. IPresentation 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(0.84 * 72, 1.65 * 72, 2.23 * 72, 0.51 * 72); heading.Left = 3.2 * 72; heading.Top = 1.51 * 72; heading.Width = 1.86 * 72; heading.Height = 0.71 * 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 = basePath + @"/Presentation/OleTemplate.docx"; //Get the excel file as stream Stream wordStream = new FileStream(mswordPath, FileMode.Open); string imagePath = basePath + @"/Presentation/OlePicture.png"; //Image to be displayed, This can be any image Stream imageStream = new FileStream(imagePath, FileMode.Open); 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 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", "InsertOLEObject.pptx")); } else { FileStream fileStreamInput = new FileStream(basePath + @"/Presentation/EmbeddedOleObject.pptx", FileMode.Open, FileAccess.Read); IPresentation pptxDoc = Presentation.Open(fileStreamInput); //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides]. //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 OLE Object string outputFile = oleObject.FileName; MemoryStream ms = new MemoryStream(array); //Initialize the file stream to download the presentation. FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/vnd.openxmlformats-officedocument.presentationml.presentation"); //Set the file name. fileStreamResult.FileDownloadName = outputFile; return(fileStreamResult); } }
private void generateSlide_Click(object sender, EventArgs e) { //Creates PowerPoint Presentation IPresentation pptxDoc = Presentation.Create(); //Adds slide to the PowerPoint ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank); //Adds textbox to the slide IShape textboxShape = slide.AddTextBox(0, 0, 1024, 100); IShape textboxShape2 = slide.AddTextBox(0, 101, 1024, 200); if (imageUrlOne != "") { WebClient myWebClient = new WebClient(); byte[] bytes = myWebClient.DownloadData(imageUrlOne); Stream pictureStream = new MemoryStream(bytes); IPicture picture = slide.Pictures.AddPicture(pictureStream, 50, 301, 150, 150); pptxDoc.Save(titleInput.Text + ".pptx"); pictureStream.Dispose(); } if (imageUrlTwo != "") { WebClient myWebClient = new WebClient(); byte[] bytes = myWebClient.DownloadData(imageUrlTwo); Stream pictureStream = new MemoryStream(bytes); IPicture picture = slide.Pictures.AddPicture(pictureStream, 250, 301, 150, 150); pptxDoc.Save(titleInput.Text + ".pptx"); pictureStream.Dispose(); } if (imageUrlThree != "") { WebClient myWebClient = new WebClient(); byte[] bytes = myWebClient.DownloadData(imageUrlThree); Stream pictureStream = new MemoryStream(bytes); IPicture picture = slide.Pictures.AddPicture(pictureStream, 450, 301, 150, 150); pptxDoc.Save(titleInput.Text + ".pptx"); pictureStream.Dispose(); } //Adds paragraph to the textbody of text box IParagraph title = textboxShape.TextBody.AddParagraph(); IParagraph body = textboxShape2.TextBody.AddParagraph(); //Adds a TextPart to the paragraph ITextPart textPart = title.AddTextPart(); ITextPart textPart2 = body.AddTextPart(); //Adds text to the TextPart textPart.Text = titleInput.Text; textPart2.Text = bodyText.Text; // Formatting title.HorizontalAlignment = HorizontalAlignmentType.Center; body.HorizontalAlignment = HorizontalAlignmentType.Center; IFont titleFont = title.Font; titleFont.Bold = true; titleFont.FontSize = 40; //Saves the Presentation pptxDoc.Save(titleInput.Text + ".pptx"); //Closes the Presentation pptxDoc.Close(); }
void OnButtonClicked(object sender, EventArgs e) { string resourcePath = "SampleBrowser.Samples.Presentation.Templates.Slides.pptx"; Assembly assembly = typeof(App).GetTypeInfo().Assembly; Stream fileStream = assembly.GetManifestResourceStream(resourcePath); IPresentation presentation = Presentation.Open(fileStream); #region Slide1 ISlide slide1 = presentation.Slides[0]; IShape shape1 = slide1.Shapes[0] as IShape; shape1.Left = 1.5 * 72; shape1.Top = 1.94 * 72; shape1.Width = 10.32 * 72; shape1.Height = 2 * 72; ITextBody textFrame1 = shape1.TextBody; IParagraphs paragraphs1 = textFrame1.Paragraphs; IParagraph paragraph1 = paragraphs1.Add(); ITextPart textPart1 = paragraph1.AddTextPart(); paragraphs1[0].IndentLevelNumber = 0; textPart1.Text = "ESSENTIAL PRESENTATION"; textPart1.Font.FontName = "HelveticaNeue LT 65 Medium"; textPart1.Font.FontSize = 48; textPart1.Font.Bold = true; slide1.Shapes.RemoveAt(1); #endregion #region Slide2 ISlide slide2 = presentation.Slides.Add(SlideLayoutType.SectionHeader); shape1 = slide2.Shapes[0] as IShape; shape1.Left = 0.77 * 72; shape1.Top = 0.32 * 72; shape1.Width = 7.96 * 72; shape1.Height = 0.99 * 72; textFrame1 = shape1.TextBody; //Instance to hold paragraphs in textframe paragraphs1 = textFrame1.Paragraphs; paragraph1 = paragraphs1.Add(); ITextPart textpart1 = paragraph1.AddTextPart(); paragraphs1[0].HorizontalAlignment = HorizontalAlignmentType.Left; textpart1.Text = "Slide with simple text"; textpart1.Font.FontName = "Helvetica CE 35 Thin"; textpart1.Font.FontSize = 40; IShape shape2 = slide2.Shapes[1] as IShape; shape2.Left = 1.21 * 72; shape2.Top = 1.66 * 72; shape2.Width = 10.08 * 72; shape2.Height = 4.93 * 72; ITextBody textFrame2 = shape2.TextBody; //Instance to hold paragraphs in textframe IParagraphs paragraphs2 = textFrame2.Paragraphs; IParagraph paragraph2 = paragraphs2.Add(); paragraph2.HorizontalAlignment = HorizontalAlignmentType.Left; ITextPart textpart2 = paragraph2.AddTextPart(); textpart2.Text = "Lorem ipsum dolor sit amet, lacus amet amet ultricies. Quisque mi venenatis morbi libero, orci dis, mi ut et class porta, massa ligula magna enim, aliquam orci vestibulum tempus."; textpart2.Font.FontName = "Calibri (Body)"; textpart2.Font.FontSize = 15; textpart2.Font.Color = ColorObject.Black; //Instance to hold paragraphs in textframe IParagraph paragraph3 = paragraphs2.Add(); paragraph3.HorizontalAlignment = HorizontalAlignmentType.Left; textpart1 = paragraph3.AddTextPart(); textpart1.Text = "Turpis facilisis vitae consequat, cum a a, turpis dui consequat massa in dolor per, felis non amet."; textpart1.Font.FontName = "Calibri (Body)"; textpart1.Font.FontSize = 15; textpart1.Font.Color = ColorObject.Black; //Instance to hold paragraphs in textframe IParagraph paragraph4 = paragraphs2.Add(); paragraph4.HorizontalAlignment = HorizontalAlignmentType.Left; textpart1 = paragraph4.AddTextPart(); textpart1.Text = "Auctor eleifend in omnis elit vestibulum, donec non elementum tellus est mauris, id aliquam, at lacus, arcu pretium proin lacus dolor et. Eu tortor, vel ultrices amet dignissim mauris vehicula."; textpart1.Font.FontName = "Calibri (Body)"; textpart1.Font.FontSize = 15; textpart1.Font.Color = ColorObject.Black; //Instance to hold paragraphs in textframe IParagraph paragraph5 = paragraphs2.Add(); paragraph5.HorizontalAlignment = HorizontalAlignmentType.Left; textpart1 = paragraph5.AddTextPart(); textpart1.Text = "Vestibulum duis integer diam mi libero felis, sollicitudin id dictum etiam blandit lacus, ac condimentum magna dictumst interdum et,"; textpart1.Font.FontName = "Calibri (Body)"; textpart1.Font.FontSize = 15; textpart1.Font.Color = ColorObject.Black; //Instance to hold paragraphs in textframe IParagraph paragraph6 = paragraphs2.Add(); paragraph6.HorizontalAlignment = HorizontalAlignmentType.Left; paragraph6.AddTextPart(); textpart1.Text = "nam commodo mi habitasse enim fringilla nunc, amet aliquam sapien per tortor luctus. Conubia voluptates at nunc, congue lectus, malesuada nulla."; textpart1.Font.Color = ColorObject.White; textpart1.Font.FontName = "Calibri (Body)"; textpart1.Font.FontSize = 15; textpart1.Font.Color = ColorObject.Black; //Instance to hold paragraphs in textframe IParagraph paragraph7 = paragraphs2.Add(); paragraph7.HorizontalAlignment = HorizontalAlignmentType.Left; textpart1 = paragraph7.AddTextPart(); textpart1.Text = "Rutrum quo morbi, feugiat sed mi turpis, ac cursus integer ornare dolor. Purus dui in et tincidunt, sed eros pede adipiscing tellus, est suscipit nulla,"; textpart1.Font.FontName = "Calibri (Body)"; textpart1.Font.FontSize = 15; textpart1.Font.Color = ColorObject.Black; //Instance to hold paragraphs in textframe IParagraph paragraph8 = paragraphs2.Add(); paragraph8.HorizontalAlignment = HorizontalAlignmentType.Left; textpart1 = paragraph8.AddTextPart(); textpart1.Text = "Auctor eleifend in omnis elit vestibulum, donec non elementum tellus est mauris, id aliquam, at lacus, arcu pretium proin lacus dolor et. Eu tortor, vel ultrices amet dignissim mauris vehicula."; textpart1.Font.FontName = "Calibri (Body)"; textpart1.Font.FontSize = 15; textpart1.Font.Color = ColorObject.Black; //Instance to hold paragraphs in textframe IParagraph paragraph9 = paragraphs2.Add(); paragraph9.HorizontalAlignment = HorizontalAlignmentType.Left; textpart1 = paragraph9.AddTextPart(); textpart1.Text = "arcu nec fringilla vel aliquam, mollis lorem rerum hac vestibulum ante nullam. Volutpat a lectus, lorem pulvinar quis. Lobortis vehicula in imperdiet orci urna."; textpart1.Font.FontName = "Calibri (Body)"; textpart1.Font.Color = ColorObject.Black; textpart1.Font.FontSize = 15; #endregion #region Slide3 slide2 = presentation.Slides.Add(SlideLayoutType.TwoContent); shape1 = slide2.Shapes[0] as IShape; shape1.Left = 0.36 * 72; shape1.Top = 0.51 * 72; shape1.Width = 11.32 * 72; shape1.Height = 1.06 * 72; //Adds textframe in shape textFrame1 = shape1.TextBody; //Instance to hold paragraphs in textframe paragraphs1 = textFrame1.Paragraphs; paragraphs1.Add(); paragraph1 = paragraphs1[0]; textpart1 = paragraph1.AddTextPart(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Left; //Assigns value to textpart textpart1.Text = "Slide with Image"; textpart1.Font.FontName = "Helvetica CE 35 Thin"; //Adds shape in slide shape2 = slide2.Shapes[1] as IShape; shape2.Left = 8.03 * 72; shape2.Top = 1.96 * 72; shape2.Width = 4.39 * 72; shape2.Height = 4.53 * 72; textFrame2 = shape2.TextBody; //Instance to hold paragraphs in textframe paragraphs2 = textFrame2.Paragraphs; paragraph2 = paragraphs2.Add(); textpart2 = paragraph2.AddTextPart(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Left; textpart2.Text = "Lorem ipsum dolor sit amet, lacus amet amet ultricies. Quisque mi venenatis morbi libero, orci dis, mi ut et class porta, massa ligula magna enim, aliquam orci vestibulum tempus."; textpart2.Font.FontName = "Helvetica CE 35 Thin"; textpart2.Font.FontSize = 16; paragraph3 = paragraphs2.Add(); textpart2 = paragraph3.AddTextPart(); paragraph3.HorizontalAlignment = HorizontalAlignmentType.Left; textpart2.Text = "Turpis facilisis vitae consequat, cum a a, turpis dui consequat massa in dolor per, felis non amet."; textpart2.Font.FontName = "Helvetica CE 35 Thin"; textpart2.Font.FontSize = 16; paragraph4 = paragraphs2.Add(); textpart2 = paragraph4.AddTextPart(); paragraph4.HorizontalAlignment = HorizontalAlignmentType.Left; textpart2.Text = "Auctor eleifend in omnis elit vestibulum, donec non elementum tellus est mauris, id aliquam, at lacus, arcu pretium proin lacus dolor et. Eu tortor, vel ultrices amet dignissim mauris vehicula."; textpart2.Font.FontName = "Helvetica CE 35 Thin"; textpart2.Font.FontSize = 16; IShape shape3 = (IShape)slide2.Shapes[2]; slide2.Shapes.RemoveAt(2); //Adds picture in the shape resourcePath = "SampleBrowser.Samples.Presentation.Templates.tablet.jpg"; assembly = typeof(App).GetTypeInfo().Assembly; fileStream = assembly.GetManifestResourceStream(resourcePath); slide2.Shapes.AddPicture(fileStream, 0.81 * 72, 1.96 * 72, 6.63 * 72, 4.43 * 72); fileStream.Close(); #endregion #region Slide4 ISlide slide4 = presentation.Slides.Add(SlideLayoutType.TwoContent); shape1 = slide4.Shapes[0] as IShape; shape1.Left = 0.51 * 72; shape1.Top = 0.34 * 72; shape1.Width = 11.32 * 72; shape1.Height = 1.06 * 72; textFrame1 = shape1.TextBody; //Instance to hold paragraphs in textframe paragraphs1 = textFrame1.Paragraphs; paragraphs1.Add(); paragraph1 = paragraphs1[0]; textpart1 = paragraph1.AddTextPart(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Left; //Assigns value to textpart textpart1.Text = "Slide with Table"; textpart1.Font.FontName = "Helvetica CE 35 Thin"; shape2 = slide4.Shapes[1] as IShape; slide4.Shapes.Remove(shape2); ITable table = (ITable)slide4.Shapes.AddTable(6, 6, 0.81 * 72, 2.14 * 72, 11.43 * 72, 3.8 * 72); table.Rows[0].Height = 0.85 * 72; table.Rows[1].Height = 0.42 * 72; table.Rows[2].Height = 0.85 * 72; table.Rows[3].Height = 0.85 * 72; table.Rows[4].Height = 0.85 * 72; table.Rows[5].Height = 0.85 * 72; table.HasBandedRows = true; table.HasHeaderRow = true; table.HasBandedColumns = false; table.BuiltInStyle = BuiltInTableStyle.MediumStyle2Accent1; ICell cell1 = table.Rows[0].Cells[0]; textFrame2 = cell1.TextBody; paragraph2 = textFrame2.Paragraphs.Add(); paragraph2.HorizontalAlignment = HorizontalAlignmentType.Center; ITextPart textPart2 = paragraph2.AddTextPart(); textPart2.Text = "ID"; ICell cell2 = table.Rows[0].Cells[1]; ITextBody textFrame3 = cell2.TextBody; paragraph3 = textFrame3.Paragraphs.Add(); paragraph3.HorizontalAlignment = HorizontalAlignmentType.Center; ITextPart textPart3 = paragraph3.AddTextPart(); textPart3.Text = "Company Name"; ICell cell3 = table.Rows[0].Cells[2]; ITextBody textFrame4 = cell3.TextBody; paragraph4 = textFrame4.Paragraphs.Add(); paragraph4.HorizontalAlignment = HorizontalAlignmentType.Center; ITextPart textPart4 = paragraph4.AddTextPart(); textPart4.Text = "Contact Name"; ICell cell4 = table.Rows[0].Cells[3]; ITextBody textFrame5 = cell4.TextBody; paragraph5 = textFrame5.Paragraphs.Add(); paragraph5.HorizontalAlignment = HorizontalAlignmentType.Center; ITextPart textPart5 = paragraph5.AddTextPart(); textPart5.Text = "Address"; ICell cell5 = table.Rows[0].Cells[4]; ITextBody textFrame6 = cell5.TextBody; paragraph6 = textFrame6.Paragraphs.Add(); paragraph6.HorizontalAlignment = HorizontalAlignmentType.Center; ITextPart textPart6 = paragraph6.AddTextPart(); textPart6.Text = "City"; ICell cell6 = table.Rows[0].Cells[5]; ITextBody textFrame7 = cell6.TextBody; paragraph7 = textFrame7.Paragraphs.Add(); paragraph7.HorizontalAlignment = HorizontalAlignmentType.Center; ITextPart textPart7 = paragraph7.AddTextPart(); textPart7.Text = "Country"; cell1 = table.Rows[1].Cells[0]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "1"; cell1 = table.Rows[1].Cells[1]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "New Orleans Cajun Delights"; cell1 = table.Rows[1].Cells[2]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "Shelley Burke"; cell1 = table.Rows[1].Cells[3]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "P.O. Box 78934"; cell1 = table.Rows[1].Cells[4]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "New Orleans"; cell1 = table.Rows[1].Cells[5]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "USA"; cell1 = table.Rows[2].Cells[0]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "2"; cell1 = table.Rows[2].Cells[1]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "Cooperativa de Quesos 'Las Cabras"; cell1 = table.Rows[2].Cells[2]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "Antonio del Valle Saavedra"; cell1 = table.Rows[2].Cells[3]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "Calle del Rosal 4"; cell1 = table.Rows[2].Cells[4]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "Oviedo"; cell1 = table.Rows[2].Cells[5]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "Spain"; cell1 = table.Rows[3].Cells[0]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "3"; cell1 = table.Rows[3].Cells[1]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "Mayumi"; cell1 = table.Rows[3].Cells[2]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "Mayumi Ohno"; cell1 = table.Rows[3].Cells[3]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "92 Setsuko Chuo-ku"; cell1 = table.Rows[3].Cells[4]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "Osaka"; cell1 = table.Rows[3].Cells[5]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "Japan"; cell1 = table.Rows[4].Cells[0]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "4"; cell1 = table.Rows[4].Cells[1]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "Pavlova, Ltd."; cell1 = table.Rows[4].Cells[2]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "Ian Devling"; cell1 = table.Rows[4].Cells[3]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "74 Rose St. Moonie Ponds"; cell1 = table.Rows[4].Cells[4]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "Melbourne"; cell1 = table.Rows[4].Cells[5]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "Australia"; cell1 = table.Rows[5].Cells[0]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "5"; cell1 = table.Rows[5].Cells[1]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "Specialty Biscuits, Ltd."; cell1 = table.Rows[5].Cells[2]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "Peter Wilson"; cell1 = table.Rows[5].Cells[3]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "29 King's Way"; cell1 = table.Rows[5].Cells[4]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "Manchester"; cell1 = table.Rows[5].Cells[5]; textFrame1 = cell1.TextBody; paragraph1 = textFrame1.Paragraphs.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; textpart1 = paragraph1.AddTextPart(); textpart1.Text = "UK"; slide4.Shapes.RemoveAt(1); #endregion MemoryStream stream = new MemoryStream(); presentation.Save(stream); presentation.Close(); stream.Position = 0; if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("SlidesSample.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("SlidesSample.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream); } }
private void btnGeneateDocument_Click(object sender, RoutedEventArgs e) { try { if (string.IsNullOrEmpty(txtFile.Text)) { MessageBox.Show("Please browse the files to generate document", "Input missing", MessageBoxButton.OK); } else { if (this.radioDestination.IsChecked == true) { //Creates presentation instance for source IPresentation sourcePresentation = Presentation.Open(txtFile.Tag.ToString()); //Clones the first slide of the presentation ISlide slide = sourcePresentation.Slides[0].Clone(); //Creates instance for the destination presentation IPresentation destinationPresentation = Presentation.Open(destTextBox.Tag.ToString()); //Adding the cloned slide to the destination presentation by using Destination option. destinationPresentation.Slides.Add(slide, PasteOptions.UseDestinationTheme, sourcePresentation); //Closing the Source presentation sourcePresentation.Close(); //Saving the Destination presentaiton. destinationPresentation.Save("ClonedUsingDestination.pptx"); //Closing the destination presentation destinationPresentation.Close(); if (MessageBox.Show("First slide is cloned and added as last slide to the Presentation,Do you want to view the resultant Presentation?", "Finished Cloning", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { #if !NETCore System.Diagnostics.Process.Start("ClonedUsingDestination.pptx"); #else System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("ClonedUsingDestination.pptx") { UseShellExecute = true }; process.Start(); #endif } } else { //Creates instance for the source presentation IPresentation sourcePresentation = Presentation.Open(txtFile.Tag.ToString()); //Clones the first slide of the presentation ISlide slide = sourcePresentation.Slides[0].Clone(); //Creates instance for the destination presentation IPresentation destinationPresentation = Presentation.Open(destTextBox.Tag.ToString()); //Adding the cloned slide to the destination presentation by using Destination option. destinationPresentation.Slides.Add(slide, PasteOptions.SourceFormatting, sourcePresentation); //Closing the Source presentation sourcePresentation.Close(); //Saving the Destination presentaiton. destinationPresentation.Save("ClonedUsingSource.pptx"); //Closing the destinatin presentation destinationPresentation.Close(); if (MessageBox.Show("First slide is cloned and added as last slide to the Presentation,Do you want to view the resultant Presentation?", "Finished Cloning", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { #if !NETCore System.Diagnostics.Process.Start("ClonedUsingSource.pptx"); #else System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("ClonedUsingSource.pptx") { UseShellExecute = true }; process.Start(); #endif } } } } catch (IOException) { MessageBox.Show("Please close the generated Presentation", "File is open", MessageBoxButton.OK); } catch (Exception) { MessageBox.Show("This file could not be cloned , please contact Syncfusion Direct-Trac system at http://www.syncfusion.com/support/default.aspx for any queries. ", "OOPS..Sorry!", MessageBoxButton.OK); this.Close(); } }
private void btnCreatePresn_Click(object sender, EventArgs e) { //Creates a new instance of the presentation. using (IPresentation presentation = Presentation.Create()) { #region Slide1 //To add a slide to PowerPoint presentation ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleOnly); //To set the table title in a slide SetTableTitle(slide); //Get table data from xml file DataSet dataSet = new DataSet(); #if !NETCore dataSet.ReadXml(@"..\..\..\..\..\..\Common\Data\Presentation\TableData.xml"); #else dataSet.ReadXml(@"..\..\..\..\..\..\..\Common\Data\Presentation\TableData.xml"); #endif int columnCount = dataSet.Tables[0].Rows.Count + 1; int rowCount = dataSet.Tables.Count - 1; //To add a new table in slide. ITable table = slide.Shapes.AddTable(rowCount, columnCount, 61.92, 95.76, 856.8, 378.72); //To set the style for the table. table.BuiltInStyle = BuiltInTableStyle.MediumStyle2Accent6; //To set category title SetCategoryTitle(table); //Iterates and sets the values to the table cells. for (int rowIndex = 0; rowIndex < table.Rows.Count; rowIndex++) { IRow row = table.Rows[rowIndex]; if (rowIndex == 0) { AddHeaderRow(row, dataSet.Tables[0].Rows); } else { AddCell(row, dataSet.Tables[rowIndex + 1]); } } #endregion //Saves the presentation presentation.Save("TablesSample.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("TablesSample.pptx"); #else System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("TablesSample.pptx") { UseShellExecute = true }; process.Start(); #endif this.Close(); } } }
public void createPresentation(string title, string body, List <string> images) { //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(255, 255, 255); //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; //Add description content to the slide by adding a new TextBox IShape descriptionShape = slide.AddTextBox(53.22, 141.73, 874.19, 77.70); // Parse bold text in body IParagraph bodyParagraph = descriptionShape.TextBody.AddParagraph(); String regular = ""; String bold = ""; for (int i = 0; i < body.Length; i++) { int lIndex = 0; int rIndex = 0; if (body[i].Equals('*') && body[i + 1].Equals('*')) { lIndex = i + 2; rIndex = body.IndexOf("**", lIndex, body.Length - lIndex); bold = bold + body.Substring(lIndex, rIndex - lIndex); // Console.WriteLine("result = " + result); ITextPart textPart1 = bodyParagraph.TextParts.Add(); textPart1.Text = regular; textPart1.Font.Bold = false; regular = ""; ITextPart textPart2 = bodyParagraph.TextParts.Add(); textPart2.Text = bold; textPart2.Font.Bold = true; bold = ""; if (rIndex + 2 < body.Length) { i = rIndex + 1; } else { break; } } else { regular = regular + body[i]; } } ITextPart textPart = bodyParagraph.TextParts.Add(); textPart.Text = regular; // regular = ""; using (WebClient client = new WebClient()) { int i = 0; foreach (string image in images) { // Download images from URLs string localImage = $@"..\..\image{i}.jpg"; client.DownloadFile(new Uri(image), localImage); //Gets a picture as stream. Stream pictureStream = File.Open(localImage, FileMode.Open); //Adds the picture to a slide by specifying its size and position. if (i == 0) { slide.Shapes.AddPicture(pictureStream, 199.79, 238.59, 140, 140); } else if (i == 1) { slide.Shapes.AddPicture(pictureStream, 349.79, 238.59, 140, 140); } else if (i == 2) { slide.Shapes.AddPicture(pictureStream, 499.79, 238.59, 140, 140); } else { break; } pictureStream.Close(); i++; } } //Save the PowerPoint Presentation pptxDoc.Save(@"..\..\SEH Challenge.pptx"); //Close the PowerPoint presentation pptxDoc.Close(); }
protected void LoadPPTx() { var filePath = string.Empty; using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.InitialDirectory = "c:\\"; openFileDialog.Filter = "pptx files (*.pptx)|*.pptx"; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { //Get the path of PowerPoint file filePath = openFileDialog.FileName; } } FileInfo fileCheck = new FileInfo(filePath); //Gets the file path to the sample pptx that is getting saved if (!IsFileLocked(fileCheck)) //If the file is not open then create and save PowerPoint else throw error message { //Opens an existing PowerPoint presentation. IPresentation pptxDoc = Presentation.Open(filePath); //Creates a slide at the end of the PowerPoint presentation ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.TitleAndContent); //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(pptTitle).HorizontalAlignment = HorizontalAlignmentType.Center; //Adds content to the text box IShape descriptionShape = slide.Shapes[1] as IShape; descriptionShape.TextBody.AddParagraph(pptText); //Saves the Presentation to the file system. pptxDoc.Save("Output.pptx"); //Following algorithm gets all the images that were selected and puts them into the pptx if (imageToPptIndex.Count != 0) { double imageOffset = 499.79; using (WebClient webClient = new WebClient()) { for (int i = 0; i < imageToPptIndex.Count; i++) { string imageUrl = imageList[(int)imageToPptIndex[i]]; byte[] imageBytes; HttpWebRequest imageRequest = (HttpWebRequest)WebRequest.Create(imageUrl); WebResponse imageResponse = imageRequest.GetResponse(); Stream responseStream = imageResponse.GetResponseStream(); using (BinaryReader br = new BinaryReader(responseStream)) { imageBytes = br.ReadBytes(500000); br.Close(); } responseStream.Close(); imageResponse.Close(); //Gets a picture as stream. MemoryStream stream = new MemoryStream(imageBytes); //Adds the picture to a slide by specifying its size and position. slide.Shapes.AddPicture(stream, imageOffset + i * 10, 238.59, 364.54, 192.16); //Offset each image so the user can see the different images on the pptx stream.Close(); } } } pptxDoc.Save(filePath); //Saves the pptx pptxDoc.Close(); //closes pptx stream //Dialog box opens, asking the user if they want to open the pptx that was created. If yes then the pptx opens if not then the box closes DialogResult result = MessageBox.Show("Slide has been added! Would you like to open the PowerPoint?", "Slide Added", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { Process proc = Process.Start(filePath); //Opens and runs the pptx } else { //close } } else { MessageBox.Show("File is already open and can not be saved!\nPlease close The PowerPoint", "PowerPoint Open", MessageBoxButtons.OK); } }
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.65 * 72; titleShape.Top = 0.24 * 72; titleShape.Width = 11.5 * 72; titleShape.Height = 1.45 * 72; //Add title content titleShape.TextBody.AddParagraph("Ole Object"); //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.Left; //Add text box of specific size and position IShape heading = slide.Shapes.AddTextBox(0.84 * 72, 1.65 * 72, 2.23 * 72, 0.51 * 72); //Add paragraph to text box heading.TextBody.AddParagraph("MS Word 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; #if !NETCore string mswordPath = @"..\..\..\..\..\..\Common\Data\Presentation\OleTemplate.docx"; string imagePath = @"..\..\..\..\..\..\Common\Images\Presentation\OlePicture.png"; #else string mswordPath = @"..\..\..\..\..\..\..\Common\Data\Presentation\OleTemplate.docx"; string imagePath = @"..\..\..\..\..\..\..\Common\Images\Presentation\OlePicture.png"; #endif //Get the word file as stream Stream wordStream = File.Open(mswordPath, FileMode.Open); //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, "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; //Save the presentation presentation.Save("InsertOLEObject.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) { #if !NETCore System.Diagnostics.Process.Start("InsertOLEObject.pptx"); #else System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("InsertOLEObject.pptx") { UseShellExecute = true }; process.Start(); #endif this.Close(); } }
protected void CreatePPTX() { var filePath = string.Empty; MessageBox.Show("Please Select The Folder You Would Like The PowerPoint To Be In", "Folder Select", MessageBoxButtons.OK); using (var fbd = new FolderBrowserDialog()) { DialogResult fileResult = fbd.ShowDialog(); if (fileResult == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath)) { filePath = fbd.SelectedPath + "\\Sample.pptx"; } } if (filePath != "") { if (IsSampleFileMade(filePath)) //If the file is made and is not open then create and save PowerPoint else throw error message { DialogResult overwriteResult = MessageBox.Show("A PowerPoint With The Name Sample.pptx Is Already Made\nWould You Like To Save Over It?", "PowerPoint Already Exists", MessageBoxButtons.YesNo); if (overwriteResult == DialogResult.Yes) { IPresentation pptxDoc = Presentation.Create(); //Creates new powerpoint ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.TitleAndContent); //Creates new slide //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(pptTitle).HorizontalAlignment = HorizontalAlignmentType.Center; //Adds content to the text box IShape descriptionShape = slide.Shapes[1] as IShape; descriptionShape.TextBody.AddParagraph(pptText); //Following algorithm gets all the images that were selected and puts them into the pptx if (imageToPptIndex.Count != 0) { double imageOffset = 499.79; using (WebClient webClient = new WebClient()) { for (int i = 0; i < imageToPptIndex.Count; i++) { string imageUrl = imageList[(int)imageToPptIndex[i]]; byte[] imageBytes; HttpWebRequest imageRequest = (HttpWebRequest)WebRequest.Create(imageUrl); WebResponse imageResponse = imageRequest.GetResponse(); Stream responseStream = imageResponse.GetResponseStream(); using (BinaryReader br = new BinaryReader(responseStream)) { imageBytes = br.ReadBytes(500000); br.Close(); } responseStream.Close(); imageResponse.Close(); //Gets a picture as stream. MemoryStream stream = new MemoryStream(imageBytes); //Adds the picture to a slide by specifying its size and position. slide.Shapes.AddPicture(stream, imageOffset + i * 10, 238.59, 364.54, 192.16); //Offset each image so the user can see the different images on the pptx stream.Close(); } } } pptxDoc.Save(filePath); //Saves the pptx pptxDoc.Close(); //closes pptx stream //Dialog box opens, asking the user if they want to open the pptx that was created. If yes then the pptx opens if not then the box closes DialogResult result = MessageBox.Show("PowerPoint has been created! Would you like to open it?", "PowerPoint Created", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { Process proc = Process.Start(filePath); //Opens and runs the pptx } else { //close } } else { //close } } else { if (File.Exists(filePath)) //If file is made and the file exists then the pptx must be open. Throw error message { MessageBox.Show("File is already open and can not be saved!\nPlease close The PowerPoint", "PowerPoint Open", MessageBoxButtons.OK); } else //File is not made yet { IPresentation pptxDoc = Presentation.Create(); //Creates new powerpoint ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.TitleAndContent); //Creates new slide //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(pptTitle).HorizontalAlignment = HorizontalAlignmentType.Center; //Adds content to the text box IShape descriptionShape = slide.Shapes[1] as IShape; descriptionShape.TextBody.AddParagraph(pptText); //Following algorithm gets all the images that were selected and puts them into the pptx if (imageToPptIndex.Count != 0) { double imageOffset = 499.79; using (WebClient webClient = new WebClient()) { for (int i = 0; i < imageToPptIndex.Count; i++) { string imageUrl = imageList[(int)imageToPptIndex[i]]; byte[] imageBytes; HttpWebRequest imageRequest = (HttpWebRequest)WebRequest.Create(imageUrl); WebResponse imageResponse = imageRequest.GetResponse(); Stream responseStream = imageResponse.GetResponseStream(); using (BinaryReader br = new BinaryReader(responseStream)) { imageBytes = br.ReadBytes(500000); br.Close(); } responseStream.Close(); imageResponse.Close(); //Gets a picture as stream. MemoryStream stream = new MemoryStream(imageBytes); //Adds the picture to a slide by specifying its size and position. slide.Shapes.AddPicture(stream, imageOffset + i * 10, 238.59, 364.54, 192.16); //Offset each image so the user can see the different images on the pptx stream.Close(); } } } pptxDoc.Save(filePath); //Saves the pptx pptxDoc.Close(); //closes pptx stream //Dialog box opens, asking the user if they want to open the pptx that was created. If yes then the pptx opens if not then the box closes DialogResult result = MessageBox.Show("PowerPoint has been created! Would you like to open it?", "PowerPoint Created", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { Process proc = Process.Start(filePath); //Opens and runs the pptx } else { //close } } } } else { //close } }
protected void Button1_Click(object sender, EventArgs e) { //Create an instance for PowerPoint IPresentation presentation = Presentation.Create(); //Add a blank slide to Presentation ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank); //Add header shape IShape headerTextBox = slide.Shapes.AddTextBox(58.44, 53.85, 221.93, 81.20); //Add a paragraph into the text box IParagraph paragraph = headerTextBox.TextBody.AddParagraph("Flow chart with "); //Add a textPart ITextPart textPart = paragraph.AddTextPart("Connector"); //Change the color of the font textPart.Font.Color = ColorObject.FromArgb(44, 115, 230); //Make the textpart bold textPart.Font.Bold = true; //Set the font size of the paragraph paragraph.Font.FontSize = 28; //Add start shape to slide IShape startShape = slide.Shapes.AddShape(AutoShapeType.FlowChartTerminator, 420.45, 36.35, 133.93, 50.39); //Add a paragraph into the start shape text body AddParagraph(startShape, "Start", ColorObject.FromArgb(255, 149, 34)); //Add alarm shape to slide IShape alarmShape = slide.Shapes.AddShape(AutoShapeType.FlowChartProcess, 420.45, 126.72, 133.93, 50.39); //Add a paragraph into the alarm shape text body AddParagraph(alarmShape, "Alarm Rings", ColorObject.FromArgb(255, 149, 34)); //Add condition shape to slide IShape conditionShape = slide.Shapes.AddShape(AutoShapeType.FlowChartDecision, 420.45, 222.42, 133.93, 97.77); //Add a paragraph into the condition shape text body AddParagraph(conditionShape, "Ready to Get Up ?", ColorObject.FromArgb(44, 115, 213)); //Add wake up shape to slide IShape wakeUpShape = slide.Shapes.AddShape(AutoShapeType.FlowChartProcess, 420.45, 361.52, 133.93, 50.39); //Add a paragraph into the wake up shape text body AddParagraph(wakeUpShape, "Wake Up", ColorObject.FromArgb(44, 115, 213)); //Add end shape to slide IShape endShape = slide.Shapes.AddShape(AutoShapeType.FlowChartTerminator, 420.45, 453.27, 133.93, 50.39); //Add a paragraph into the end shape text body AddParagraph(endShape, "End", ColorObject.FromArgb(44, 115, 213)); //Add snooze shape to slide IShape snoozeShape = slide.Shapes.AddShape(AutoShapeType.FlowChartProcess, 624.85, 245.79, 159.76, 50.02); //Add a paragraph into the snooze shape text body AddParagraph(snoozeShape, "Hit Snooze button", ColorObject.FromArgb(255, 149, 34)); //Add relay shape to slide IShape relayShape = slide.Shapes.AddShape(AutoShapeType.FlowChartDelay, 624.85, 127.12, 159.76, 49.59); //Add a paragraph into the relay shape text body AddParagraph(relayShape, "Relay", ColorObject.FromArgb(255, 149, 34)); //Connect the start shape with alarm shape using connector IConnector connector1 = slide.Shapes.AddConnector(ConnectorType.Straight, startShape, 2, alarmShape, 0); //Set the arrow style for the connector connector1.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Connect the alarm shape with condition shape using connector IConnector connector2 = slide.Shapes.AddConnector(ConnectorType.Straight, alarmShape, 2, conditionShape, 0); //Set the arrow style for the connector connector2.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Connect the condition shape with snooze shape using connector IConnector connector3 = slide.Shapes.AddConnector(ConnectorType.Straight, conditionShape, 3, snoozeShape, 1); //Set the arrow style for the connector connector3.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Connect the snooze shape with relay shape using connector IConnector connector4 = slide.Shapes.AddConnector(ConnectorType.Straight, snoozeShape, 0, relayShape, 2); //Set the arrow style for the connector connector4.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Connect the relay shape with alarm shape using connector IConnector connector5 = slide.Shapes.AddConnector(ConnectorType.Straight, relayShape, 1, alarmShape, 3); //Set the arrow style for the connector connector5.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Connect the condition shape with wake up shape using connector IConnector connector6 = slide.Shapes.AddConnector(ConnectorType.Straight, conditionShape, 2, wakeUpShape, 0); //Set the arrow style for the connector connector6.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Connect the wake up shape with end shape using connector IConnector connector7 = slide.Shapes.AddConnector(ConnectorType.Straight, wakeUpShape, 2, endShape, 0); //Set the arrow style for the connector connector7.LineFormat.EndArrowheadStyle = ArrowheadStyle.Arrow; //Add No textbox to slide IShape noTextBox = slide.Shapes.AddTextBox(564.02, 245.43, 51.32, 26.22); //Add a paragraph into the text box noTextBox.TextBody.AddParagraph("No"); //Add Yes textbox to slide IShape yesTextBox = slide.Shapes.AddTextBox(487.21, 327.99, 50.09, 26.23); //Add a paragraph into the text box yesTextBox.TextBody.AddParagraph("Yes"); //Saves the presentation presentation.Save("ConnectorSample.pptx", FormatType.Pptx, Response); }
private void btnCreateImage_Click(object sender, RoutedEventArgs e) { try { //Opens the existing presentation stream. using (IPresentation presentation = Presentation.Create()) { ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleOnly); IParagraph paragraph = ((IShape)slide.Shapes[0]).TextBody.Paragraphs.Add(); //Apply center alignment to the paragraph paragraph.HorizontalAlignment = HorizontalAlignmentType.Center; //Add slide title ITextPart textPart = paragraph.AddTextPart("Northwind Management Report"); textPart.Font.Color = ColorObject.FromArgb(46, 116, 181); //Get chart data from xml file DataSet dataSet = new DataSet(); dataSet.ReadXml(@"Assets\Presentation\Products.xml"); //Add a new chart to the presentation slide IPresentationChart chart = slide.Charts.AddChart(44.64, 133.2, 870.48, 380.16); //Set chart type chart.ChartType = OfficeChartType.Pie; //Set chart title chart.ChartTitle = "Best Selling Products"; //Set chart properties font name and size chart.ChartTitleArea.FontName = "Calibri (Body)"; chart.ChartTitleArea.Size = 14; for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++) { chart.ChartData.SetValue(i + 2, 1, dataSet.Tables[0].Rows[i].ItemArray[1]); chart.ChartData.SetValue(i + 2, 2, dataSet.Tables[0].Rows[i].ItemArray[2]); } //Create a new chart series with the name “Sales” AddSeriesForChart(chart); //Setting the font size of the legend. chart.Legend.TextArea.Size = 14; //Setting background color chart.ChartArea.Fill.ForeColor = System.Drawing.Color.FromArgb(242, 242, 242); chart.PlotArea.Fill.ForeColor = System.Drawing.Color.FromArgb(242, 242, 242); chart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None; chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 11, 1]; //Saves the presentation instance to the stream. presentation.Save("ChartCreation.pptx"); if (System.Windows.MessageBox.Show("Do you want to view the generated PowerPoint Presentation?", "Chart Creation", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("ChartCreation.pptx") { UseShellExecute = true }; process.Start(); } } } catch (Exception) { System.Windows.MessageBox.Show("This Presentation could not be created, please contact Syncfusion Direct-Trac system at http://www.syncfusion.com/support/default.aspx for any queries. ", "OOPS..Sorry!", MessageBoxButton.OK); } }
private void OnButtonClicked(object sender, EventArgs e) { string resourcePath = ""; #if COMMONSB resourcePath = "SampleBrowser.Samples.Presentation.Samples.Templates.Images.pptx"; #else resourcePath = "SampleBrowser.Presentation.Samples.Templates.Images.pptx"; #endif Assembly assembly = typeof(Comments).GetTypeInfo().Assembly; Stream fileStream = assembly.GetManifestResourceStream(resourcePath); IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fileStream); #region Slide 1 ISlide slide1 = presentation.Slides[0]; IShape shape1 = (IShape)slide1.Shapes[0]; shape1.Left = 1.27 * 72; shape1.Top = 0.85 * 72; shape1.Width = 10.86 * 72; shape1.Height = 3.74 * 72; ITextBody textFrame = shape1.TextBody; IParagraphs paragraphs = textFrame.Paragraphs; paragraphs.Add(); IParagraph paragraph = paragraphs[0]; paragraph.HorizontalAlignment = HorizontalAlignmentType.Left; ITextParts textParts = paragraph.TextParts; textParts.Add(); ITextPart textPart = textParts[0]; textPart.Text = "Essential Presentation "; textPart.Font.CapsType = TextCapsType.All; textPart.Font.FontName = "Calibri Light (Headings)"; textPart.Font.FontSize = 80; textPart.Font.Color = ColorObject.Black; IComment comment = slide1.Comments.Add(0.35, 0.04, "Author1", "A1", "Essential Presentation is available from 13.1 versions of Essential Studio", DateTime.Now); #endregion #region Slide2 ISlide slide2 = presentation.Slides.Add(SlideLayoutType.Blank); IPresentationChart chart = slide2.Shapes.AddChart(230, 80, 500, 400); //Specifies the chart title chart.ChartTitle = "Sales Analysis"; //Sets chart data - Row1 chart.ChartData.SetValue(1, 2, "Jan"); chart.ChartData.SetValue(1, 3, "Feb"); chart.ChartData.SetValue(1, 4, "March"); //Sets chart data - Row2 chart.ChartData.SetValue(2, 1, 2010); chart.ChartData.SetValue(2, 2, 60); chart.ChartData.SetValue(2, 3, 70); chart.ChartData.SetValue(2, 4, 80); //Sets chart data - Row3 chart.ChartData.SetValue(3, 1, 2011); chart.ChartData.SetValue(3, 2, 80); chart.ChartData.SetValue(3, 3, 70); chart.ChartData.SetValue(3, 4, 60); //Sets chart data - Row4 chart.ChartData.SetValue(4, 1, 2012); chart.ChartData.SetValue(4, 2, 60); chart.ChartData.SetValue(4, 3, 70); chart.ChartData.SetValue(4, 4, 80); //Creates a new chart series with the name IOfficeChartSerie serieJan = chart.Series.Add("Jan"); //Sets the data range of chart serie – start row, start column, end row, end column serieJan.Values = chart.ChartData[2, 2, 4, 2]; //Creates a new chart series with the name IOfficeChartSerie serieFeb = chart.Series.Add("Feb"); //Sets the data range of chart serie – start row, start column, end row, end column serieFeb.Values = chart.ChartData[2, 3, 4, 3]; //Creates a new chart series with the name IOfficeChartSerie serieMarch = chart.Series.Add("March"); //Sets the data range of chart series – start row, start column, end row, end column serieMarch.Values = chart.ChartData[2, 4, 4, 4]; //Sets the data range of the category axis chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 4, 1]; //Specifies the chart type chart.ChartType = OfficeChartType.Column_Clustered_3D; slide2.Comments.Add(0.35, 0.04, "Author2", "A2", "All 3D-chart types are supported in Presentation library.", DateTime.Now); #endregion #region Slide3 ISlide slide3 = presentation.Slides.Add(SlideLayoutType.ContentWithCaption); slide3.Background.Fill.FillType = FillType.Solid; slide3.Background.Fill.SolidFill.Color = ColorObject.White; //Adds shape in slide IShape shape2 = (IShape)slide3.Shapes[0]; shape2.Left = 0.47 * 72; shape2.Top = 1.15 * 72; shape2.Width = 3.5 * 72; shape2.Height = 4.91 * 72; ITextBody textFrame1 = shape2.TextBody; //Instance to hold paragraphs in textframe IParagraphs paragraphs1 = textFrame1.Paragraphs; IParagraph paragraph1 = paragraphs1.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Left; ITextPart textpart1 = paragraph1.AddTextPart(); textpart1.Text = "Lorem ipsum dolor sit amet, lacus amet amet ultricies. Quisque mi venenatis morbi libero, orci dis, mi ut et class porta, massa ligula magna enim, aliquam orci vestibulum tempus."; textpart1.Font.Color = ColorObject.White; textpart1.Font.FontName = "Calibri (Body)"; textpart1.Font.FontSize = 15; paragraphs1.Add(); IParagraph paragraph2 = paragraphs1.Add(); paragraph2.HorizontalAlignment = HorizontalAlignmentType.Left; textpart1 = paragraph2.AddTextPart(); textpart1.Text = "Turpis facilisis vitae consequat, cum a a, turpis dui consequat massa in dolor per, felis non amet."; textpart1.Font.Color = ColorObject.White; textpart1.Font.FontName = "Calibri (Body)"; textpart1.Font.FontSize = 15; paragraphs1.Add(); IParagraph paragraph3 = paragraphs1.Add(); paragraph3.HorizontalAlignment = HorizontalAlignmentType.Left; textpart1 = paragraph3.AddTextPart(); textpart1.Text = "Auctor eleifend in omnis elit vestibulum, donec non elementum tellus est mauris, id aliquam, at lacus, arcu pretium proin lacus dolor et. Eu tortor, vel ultrices amet dignissim mauris vehicula."; textpart1.Font.Color = ColorObject.White; textpart1.Font.FontName = "Calibri (Body)"; textpart1.Font.FontSize = 15; paragraphs1.Add(); IParagraph paragraph4 = paragraphs1.Add(); paragraph4.HorizontalAlignment = HorizontalAlignmentType.Left; textpart1 = paragraph4.AddTextPart(); textpart1.Text = "Lorem tortor neque, purus taciti quis id. Elementum integer orci accumsan minim phasellus vel."; textpart1.Font.Color = ColorObject.White; textpart1.Font.FontName = "Calibri (Body)"; textpart1.Font.FontSize = 15; paragraphs1.Add(); slide3.Shapes.RemoveAt(1); slide3.Shapes.RemoveAt(1); //Adds picture in the shape resourcePath = ""; #if COMMONSB resourcePath = "SampleBrowser.Samples.Presentation.Samples.Templates.tablet.jpg"; #else resourcePath = "SampleBrowser.Presentation.Samples.Templates.tablet.jpg"; #endif fileStream = assembly.GetManifestResourceStream(resourcePath); IPicture picture1 = slide3.Shapes.AddPicture(fileStream, 5.18 * 72, 1.15 * 72, 7.3 * 72, 5.31 * 72); fileStream.Dispose(); slide3.Comments.Add(0.14, 0.04, "Author3", "A3", "Can we use a different font family for this text?", DateTime.Now); #endregion MemoryStream memoryStream = new MemoryStream(); presentation.Save(memoryStream); presentation.Close(); memoryStream.Position = 0; if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("CommentsSamples.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", memoryStream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("CommentsSamples.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", memoryStream); } }
void OnInsertOleButtonClicked(object sender, EventArgs e) { Assembly assembly = typeof(GettingStarted).GetTypeInfo().Assembly; //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 = ""; #if COMMONSB mswordPath = "SampleBrowser.Samples.Presentation.Samples.Templates.OleTemplate.docx"; #else mswordPath = "SampleBrowser.Presentation.Samples.Templates.OleTemplate.docx"; #endif //Get the word file as stream Stream wordStream = assembly.GetManifestResourceStream(mswordPath); string imagePath = ""; #if COMMONSB imagePath = "SampleBrowser.Samples.Presentation.Samples.Templates.OlePicture.png"; #else imagePath = "SampleBrowser.Presentation.Samples.Templates.OlePicture.png"; #endif //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; MemoryStream stream = new MemoryStream(); presentation.Save(stream); presentation.Close(); stream.Position = 0; if (Device.RuntimePlatform == Device.UWP) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("InsertOLEObject.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("InsertOLEObject.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream); } }
void OnButtonClicked(object sender, EventArgs e) { string resourcePath = "SampleBrowser.Presentation.Samples.Templates.Slides.pptx"; Assembly assembly = typeof(Slides).GetTypeInfo().Assembly; Stream fileStream = assembly.GetManifestResourceStream(resourcePath); //Open a existing PowerPoint presentation IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fileStream); #region Slide1 ISlide slide1 = presentation.Slides[0]; IShape shape1 = slide1.Shapes[0] as IShape; shape1.Left = 108; shape1.Top = 139.68; shape1.Width = 743.04; shape1.Height = 144; ITextBody textFrame1 = shape1.TextBody; IParagraphs paragraphs1 = textFrame1.Paragraphs; IParagraph paragraph1 = paragraphs1.Add(); paragraphs1[0].IndentLevelNumber = 0; AddParagraphData(paragraph1, "ESSENTIAL PRESENTATION", "Calibri", 48, true); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Center; slide1.Shapes.RemoveAt(1); #endregion #region Slide2 ISlide slide2 = presentation.Slides.Add(SlideLayoutType.SectionHeader); shape1 = slide2.Shapes[0] as IShape; shape1.Left = 55; shape1.Top = 23; shape1.Width = 573; shape1.Height = 71; textFrame1 = shape1.TextBody; //Instance to hold paragraphs in textframe paragraphs1 = textFrame1.Paragraphs; paragraph1 = paragraphs1.Add(); AddParagraphData(paragraph1, "Slide with simple text", "Calibri", 40, false); paragraphs1[0].HorizontalAlignment = HorizontalAlignmentType.Left; IShape shape2 = slide2.Shapes[1] as IShape; shape2.Left = 87; shape2.Top = 119; shape2.Width = 725; shape2.Height = 355; ITextBody textFrame2 = shape2.TextBody; //Instance to hold paragraphs in textframe IParagraphs paragraphs2 = textFrame2.Paragraphs; //Add paragrpah text IParagraph paragraph_1 = paragraphs2.Add(); AddParagraphData(paragraph_1, "Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.", "Calibri", 15, false); IParagraph paragraph_2 = paragraphs2.Add(); AddParagraphData(paragraph_2, "In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group.", "Calibri", 15, false); #endregion #region Slide3 slide2 = presentation.Slides.Add(SlideLayoutType.TwoContent); shape1 = slide2.Shapes[0] as IShape; shape1.Left = 26; shape1.Top = 37; shape1.Width = 815; shape1.Height = 76; //Adds textframe in shape textFrame1 = shape1.TextBody; //Instance to hold paragraphs in textframe paragraphs1 = textFrame1.Paragraphs; paragraphs1.Add(); paragraph1 = paragraphs1[0]; AddParagraphData(paragraph1, "Slide with Image", "Calibri", 44, false); //Adds shape in slide shape2 = slide2.Shapes[1] as IShape; shape2.Left = 578; shape2.Top = 141; shape2.Width = 316; shape2.Height = 326; textFrame2 = shape2.TextBody; //Instance to hold paragraphs in textframe paragraphs2 = textFrame2.Paragraphs; IParagraph paragraph2 = paragraphs2.Add(); AddParagraphData(paragraph2, "The Northwind sample database (Northwind.mdb) is included with all versions of Access. It provides data you can experiment with and database objects that demonstrate features you might want to implement in your own databases.", "Calibri", 16, false); IParagraph paragraph3 = paragraphs2.Add(); AddParagraphData(paragraph3, "Using Northwind, you can become familiar with how a relational database is structured and how the database objects work together to help you enter, store, manipulate, and print your data.", "Calibri", 16, false); IParagraph paragraph4 = paragraphs2.Add(); // AddParagraphData(paragraph4, ref textpart1, "While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.", "Calibri", 16); IShape shape3 = (IShape)slide2.Shapes[2]; slide2.Shapes.RemoveAt(2); //Adds picture in the shape resourcePath = "SampleBrowser.Presentation.Samples.Templates.tablet.jpg"; assembly = typeof(Slides).GetTypeInfo().Assembly; fileStream = assembly.GetManifestResourceStream(resourcePath); slide2.Shapes.AddPicture(fileStream, 58, 141, 477, 318); fileStream.Close(); #endregion #region Slide4 ISlide slide4 = presentation.Slides.Add(SlideLayoutType.TwoContent); shape1 = slide4.Shapes[0] as IShape; shape1.Left = 37; shape1.Top = 24; shape1.Width = 815; shape1.Height = 76; textFrame1 = shape1.TextBody; //Instance to hold paragraphs in textframe paragraphs1 = textFrame1.Paragraphs; paragraphs1.Add(); paragraph1 = paragraphs1[0]; AddParagraphData(paragraph1, "Slide with Table", "Calibri", 44, false); shape2 = slide4.Shapes[1] as IShape; slide4.Shapes.Remove(shape2); ITable table = (ITable)slide4.Shapes.AddTable(6, 6, 58, 154, 823, 273); table.Rows[0].Height = 61.2; table.Rows[1].Height = 30; table.Rows[2].Height = 61; table.Rows[3].Height = 61; table.Rows[4].Height = 61; table.Rows[5].Height = 61; table.HasBandedRows = true; table.HasHeaderRow = true; table.HasBandedColumns = false; table.BuiltInStyle = BuiltInTableStyle.MediumStyle2Accent1; ICell cell1 = table.Rows[0].Cells[0]; textFrame2 = cell1.TextBody; paragraph2 = textFrame2.Paragraphs.Add(); paragraph2.HorizontalAlignment = HorizontalAlignmentType.Center; ITextPart textPart2 = paragraph2.AddTextPart(); textPart2.Text = "ID"; ICell cell2 = table.Rows[0].Cells[1]; ITextBody textFrame3 = cell2.TextBody; paragraph3 = textFrame3.Paragraphs.Add(); paragraph3.HorizontalAlignment = HorizontalAlignmentType.Center; ITextPart textPart3 = paragraph3.AddTextPart(); textPart3.Text = "Company Name"; ICell cell3 = table.Rows[0].Cells[2]; ITextBody textFrame4 = cell3.TextBody; paragraph4 = textFrame4.Paragraphs.Add(); paragraph4.HorizontalAlignment = HorizontalAlignmentType.Center; ITextPart textPart4 = paragraph4.AddTextPart(); textPart4.Text = "Contact Name"; ICell cell4 = table.Rows[0].Cells[3]; ITextBody textFrame5 = cell4.TextBody; IParagraph paragraph5 = textFrame5.Paragraphs.Add(); paragraph5.HorizontalAlignment = HorizontalAlignmentType.Center; ITextPart textPart5 = paragraph5.AddTextPart(); textPart5.Text = "Address"; ICell cell5 = table.Rows[0].Cells[4]; ITextBody textFrame6 = cell5.TextBody; IParagraph paragraph6 = textFrame6.Paragraphs.Add(); paragraph6.HorizontalAlignment = HorizontalAlignmentType.Center; ITextPart textPart6 = paragraph6.AddTextPart(); textPart6.Text = "City"; ICell cell6 = table.Rows[0].Cells[5]; ITextBody textFrame7 = cell6.TextBody; IParagraph paragraph7 = textFrame7.Paragraphs.Add(); paragraph7.HorizontalAlignment = HorizontalAlignmentType.Center; ITextPart textPart7 = paragraph7.AddTextPart(); textPart7.Text = "Country"; //Add data in table AddTableData(cell1, table, textFrame1, paragraph1); slide4.Shapes.RemoveAt(1); #endregion MemoryStream stream = new MemoryStream(); presentation.Save(stream); presentation.Close(); stream.Position = 0; if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("SlidesSample.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("SlidesSample.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream); } }
private void ExportTemplate(int fieldId, string filePath) { try { IPresentation pptxDoc = Presentation.Open(@"Templates\Report.pptx"); Syncfusion.Drawing.Image image = null; List <FieldResultDetail> fieldResultDetail = fieldResultDetails.Where(p => p.RestaurantFieldId == fieldId && !string.IsNullOrWhiteSpace(p.AttachPath)).ToList(); //Adds a blank slide to Presentation int idxImg = 0; var field = fieldResults.FirstOrDefault(p => p.RestaurantFieldId == fieldId); string shiftWork = "C"; if (field.StartTime.Hour < 12) { shiftWork = "S"; } for (int idx = 1; idx < pptxDoc.Slides.Count; idx++) { ISlide itmSlide = pptxDoc.Slides[idx]; if (idx < pptxDoc.Slides.Count - 1) { //Adds normal shape to slide foreach (IShape itmShap in itmSlide.Shapes.OrderBy(p => p.ShapeName)) { if (itmShap.ShapeName.Contains("header")) { //xu ly replace ITextBody textBody = itmShap.TextBody; textBody.Text = textBody.Text.Replace("Localtion", field.LocationName); textBody.Text = textBody.Text.Replace("ActionDate", field.StartTime.ToString("yyyy-MM-dd")); if (field.StartTime.Hour < 13) { textBody.Text = textBody.Text.Replace("Shift", "Ca Sáng"); } else { textBody.Text = textBody.Text.Replace("Shift", "Ca Chiều"); } textBody.Text = textBody.Text.Replace("WorkingTime", $"{field.StartTime.ToString("HH:mm")} - {field.StartTime.ToString("HH:mm")}"); } else { if (idxImg <= fieldResultDetail.Count - 1 && !string.IsNullOrEmpty(fieldResultDetail[idxImg].AttachPath)) { using (Stream stream = new FileStream(fieldResultDetail[idxImg].AttachPath, FileMode.Open)) { image = Syncfusion.Drawing.Image.FromStream(stream); } IFill lineFormat = itmShap.Fill; lineFormat.FillType = FillType.Picture; lineFormat.PictureFill.ImageBytes = image.ImageData; } else { break; } idxImg++; } } } else { //lay duong dan folder. //search image string folder = fieldResultDetail[0].AttachPath.Substring(0, fieldResultDetail[0].AttachPath.LastIndexOf(@"\")); string[] fileResults = Directory.GetFiles(folder, $"ketqua_{shiftWork}*"); idxImg = 0; foreach (IShape itmShap in itmSlide.Shapes.OrderBy(p => p.ShapeName)) { if (itmShap.ShapeName.Contains("header")) { ITextBody textBody = itmShap.TextBody; textBody.Text = textBody.Text.Replace("Localtion", field.LocationName); textBody.Text = textBody.Text.Replace("ActionDate", field.StartTime.ToString("yyyy-MM-dd")); if (field.StartTime.Hour < 13) { textBody.Text = textBody.Text.Replace("Shift", "Ca Sáng"); } else { textBody.Text = textBody.Text.Replace("Shift", "Ca Chiều"); } textBody.Text = textBody.Text.Replace("WorkingTime", $"{field.StartTime.ToString("HH:mm")} - {field.StartTime.ToString("HH:mm")}"); //xu ly replace } else { using (Stream stream = new FileStream(fileResults[idxImg], FileMode.Open)) { image = Syncfusion.Drawing.Image.FromStream(stream); } IFill lineFormat = itmShap.Fill; lineFormat.FillType = FillType.Picture; lineFormat.PictureFill.ImageBytes = image.ImageData; idxImg++; } } } } pptxDoc.Save(filePath); pptxDoc.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }