欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-05-04 19:16:49
本文将介绍图和通过java程序添加文本框到ppt幻灯片的方法。包括设置文本框边框样式、填充效果、阴影效果、文本框旋转、文字样式等。 使用工具:free spire.pre...

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

使用工具:free spire.presentation for java (免费版)

jar文件获取及导入:

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

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

方法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();
  }
}

文本框添加效果:

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

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