How to get Shape size inserted into the Word Document

Hi,
We use Java API, to process the word documents.
We are facing issue with word documents having an embedded object of large size which causing JVM to go out of memory.
I need to know what are the OLE object or any images present in the document, and need to check its size.

Any idea how to achieve that.
I would appreciate any help.

@Zycus123,

Have you tried latest version of Aspose.Words for Java i.e. 18.5? Are you getting out of memory exception during converting Word document to PDF? May be you should increase Java Heap Space size.

Please ZIP and upload your sample input Word document here for testing We will investigate the issue on our end and provide you more information.

We are converting Doc to HTML, that’s where it JVM goes out of memory. We can increase the JVM heap size.
I just need to know all the OLE objects or any images present in the document, and check its size.
Is there way to achieve that?
Below are the sample code with which I can get the OLE objects.

Document doc;
try
{
doc = new Document(“C:\Users\pancham.gupta\Desktop\ASPOSE_POC\TEST_EMBEDDED.docx”);
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
for (int i = 0; i < shapes.getCount(); i++)
{

  		try
  		{
  			Shape shape = (Shape) shapes.get(i);
  			// Check if the current shape has OLE object	
  			if (shape.getOleFormat() == null)
  				continue;
  			System.out.println(shape.getOleFormat());					
  		}
  		catch (Exception e)
  		{
  			continue;
  		}

  	}
  }
  catch (Exception e)
  {
  	e.printStackTrace();
  }

@iContract123,

I am afraid, it is difficult to say what is the cause of out of memory. Please ZIP and upload your sample input Word document (DOCX file) here for testing. We will investigate the issue on our end and provide you more information.

Hi,
I just need to know all the OLE objects or any images present in the document, and check its size.
Is there a way to achieve that?
I would appreciate any help.

@iContract123,

Please try using the following code:

Document doc = new Document("D:\\temp\\input.docx");
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);

for (com.aspose.words.Shape shape : (Iterable<com.aspose.words.Shape>) shapes) {
    if (shape.hasImage()) {
        double bytes = shape.getImageData().getImageBytes().length;
        System.out.println("File Size: " + String.format("%.2f", bytes / 1024) + "kb");
    }

    if (shape.getOleFormat() != null) {
        if (!shape.getOleFormat().isLink()) {
            // Optional
            if (shape.getOleFormat().getProgId().equals("Word.Document.12")) {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                shape.getOleFormat().save(baos);

                double bytes = baos.toByteArray().length;
                System.out.println("File Size: " + String.format("%.2f", bytes / 1024) + "kb");

                break;
            }
        }
    }
}