Add text
Text: | |
Font: | |
Font Size: | The font size must be a valid number. The font size must be a valid number. |
Color: | The format of color value must be rrggbb. |
downloads
|
Add image
Image: |
Click here to browse files
CustomValidator |
downloads
|
- Demo
- Java
- C# source
This demo shows you how to add text and image to a PowerPoint document.
package ppt; import com.spire.presentation.*; import com.spire.presentation.drawing.FillFormatType; import java.awt.*; import java.awt.geom.Rectangle2D; public class AddTextOrImageDemo { public void addTextOrImage(String filePath, String addType, String text, String imageFile, String resultFilePath) throws Exception { Presentation presentation = new Presentation(); presentation.loadFromFile(filePath); switch (addType){ case "TEXT": addText(presentation,text); break; case "IMAGE": addImage(presentation,imageFile); break; } presentation.saveToFile(resultFilePath,FileFormat.PPTX_2013); } private void addText(Presentation presentation, String text) throws Exception { IAutoShape shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle(50, 70, 620, 150)); shape.getFill().setFillType(FillFormatType.NONE); shape.getShapeStyle().getLineColor().setColor(Color.white); shape.getTextFrame().getParagraphs().get(0).setAlignment(TextAlignmentType.LEFT); shape.getTextFrame().getParagraphs().get(0).setIndent(50); shape.getTextFrame().getParagraphs().get(0).setLineSpacing(150); shape.getTextFrame().setText(text); shape.getTextFrame().getParagraphs().get(0).getTextRanges().get(0).setLatinFont(new TextFont("Arial Rounded MT Bold")); shape.getTextFrame().getParagraphs().get(0).getTextRanges().get(0).setFontHeight(16); shape.getTextFrame().getParagraphs().get(0).getTextRanges().get(0).getFill().setFillType(FillFormatType.SOLID); shape.getTextFrame().getParagraphs().get(0).getTextRanges().get(0).getFill().getSolidColor().setColor(Color.RED); } private void addImage(Presentation presentation, String imageFile) throws Exception { Rectangle2D.Double rect1 = new Rectangle2D.Double(presentation.getSlideSize().getSize().getWidth() / 2 - 280, 140, 120, 120); IEmbedImage image = presentation.getSlides().get(0).getShapes().appendEmbedImage(ShapeType.RECTANGLE, imageFile, rect1); image.getLine().setFillType(FillFormatType.NONE); } }
using Spire.Presentation; using Spire.Presentation.Drawing; using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DemoOnlineCode { class AddTextOrImage { public void AddTextOrImageDemo(string format, string text, string imageFilePath, string resultFileName) { Presentation presentation = new Presentation(); switch (format) { case "TEXT": AddText(presentation,text,resultFileName); break; case "IMAGE": AddImage(presentation, imageFilePath, resultFileName); break; } } private static void AddText(Presentation presentation, string text, string resultFileName) { IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 620, 150)); shape.Fill.FillType = FillFormatType.None; shape.ShapeStyle.LineColor.Color = Color.White; //Set the alignment of paragraph shape.TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left; //Set the indent of paragraph shape.TextFrame.Paragraphs[0].Indent = 50; //Set the linespacing of paragraph shape.TextFrame.Paragraphs[0].LineSpacing = 150; //Set the text of paragraph shape.TextFrame.Text = text; //Set the Font shape.TextFrame.Paragraphs[0].TextRanges[0].LatinFont = new TextFont("Arial Rounded MT Bold"); shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.FillType = FillFormatType.Solid; shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.SolidColor.Color = Color.Black; presentation.SaveToFile(resultFileName + ".pptx", FileFormat.Pptx2013); } private static void AddImage(Presentation presentation, string imageFilePath, string resultFileName) { RectangleF rect1 = new RectangleF(presentation.SlideSize.Size.Width / 2 - 280, 140, 120, 120); IEmbedImage image = presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, imageFilePath, rect1); image.Line.FillType = FillFormatType.None; presentation.SaveToFile(resultFileName + ".pptx", FileFormat.Pptx2013); } } }
No Matter How Big or Small Your Project is,
Any technical question related to our product, contact us at support@e-iceblue.com.
Any question related to the purchase of product, contact us at sales@e-iceblue.com.
If you don't find the function you want, please request a free demo from us.