Tab 1
此演示向您展示如何将文本和图像添加到 PowerPoint 文档。
Add text
Text: | |
Font: | |
Font Size: | |
Color: | |
downloads
|
Add image
Image: |
Click here to browse files
|
![]() |
|
downloads
|
如果这不是您想要的 Demo,您可以通过填写表格获取免费定制 Demo。
如您有与我们产品相关的其他技术问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。;销售相关的问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。。
Tab 2
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);}}
Tab 3
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);}}}