Preserve Image Dimensions when Inserted inside GroupShape in DOCX Document using C# .NET API

Currently we’re evaluating to upgrade to the latest version of Aspose.Words 17.11. With this process we’ve found some strange behavior when it comes to Shapes within GroupShapes:

1. In our template document we have a GroupShape that contains a few rectangle childShapes. We try to insert an image into a childShape. When we try to manipulate the childShape’s Height to get the same aspect ratio as our image, the Height is calculated correctly, but the rendered image Height is blown up.

We use this calculation: childShape.Height = childShape.Width / imageRatio

Looking at the document (DOCX format) which contains the error, These are some of the properties of the (group)Shapes. Notice that all the (group)shapes are Dml’s:

GroupShape.CoordOrigin = {X = 0 Y = 0}
GroupShape.CoordSize = {Width = 31946 Height = 20167}
GroupShape.Height = 159
GroupShape.Width = 252.55
GroupShape.MarkupLanguage = Dml

childShape.CoordOrigin = {X = 1099 Y = 1215}
childShape.CoordSize = {Width = 30847 Height = 12732}
childShape.Height = 12732
childShape.Width = 30847
childShape.MarkupLanguage = Dml

After changing the Height it gets:

childShape.CoordOrigin = {X = 1099 Y = 1215}
childShape.CoordSize = {Width = 30847 Height = 117527070}
childShape.Height = 9254.1
childShape.Width = 30847
childShape.MarkupLanguage = Dml

So it looks like the Height gets the correct value, but the CoordSize.Height is blown up. Looking at a similar document (DOC format), where the (group)shapes are Vml’s it seems to work correctly:

GroupShape.CoordOrigin = {X = 0 Y = 0}
GroupShape.CoordSize = {Width = 31946 Height = 20167}
GroupShape.Height = 159
GroupShape.Width = 252.55
GroupShape.MarkupLanguage = Vml

childShape.CoordOrigin = {X = 0 Y = 0}
childShape.CoordSize = {Width = 21600 Height = 21600}
childShape.Height = 12732
childShape.Width = 30847
childShape.MarkupLanguage = Vml

After changing the Height it gets:

childShape.CoordOrigin = {X = 0 Y = 0}
childShape.CoordSize = {Width = 21600 Height = 21600}
childShape.Height = 9254.1
childShape.Width = 30847
childShape.MarkupLanguage = Vml

In this case the CoordSize isn’t even changed.

2. The second issue is that we’ve noticed a NullReference when trying to use an InsertBefore on a GroupShape:

childShape.ParentNode.InsertBefore(newShape, childShape);

where ParentNode is a GroupShape (and ofcourse childShape and newShape both are not NULL). Again if the GroupShape is a Vml (in a DOC template) it works just fine., But when it is a Dml (in a DOCX template) we get the following StackTrace:

Object not set to an instance of an object
   at Aspose.Words.Drawing.GroupShape.r3ka8zscesabkstb24kjjv9sml9wq7pw  (Node )
   at Aspose.Words.CompositeNode.(Node , Node , Boolean )

Can you confirm these bugs?

@hro_jordy1,

To ensure a timely and accurate response, please ZIP and upload the following resources for your two different scenarios here for testing:

  • Your input Word documents.
  • Aspose.Words for .NET 17.11 generated output documents (if any) which show the undesired behaviors.
  • Please attach your expected document(s) here for our reference. We will investigate the structure of your expected document(s) as to how you want your final outputs be generated like. You can create expected document(s) by using Microsoft Word.
  • Please create standalone Console Applications (source code without compilation errors) that helps us to reproduce your problems on our end and attach them here for testing.
  • Please provide information about the Aspose.Words’ version number for which there were no problems on your side previously.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

@awais.hafeez I was hoping to skip the creation of sample projects by providing enough information :wink: But I’ve created a zip-file with the requested information.

For each scenario I’ve created duplicate code and documents (DOCX and DOC format) to see the change in output.

Scenario 01: As you can see in the output DOCX the shape is vertically way to large. In the output DOC the shape is how it should be, but we want the same result also in the DOCX file.

Scenario 02: There is no DOCX output as the InsertBefore generates an error (see the catch message). The DOC file is generated as the code does not throw an error.

Aspose bug(s).zip (206.1 KB)

@hro_jordy1,

We are checking these scenarios and will get back to you soon.

Hi @awais.hafeez,

It’s been a few days now, can you confirm the bugs at your end?

@hro_jordy1,

We tested the Scenario 01 and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-16239.Our product team will further look into the details of this problem and we will keep you updated on the status of correction. We apologize for your inconvenience.

@hro_jordy1,

We tested the Scenario 02 and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-16240.Our product team will further look into the details of this problem and we will keep you updated on the status of correction. We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-16239) have been fixed in this Aspose.Words for .NET 18.3 update and this Aspose.Words for Java 18.3 update.

Hi @awais.hafeez,

Thanks for fixing the first issue (we still need to confirm that it fixes our issue, but I’m confident that it does). I’m also tracking the second issue, which went from ‘In Review’ to ‘Postponed’. Because we want to upgrade to the new Aspose version, and these issues needs to be resolved, I would like to know if the second issue will be fixed. Could you elaborate why the issue is postponed?

@hro_jordy,

Regarding WORDSNET-16240, the implementation of the fix of this issue has been postponed till a later date (currently no estimates are available). We will inform you via this thread as soon as this issue is resolved or any estimates are available. We apologize for any inconvenience.

Hi @awais.hafeez,

After 6 months is the fix for the second bug still on your roadmap?

@hro_jordy,

Unfortunately, your issue (WORDSNET-16240) is not resolved yet and there is no further news about it i.e. the implementation of the fix of this issue has still been postponed. We can currently not share any estimates with you either. We will inform you via this thread as soon as this issue is resolved or any estimates are available. We apologize for your inconvenience.

Hi @awais.hafeez,

Thank you for you ‘generic’ reply. Because this bug forces us not to update to the latest version and still use old formats (DOC files, DOCX with compatibility mode) we would like to know if there’s a workaround for this bug so we can use the normal DOCX format?

@hro_jordy,

We have logged your concern in our issue tracking system and will let you know via this thread as soon as any further update or workaround is available. We apologize for your inconvenience.

@hro_jordy,

Regarding WORDSNET-16240, it is to update you that the solution for this problem is being developed. Rough estimate is Aspose.Words’ 19.3 March release. Please note that this estimate is not final at the moment. If everything goes by plan, then we will include this fix in 19.3 version. We will inform you via this thread as soon as this issue is resolved. Thanks for being patient.

Hi Awais,

It has been almost a year since your last update on this issue. Is this issue still under development?

@hro_jordy,

Unfortunately, WORDSNET-16240 is not resolved yet. We have noted your concern and will update you via this thread as soon as any estimates (ETA) or any more updates will be available. We apologize for your inconvenience.

@hro_jordy,

Regarding WORDSNET-16240, it is to update you that we are currently working on this issue but cannot promise an ETA at the moment. However, if everything goes by plan, we are hopeful to include the fix to your issue in Aspose.Words’ 20.3 release. We will keep you posted on any further updates.

Hi Awais,

The current version of Aspose.Words is 20.6, yet still no fix for this issue, which is reported 2,5 years ago. Will this ever be fixed? We cannot upgrade to a newer version, which we definitely want to do, if this isn’t fixed. Does this issue still exist in 20.6?

@hro_jordy,

I am afraid, WORDSNET-16240 is still not resolved. We have logged your concerns in our issue tracking system and will update you via this thread as soon as any reliable estimates (time frame) or any more updates may be available. We apologize for your inconvenience.