Tue Jul 26, 2022 3:37 pm
Thank you for your response .
Please check the code I used to extract image
int index = 0;
Document document1 = new Document();
for (int i = 0; i < document.getSections().getCount();i++) {
Section section = document.getSections().get(i);
for (int p = 0; p < section.getParagraphs().getCount(); p++) {
Paragraph paragraph = section.getParagraphs().get(p);
for (int c = 0; c < paragraph.getChildObjects().getCount(); c++) {
IDocumentObject dob = paragraph.getChildObjects().get(c);
if( dob.getDocumentObjectType() == DocumentObjectType.Picture) {
System.out.println("picture");
Section tempSection = document1.addSection();
Paragraph paragraph1 = tempSection.addParagraph();
DocPicture picture = (DocPicture) dob;
paragraph1.getChildObjects().add(picture.deepClone());
Image image = document1.saveToImages(0, ImageType.Bitmap);
File file = new File(String.format("extractImageAndShape-%d.png", index));
System.out.println("file "+file);
document1.saveToFile("C:\\Users\\RA\\Desktop\\smartArt\\image.docx", FileFormat.Docx);
// ImageIO.write((RenderedImage) image, "PNG", file);
index++;
}
if ( dob instanceof ShapeObject
|| dob.getDocumentObjectType().equals(DocumentObjectType.Shape)
|| (dob.getDocumentObjectType().equals(DocumentObjectType.Text_Box))
|| (dob.getDocumentObjectType().equals(DocumentObjectType.Shape_Group))){
System.out.println("shape");
Section tempSection = document1.addSection();
Paragraph paragraph1 = tempSection.addParagraph();
ShapeObject shapeObject = (ShapeObject) dob;
paragraph1.getChildObjects().add(shapeObject.deepClone());
Image image = document1.saveToImages(0, ImageType.Bitmap);
File file = new File(String.format("extractImageAndShape-%d.png", index));
// ImageIO.write((RenderedImage) image, "PNG", file);
document1.saveToFile("C:\\Users\\RA\\Desktop\\smartArt\\image.docx", FileFormat.Docx);
index++;
}
It is considering image and shape individually but i added shape over image