zoukankan      html  css  js  c++  java
  • Java 添加文本框到 PPT 幻灯片

    文本框是指一种可移动、可调大小的文字或图形容器。在PowerPoint中,当我们需要新添加内容时,常常需要插入新的文本框。本文就将介绍如何使用Free Spire.Presentation for Java 添加文本框到PPT幻灯片,以及如何设置文本框边框样式、填充效果、阴影效果、文本框旋转、文字样式等。

    JAR包导入

    方法一:下载Free Spire.Presentation for Java包并解压缩,然后将lib文件夹下的jar包作为依赖项直接导入到Java应用程序中。

    方法二:通过Maven仓库安装jar包,配置pom.xml文件的代码如下:

    <repositories>
        <repository>
            <id>com.e-iceblue</id>
            <url>http://repo.e-iceblue.cn/repository/maven-public/</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>e-iceblue</groupId>
            <artifactId>spire.presentation.free</artifactId>
            <version>2.6.1</version></dependency>
    </dependencies>

    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("感谢观看!
     Thanks for Watching");
            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.LIGHT_SEA_GREEN);
            tb.getFill().getGradient().getGradientStops().append(0f,KnownColors.LIGHT_PINK);
    
            //设置文本框阴影效果
            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();
        }
    }

  • 相关阅读:
    SMI/慧荣/SM32**主控量产通用教程,PNY U盘量产!
    显示隐藏文件的批处理!
    office2003与office2007/2010文件关联问题!
    WDS功能及中继与桥接模式的区别.
    利用WinRar命令行定时备份Sql2005数据库!
    windows 7 关机的误区及睡眠和休眠的作用。
    ajax helloworld jsp ajax入门,后台使用jsp
    jquery width height innerWidth innerHeight
    d3.js GeoJSON 显示陕西省地图 projection
    jquery 向html添加元素append prepend before after
  • 原文地址:https://www.cnblogs.com/jazz-z/p/13490371.html
Copyright © 2011-2022 走看看