gpt4 book ai didi

java - Docx4j - 文档中的图像

转载 作者:行者123 更新时间:2023-11-29 05:46:02 30 4
gpt4 key购买 nike

我们如何从 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"));

关于java - Docx4j - 文档中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15827498/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com