本文将介绍如何使用spire.presentation for java获取powerpoint文档中文本的位置。
import com.spire.presentation.iautoshape;
import com.spire.presentation.islide;
import com.spire.presentation.presentation;
import java.awt.geom.point2d;
public class getpositionoftext {
public static void main(string []args) throws exception {
//创建presentation实例
presentation ppt = new presentation();
//加载powerpoint文档
ppt.loadfromfile("sample.pptx");
//获取第一张幻灯片
islide slide = ppt.getslides().get(0);
//获取第一个形状
iautoshape shape = (iautoshape)slide.getshapes().get(0);
//获取形状中文本的位置
point2d location =shape.gettextframe().gettextlocation();
//打印文本位置(相对于幻灯片)的x和y坐标
string point1="文本位置(相对于幻灯片): x= " location.getx() " y = " location.gety();
system.out.println(point1);
//打印文本位置(相对于形状)的x和y坐标
string point2 = "文本位置(相对于形状): x= " (location.getx() - shape.getleft()) " y = " (location.gety() - shape.gettop());
system.out.println(point2);
}
}
输出结果: