-
Notifications
You must be signed in to change notification settings - Fork 5
Extract Images from Word Document
shoaibkhan-aspose edited this page Apr 16, 2014
·
1 revision
HWPFDocument doc = new HWPFDocument(new FileInputStream(
"data/document.doc"));
List<Picture> pics = doc.getPicturesTable().getAllPictures();
for (int i = 0; i < pics.size(); i++)
{
Picture pic = (Picture) pics.get(i);
FileOutputStream outputStream = new FileOutputStream(
"data/apacheImages/" + "Apache_"
+ pic.suggestFullFileName());
outputStream.write(pic.getContent());
outputStream.close();
}
Document doc = new Document("data/document.doc");
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
int imageIndex = 0;
for (Shape shape : (Iterable<Shape>) shapes)
{
if (shape.hasImage())
{
String imageFileName = java.text.MessageFormat.format(
"Aspose.Images.{0}{1}", imageIndex, FileFormatUtil
.imageTypeToExtension(shape.getImageData()
.getImageType()));
shape.getImageData().save("data/asposeImages/" + imageFileName);
imageIndex++;
}
}
Download Source Code
For further releases and updates, please follow these new repositories:
- Aspose.Words Java for Apache POI
- Aspose.Cells Java for Apache POI
- Aspose.Slides Java for Apache POI
- Aspose.Email Java for Apache POI
- For documentation, please visit Aspose Docs.
- Raise your queries and suggest more examples via Aspose Forums or via new social coding sites.