//Create slide using SyncFusion framework private void btnCreateSlide_Click(object sender, EventArgs e) { user.Title = txtTitle.Text; user.TextField = txtTextField.Text; IPresentation powerpointDoc = Presentation.Create(); ISlide slide = powerpointDoc.Slides.Add(SlideLayoutType.Blank); IShape title = slide.AddTextBox(50, 40, 500, 100); title.TextBody.AddParagraph(user.Title); title.TextBody.Paragraphs[0].Font.FontSize = 24; IShape textfield = slide.AddTextBox(100, 110, 800, 300); textfield.TextBody.AddParagraph(user.TextField); for (int imgCt = 1; imgCt <= user.Images.Count; imgCt++) { var ms = new MemoryStream(); user.Images[imgCt - 1].Save(ms, ImageFormat.Png); IPicture picture = slide.Pictures.AddPicture(ms, ReturnImgLength(imgCt), 350, user.Images[imgCt - 1].Width * 1.25, user.Images[imgCt - 1].Height * 1.25); } powerpointDoc.Save("GeneratedPowerpoint.pptx"); powerpointDoc.Close(); ResetSelection(); }
public ActionResult CreateDocument() { // create a powerpoint instance IPresentation pptxDoc = Presentation.Create(); //Add slide to the the Powerpoint presentation ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank); //Addd a textbox to the slide IShape shape = slide.AddTextBox(10, 10, 500, 100); //Add a textbox to the text box shape.TextBody.AddParagraph("Welcome to Powerpoint"); //Save the PowerPoint Presentation pptxDoc.Save("Sample.pptx", FormatType.Pptx, HttpContext.ApplicationInstance.Response); // Close the PowerPoint presentation pptxDoc.Close(); ViewBag.Message = "Create A new SlideShow."; return(View()); }
private void btnCreatePowerPoint_Click(object sender, RoutedEventArgs e) { //Create a new PowerPoint presentation IPresentation powerpointDoc = Presentation.Create(); //Add a blank slide to the presentation ISlide slide = powerpointDoc.Slides.Add(SlideLayoutType.Blank); //Add a textbox to the slide IShape shape = slide.AddTextBox(400, 100, 500, 100); shape.TextBody.AddParagraph(titleAreaText.Text); //Add a text to the textbox. //shape.TextBody.AddParagraph(titleAreaText.Text); shape.TextBody.AddParagraph(textAreaText.Text); //Save the PowerPoint presentation powerpointDoc.Save("Sample.pptx"); //Close the PowerPoint presentation powerpointDoc.Close(); //Open the PowerPoint presentation System.Diagnostics.Process.Start("Sample.pptx"); }
private void Button_Click_6(object sender, RoutedEventArgs e) { //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); //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(titleWord.Text).HorizontalAlignment = HorizontalAlignmentType.Center; //Add description content to the slide by adding a new TextBox IShape descriptionShape = slide.AddTextBox(53.22, 141.73, 874.19, 77.70); descriptionShape.TextBody.Text = bodyPPT.Text; //Gets a picture as stream. Stream pictureStream = File.Open("C:/ImagesForPowerPoint/ImagesForPowerPoint/Images/image6.png", FileMode.Open); //Adds the picture to a slide by specifying its size and position. slide.Shapes.AddPicture(pictureStream, 499.79, 238.59, 364.54, 192.16); pictureStream.Close(); //Save the PowerPoint Presentation //pptxDoc.Save("Sample.pptx"); //Close the PowerPoint presentation //pptxDoc.Close(); }
public static void Main() { /* Take in values for numbers of slides and images to parse from HTML */ Console.WriteLine("How many items do you need?: "); string input = Console.ReadLine(); int number; Int32.TryParse(input, out number); /* Take in user response for image content */ Console.WriteLine("What would you like to search for?: "); var search = Console.ReadLine(); /* Load Shutterstock site and create new WebClient and scrape searching for <img src> tag */ var document = new HtmlWeb().Load("https://www.shutterstock.com/search/" + search); WebClient client = new WebClient(); var urls = document.DocumentNode.Descendants("img") .Select(e => e.GetAttributeValue("src", null)) .Where(s => !String.IsNullOrEmpty(s)); int x = 0; /* Initialize new PPT Presentation using SyncFusion */ IPresentation pptxDoc = Presentation.Create(); /* Iterate over urls of images, download to local directory number of specified images */ foreach (string item in urls) { if (x == number) { break; } client.DownloadFile(item, search + x + ".jpg"); Console.WriteLine(item); /* Create new Blank slide, take in User title text */ ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank); Console.WriteLine("Enter title text: "); var title = Console.ReadLine(); /* Open local image files scraped from web and add to slide with user defined title of each slide */ Stream pictureStream = File.Open("./" + search + x + ".jpg", FileMode.Open); slide.Pictures.AddPicture(pictureStream, slide.SlideSize.Width / 2, slide.SlideSize.Height / 2, 250, 250); IShape titleTextBox = slide.AddTextBox(slide.SlideSize.Width / 2, 10, 500, 500); IParagraph paragraph = titleTextBox.TextBody.AddParagraph(); ITextPart textPart = paragraph.AddTextPart(); textPart.Text = title; pictureStream.Dispose(); x++; } /* Save PPT project */ pptxDoc.Save("Sample.pptx"); pptxDoc.Close(); Console.ReadLine(); }
public IActionResult CreateSlide(string image, string header, string content) { WebClient webClient = new WebClient(); webClient.DownloadFile(image, "image.jpg"); //Create a new instance of PowerPoint Presentation file IPresentation pptxDoc = Presentation.Create(); //Add a new slide to file and apply background color ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.TitleOnly); //Specify the fill type and fill color for the slide background slide.Background.Fill.FillType = FillType.Solid; slide.Background.Fill.SolidFill.Color = ColorObject.FromArgb(232, 241, 229); //Add title content to the slide by accessing the title placeholder of the TitleOnly layout-slide IShape titleShape = slide.Shapes[0] as IShape; titleShape.TextBody.AddParagraph(header).HorizontalAlignment = HorizontalAlignmentType.Center; //Add description content to the slide by adding a new TextBox IShape descriptionShape = slide.AddTextBox(53.22, 141.73, 874.19, 77.70); descriptionShape.TextBody.Text = content; //Gets a picture as stream. FileStream pictureStream = new FileStream("image.jpg", FileMode.Open); //Adds the picture to a slide by specifying its size and position. slide.Shapes.AddPicture(pictureStream, 499.79, 238.59, 364.54, 192.16); //Save the PowerPoint Presentation as stream FileStream outputStream = new FileStream("Sample.pptx", FileMode.Create); pptxDoc.Save(outputStream); //Release all resources from stream outputStream.Dispose(); //Close the PowerPoint presentation pptxDoc.Close(); var displaySlide = new Result { Title = header, Content = content, Link = image }; return(View(displaySlide)); }
private void CreateInitialPPt() { String Title, TextDesc; Title = Title_txtBx.Text; TextDesc = Txt_Blk.Text; string today = DateTime.Now.ToShortDateString(); //Creates a new ppt doc IPresentation ppt_doc = Presentation.Create(); //Adding a initial slide to the ppt ISlide slide = ppt_doc.Slides.Add(SlideLayoutType.PictureWithCaption); //Specify the fill type and fill color for the slide background slide.Background.Fill.FillType = FillType.Solid; slide.Background.Fill.SolidFill.Color = ColorObject.FromArgb(232, 241, 229); //Add title content to the slide by accessing the title placeholder of the TitleOnly layout-slide IShape titleShape = slide.Shapes[0] as IShape; titleShape.TextBody.AddParagraph(Title).HorizontalAlignment = HorizontalAlignmentType.Center; //Adding a TextBox to the slide IShape shape = slide.AddTextBox(80, 200, 500, 100); shape.TextBody.AddParagraph(TextDesc); String imgName = GetImageName(); imgName = staticFilePath + imgName; //Gets a picture as stream. Stream pictureStream = File.Open(imgName, FileMode.Open); //Adds the picture to a slide by specifying its size and position. slide.Shapes.AddPicture(pictureStream, 499.79, 238.59, 364.54, 192.16); //Save the ppt ppt_doc.Save(Title + ".pptx"); //Dispose the image stream pictureStream.Dispose(); //closing the ppt ppt_doc.Close(); }
public void WritePPT(string sText) { try { using (var powerpointDoc = Presentation.Open(GeneratePath())) { ISlide slide = powerpointDoc.Slides[0]; IShape shape = slide.AddTextBox(10, 10, 500, 100); shape.TextBody.AddParagraph(sText); powerpointDoc.Save(GeneratePath()); } } catch (Exception) { throw; } }
private void GeneratePPT() { //Create a new PowerPoint presentation IPresentation powerpointDoc = Presentation.Create(); ISlide slide = powerpointDoc.Slides.Add(SlideLayoutType.TitleOnly); IShape titleShape = slide.Shapes[0] as IShape; titleShape.TextBody.AddParagraph(TitleInput.Text).HorizontalAlignment = HorizontalAlignmentType.Center; //Add a text to the textbox. IShape descriptionShape = slide.AddTextBox(53.22, 141.73, 874.19, 77.70); descriptionShape.TextBody.Text = BodyText.Text; Console.WriteLine(imgListView.SelectedItems.Count); // Grab checked images int x = 170, y = 0, indx = 0; foreach (int i in imgListView.CheckedIndices) { slide.Shapes.AddPicture(ToStream(listImg[i + 1]), x, y, 140, 140); x += 140; if (indx % 5 == 0) { y += 140; x = 170; } indx++; } //Save the PowerPoint presentation powerpointDoc.Save("Result.pptx"); //Close the PowerPoint presentation powerpointDoc.Close(); DialogResult res = MessageBox.Show("Result saved as Result.pptx"); }
// Export PPT slide private void Button_Click_Generate(object sender, RoutedEventArgs e) { //Create a new PowerPoint presentation IPresentation powerpointDoc = Presentation.Create(); //Add a blank slide to the presentation ISlide slide = powerpointDoc.Slides.Add(SlideLayoutType.TitleOnly); IShape titleShape = slide.Shapes[0] as IShape; titleShape.TextBody.AddParagraph(TitleBox.Text).HorizontalAlignment = HorizontalAlignmentType.Center; //Add a textbox to the slide IShape descriptionShape = slide.AddTextBox(53.22, 141.73, 874.19, 77.70); descriptionShape.TextBody.Text = TextBox.Text; List <Stream> pictureStreams = new List <Stream>(); if (btn1.IsChecked == true) { pictureStreams.Add(new MemoryStream(GetImage(luckyUrls[0]))); } if (btn2.IsChecked == true) { pictureStreams.Add(new MemoryStream(GetImage(luckyUrls[1]))); } if (btn3.IsChecked == true) { pictureStreams.Add(new MemoryStream(GetImage(luckyUrls[2]))); } if (btn4.IsChecked == true) { pictureStreams.Add(new MemoryStream(GetImage(luckyUrls[3]))); } if (btn5.IsChecked == true) { pictureStreams.Add(new MemoryStream(GetImage(luckyUrls[4]))); } if (btn6.IsChecked == true) { pictureStreams.Add(new MemoryStream(GetImage(luckyUrls[5]))); } if (btn7.IsChecked == true) { pictureStreams.Add(new MemoryStream(GetImage(luckyUrls[6]))); } if (btn8.IsChecked == true) { pictureStreams.Add(new MemoryStream(GetImage(luckyUrls[7]))); } if (btn9.IsChecked == true) { pictureStreams.Add(new MemoryStream(GetImage(luckyUrls[8]))); } double top = 53.22; double left = 219.43; double width = 75; double height = 75; foreach (Stream pictureStream in pictureStreams) { //Adds the picture to a slide by specifying its size and position. slide.Shapes.AddPicture(pictureStream, top, left, width, height); top += width; } //Save the PowerPoint presentation powerpointDoc.Save("Sample.pptx"); //Close the PowerPoint presentation powerpointDoc.Close(); MessageBox.Show("PPT is generated at the repo's bin file!"); }
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(); }
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(); }