java矩形派生正方形,阅读形状(矩形,正方形,圆形,箭头等),使用java从MS Word文件剪贴画...

我能够从ms word table获取图像,但无法获得形状和剪贴画.

public static void main(String[] args) throws Exception {

// The path to the documents directory.

try {

String dataDir = "E://test//demo.docx";

generatePicturesAsImages(dataDir);

} catch (Exception e) {

e.printStackTrace();

}

}

public static void generatePicturesAsImages(String sourcePath) {

try {

Document doc = new Document(sourcePath);

ImageSaveOptions options = new ImageSaveOptions(SaveFormat.JPEG);

options.setJpegQuality(100);

options.setResolution(100);

// options.setUseHighQualityRendering(true);

List pictures = getAllPictures(doc);

if (pictures != null) {

for (int i = 0; i < pictures.size(); i++) {

ShapeRenderer picture = pictures.get(i);

String imageFilePath = sourcePath + "_output_" + i + ".jpeg";

picture.save(imageFilePath, options);

}

}

} catch (Exception e) {

e.printStackTrace();

}

}

private static List getAllPictures(final Document document) throws Exception {

List images = null;

@SuppressWarnings("unchecked")

NodeCollection nodeCollection = document.getChildNodes(NodeType.DRAWING_ML, Boolean.TRUE);

if (nodeCollection.getCount() > 0) {

images = new ArrayList();

for (DrawingML drawingML : nodeCollection) {

images.add(drawingML.getShapeRenderer());

}

}

return images;

}

上面的程序是从表中获取图像所以我应该添加更多来获取形状..请建议我任何帮助将不胜感激!

最佳答案 您使用的是较旧版本的Aspose.Words.如果要使用旧版本的Aspose.Words,请在getAllPictures方法中使用Document.getChildNodes获取Shape和DrawingML节点的集合.

NodeCollection drwingmlnodes = document.getChildNodes(NodeType.DRAWING_ML, Boolean.TRUE);

NodeCollection shapenodes = document.getChildNodes(NodeType.SHAPE, Boolean.TRUE);

我和Aspose一起担任开发人员传道人.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值