首页 > 编程 > Java > 正文

Java 添加文本框到PPT幻灯片过程解析

2019-11-26 08:37:57
字体:
来源:转载
供稿:网友

本文将介绍图和通过Java程序添加文本框到PPT幻灯片的方法。包括设置文本框边框样式、填充效果、阴影效果、文本框旋转、文字样式等。

使用工具:Free Spire.Presentation for Java (免费版)

Jar文件获取及导入:

方法1:通过E-iceblue官网下载jar文件包。下载后,解压文件,并将lib文件夹下的Spire.Presentation.jar文件导入到java程序。参考如下导入效果:

方法2:可通过maven仓库安装导入。可参考导入方法

Java代码示例(供参考)

import com.spire.presentation.*;import com.spire.presentation.drawing.FillFormatType;import com.spire.presentation.drawing.GradientShapeType;import com.spire.presentation.drawing.OuterShadowEffect;import java.awt.*;public class AddTextBox {  public static void main(String[]args)throws Exception {    //创建文档    Presentation ppt = new Presentation();    //获取第一张幻灯片,添加指定大小和位置的矩形文本框    IAutoShape tb = ppt.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE,new Rectangle(80, 120, 550, 200));    //设置文本框边框样式    tb.getLine().setFillType(FillFormatType.SOLID);    tb.getLine().setWidth(2.5);    tb.getLine().getSolidFillColor().setColor(Color.white);    //添加文本到文本框,并格式化文本    tb.appendTextFrame("添加文本框/n Append Textbox");    PortionEx textRange = tb.getTextFrame().getTextRange();    textRange.getFill().setFillType(FillFormatType.SOLID);    textRange.getFill().getSolidColor().setColor(Color.white);    textRange.setFontHeight(30);    textRange.setLatinFont(new TextFont("Arial Unicode MS"));    //填充文本框颜色为渐变色    tb.getFill().setFillType(FillFormatType.GRADIENT);    tb.getFill().getGradient().setGradientShape(GradientShapeType.LINEAR);    tb.getFill().getGradient().getGradientStops().append(1f,KnownColors.THISTLE);    tb.getFill().getGradient().getGradientStops().append(0f,KnownColors.ROYAL_BLUE);    //设置文本框阴影效果    OuterShadowEffect shadowEffect= new OuterShadowEffect();    shadowEffect.setBlurRadius(20);    shadowEffect.setDirection(30);    shadowEffect.setDistance(8);    shadowEffect.getColorFormat().setColor(Color.LIGHT_GRAY);    tb.getEffectDag().setOuterShadowEffect(shadowEffect);    //设置文本框向右旋转5度( 向左旋转设置数值为负数)    tb.setRotation(5);    //保存文档    ppt.saveToFile("AddTextBox.pptx",FileFormat.PPTX_2013);    ppt.dispose();  }}

文本框添加效果:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持武林网。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表