[英]Docx4j - Images in the document
我们如何从docx4j中删除图像。
假设我有10个图像,我想用我自己的字节数组/二进制数据替换8个图像,我想删除剩余的2个。
我在查找图像方面也遇到了麻烦。
是否有可能用图像替换文档中的文本占位符?
请参阅这篇文章: http : //vixmemon.blogspot.com/2013/04/docx4j-replace-text-placeholders-with.html
for(Object obj : elemetns){
if(obj instanceof Tbl){
Tbl table = (Tbl) obj;
List rows = getAllElementFromObject(table, Tr.class);
for(Object trObj : rows){
Tr tr = (Tr) trObj;
List cols = getAllElementFromObject(tr, Tc.class);
for(Object tcObj : cols){
Tc tc = (Tc) tcObj;
List texts = getAllElementFromObject(tc, Text.class);
for(Object textObj : texts){
Text text = (Text) textObj;
if(text.getValue().equalsIgnoreCase("${MY_PLACE_HOLDER}")){
File file = new File("C:\\image.jpeg");
P paragraphWithImage = addInlineImageToParagraph(createInlineImage(file));
tc.getContent().remove(0);
tc.getContent().add(paragraphWithImage);
}
}
System.out.println("here");
}
}
System.out.println("here");
}
}
wordMLPackage.save(new java.io.File("C:\\result.docx"));
有关查找内容的两种方法(XPath或非XPath遍历),请参阅docx4j检查复选框 。
VariableReplace允许您替换文本占位符,但不能替换图像。 我认为可能有代码浮动(在docx4j论坛?),它扩展它来做到这一点。
但我建议您使用内容控制数据绑定。 了解如何使用docx4j从模板创建新单词
您可以在XML数据中使用base64编码图像,docx4j和/或Word将完成剩下的工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.