Remove images in .docx file

喜你入骨 提交于 2019-12-04 14:15:17

If you get an IndexOutOfBoundsException on a call where you try to remove item #0, then your list is obviously empty. So either do an emptiness check on all the drawings in your Run object, or use a for loop - which won't execute if your List<CTDrawing> is empty.

for (XWPFRun run : runs) {
    CTR ctr = run.getCTR();
    List<CTDrawing> lst = ctr.getDrawingList();
    for (int i = 0; i < lst.size(); i++) {
        ctr.removeDrawing(i);
    }
}

Try this :

        for (XWPFRun run : paragraph.getRuns())
                {
                     CTDrawing []  arr = run.getCTR().getDrawingArray();

                     for(int k=0; k<arr.length; k++)
                     {
                         run.getCTR().removeDrawing(k);
                     }

                }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!