本文将详细介绍如何在java应用程序中给powerpoint文档添加多行多列文本水印。
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;
import java.awt.*;
import java.awt.geom.rectangle2d;
public class watermarkdemo {
public static void main(string[] args) throws exception {
presentation presentation = new presentation();
presentation.loadfromfile("sample.pptx");
//设置文本水印的宽和高
int width= 300;
int height= 200;
//绘制文本,设置文本格式并将其添加到第一张幻灯片
float x = 30;
float y = 80;
for (int i = 0; i < 3; i )
{
for (int j = 0; j < 3; j )
{
rectangle2d.double rect = new rectangle2d.double(x,y,width, height);
//添加一个shape到定义区域
iautoshape shape = presentation.getslides().get(0).getshapes().appendshape(shapetype.rectangle, rect);
//设置shape样式
shape.getfill().setfilltype(fillformattype.none);
shape.getshapestyle().getlinecolor().setcolor(color.white);
shape.setrotation(-45);
shape.getlocking().setselectionprotection(true);
shape.getline().setfilltype(fillformattype.none);
//添加文本到shape
shape.gettextframe().settext("内部使用");
portionex textrange = shape.gettextframe().gettextrange();
//设置文本水印样式
textrange.getfill().setfilltype(fillformattype.solid);
textrange.getfill().getsolidcolor().setcolor(color.pink);
textrange.setfontheight(20);
x = (100 presentation.getslidesize().getsize().getwidth()/5);
}
x = 30;
y = (100 presentation.getslidesize().getsize().getheight()/6);
}
//保存文档
presentation.savetofile("output/result.pptx", fileformat.pptx_2010);
}
}
效果图: