Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Mon Jul 25, 2022 10:19 am

Hi Team

I have added shape object in an Image ,while fetching image with shape object location of the shape object is misplaced .If we grouping the images ,in that scenario images will be placed in the proper place

Please let me know that how to resolve this issue .I have sent sample files for your reference through the mail.

Thanks in advance

pr20080798
 
Posts: 148
Joined: Wed Jan 20, 2021 1:15 pm

Tue Jul 26, 2022 7:06 am

Hello Wipro Harmony,

Thanks for your message.
To help us have an accurate investigation, could you please share your full testing code with us? Thanks in advance.

Sincerely
Simple
E-iceblue support team
User avatar

Simple.Li
 
Posts: 248
Joined: Fri Jul 01, 2022 2:33 am

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

pr20080798
 
Posts: 148
Joined: Wed Jan 20, 2021 1:15 pm

Wed Jul 27, 2022 9:35 am

Hello Wipro Harmony,

Thanks for your sharing.
After testing your code, I got the same result as yours. As you know that the shape and the first picture of your word file are not the group shapes, our Spire.Doc mimics the same behavior as MS Word does, it only can obtain the single shape or picture object. To get the first picture and shape with keeping them position, you need to use group shapes for your original document. Thanks for your understanding.

Sincerely
Simple
E-iceblue support team
User avatar

Simple.Li
 
Posts: 248
Joined: Fri Jul 01, 2022 2:33 am

Wed Jul 27, 2022 10:28 am

Thank you for your response.

I have few points to ask :

1. can we check image overlapped with any shapes or not .
2. If image is overlapped with any shape ,can we group image and shapes by using ShapeGroup class

Thanks in advance

pr20080798
 
Posts: 148
Joined: Wed Jan 20, 2021 1:15 pm

Thu Jul 28, 2022 9:55 am

Hello Wipro Harmony,

Thanks for your reply.
Since the word document xml data doesn't have the image overlapped property, sorry our product also was unable to get and detect it. And I encountered some problems when grouping image and shapes by using ShapeGroup class. I have logged these issues into our tracking system with the ticket SPIREDOC-8253. Our Dev team will do more investigations to check if there is any approach to achieve it. Once there is any update, I will inform you asap. Sorry for the inconvenience caused.

Sincerely
Simple
E-iceblue support team
User avatar

Simple.Li
 
Posts: 248
Joined: Fri Jul 01, 2022 2:33 am

Mon Aug 01, 2022 4:46 am

Thank you for your response

pr20080798
 
Posts: 148
Joined: Wed Jan 20, 2021 1:15 pm

Tue Aug 02, 2022 7:44 am

Hello Wipro Harmony,

Thanks for your reply.
If there is any other issues, just feel free to write back. Wish you a happy life.

Sincerely
Simple
E-iceblue support team
User avatar

Simple.Li
 
Posts: 248
Joined: Fri Jul 01, 2022 2:33 am

Mon Aug 22, 2022 6:13 am

Hi Team ,

Any updates on this issue ?

pr20080798
 
Posts: 148
Joined: Wed Jan 20, 2021 1:15 pm

Mon Aug 22, 2022 7:47 am

Hello Wipro Harmony,

I am sorry to tell that there is no significant progress so far due to the complexity of the case. Our dev team would keep looking into it. Once there’s any update, I will inform you asap. We apologize for the inconvenience. Thanks for your patience.

Sincerely
Simple
E-iceblue support team
User avatar

Simple.Li
 
Posts: 248
Joined: Fri Jul 01, 2022 2:33 am

Wed Aug 24, 2022 7:30 am

Hello Wipro Harmony,

Thanks for your patience.
After more investigations, we found that the following code could group image and shapes by using ShapeGroup class.
Code: Select all
        Document doc = new Document();
        Section sec = doc.addSection();
        //add a new paragraph
        Paragraph para = sec.addParagraph();
        //add a shape group with the height and width
        ShapeGroup shapegroup = para.appendShapeGroup(250, 140);
        DocPicture picture = new DocPicture(doc);
        picture.loadImage("test.png");
        picture.setWidth(1250);
        picture.setHeight(1400);
        picture.setHorizontalPosition(19);
        picture.setVerticalPosition(27);
        picture.setTextWrappingStyle(TextWrappingStyle.Behind);
        shapegroup.getChildObjects().add(picture);
        ShapeObject shapeObject = new ShapeObject(doc, ShapeType.Rectangle);
        shapeObject.setWidth(300);
        shapeObject.setHeight(300);
        shapeObject.setHorizontalPosition(659);
        shapeObject.setVerticalPosition(520);
        shapeObject.setStrokeColor(Color.GREEN);
        shapeObject.setFillColor(null);
        shapegroup.getChildObjects().add(shapeObject);
        doc.saveToFile("output.docx", FileFormat.Docx);

If you have any further questions, please feel free to contact us.

Sincerely,
Simple
E-iceblue support team
User avatar

Simple.Li
 
Posts: 248
Joined: Fri Jul 01, 2022 2:33 am

Fri Dec 09, 2022 6:41 am

Hi Team ,

Any updates on SPIREDOC-8253 ticket?

pr20080798
 
Posts: 148
Joined: Wed Jan 20, 2021 1:15 pm

Fri Dec 09, 2022 8:37 am

Hello,

Thank you for following up.
As for the issue SPIREDOC-8253, please use the sample code that my colleague Simple provided on 8/24 to group image and shapes. If there is any other issues, just feel free to write back.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.Doc