您的位置:首页 > 其它

poi获取图片位置

2015-03-31 00:07 211 查看
参考资料:http://stackoverflow.com/questions/28288104/how-to-know-the-image-or-picture-location-while-parsing-ms-word-doc-in-java-usin

内容:

You're getting at the pictures the wrong way, which is why you're not finding any positions!

What you need to do is process each
CharacterRun of the document in turn. Pass that to the
PicturesTable, and check if the character run has a picture in. If it does, fetch back the picture from the table, and you know where in the document it belongs as you have the run it comes from

At the simplest, it'd be something like:

PicturesTable pictureTable = document.getPicturesTable();
Range r = document.getRange();
for(int i=0; i<r.numParagraphs(); i++) {
Paragraph p = r.getParagraph(i);
for(int j=0; j<p.numCharacterRuns(); j++) {
CharacterRun cr = p.getCharacterRun(j);
if (pictureTable.hasPicture(cr)) {
Picture picture = pictures.getFor(cr);
// Do something useful with the picture
}
}
}

but,Picture picture = pictures.getFor(cr)有错误,不知道是不是因为版本问题,解决:

Picture picture = pictureTable.extractPicture(cr, true);

i第几行,(纵坐标)

j为第几个(横坐标)

j的单位是字符。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: