【发布时间】:2018-04-16 07:01:02
【问题描述】:
我想将图像替换为文本,但是当我删除形状节点时,结果有些图片没有被删除。 为什么?
public void replaceImageToMark() throws Exception {
Document doc = new Document("D:\\company\\demo.docx");
NodeCollection shapeCollection = doc.getChildNodes(NodeType.DRAWING_ML, true);
for (int i = 0; i < shapeCollection.getCount(); i++) {
DrawingML drawingML = (DrawingML) shapeCollection.get(i);
if (drawingML.hasImage()) {
String imageFileName = java.text.MessageFormat.format(
"Image.ExportImages.{0} Out{1}", i, FileFormatUtil.imageTypeToExtension(drawingML.getImageData().getImageType()));
DrawingMLImageData imageData = drawingML.getImageData();
imageData.save("D:\\company\\pic\\" + imageFileName);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveTo(drawingML);
builder.write("${image}");
drawingML.remove(); // There are some images that are not effective
}
}
doc.save("D:\\company\\newDemo.docx");
}
【问题讨论】:
标签: java aspose.words