We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

InsertImage positioning ignores what I specify

I’m trying to insert an image at the bottom-right of the footer on first page, and if I use the exact same dimensions that I can see are OK in Word, they come out differently in the Aspose-generated document.


builder.MoveToHeaderFooter(HeaderFooterType.FooterFirst);
builder.InsertImage(myImagePath, RelativeHorizontalPosition.RightMargin, -4.31, RelativeVerticalPosition.BottomMargin, -4.97, 60, 29, WrapType.None);

The above code results in positioning of -0.15 (instead of -4.31) and -0.17 (instead of -4.97). Why are the numbers coming out differently?

Thanks.

I checked the docs and it says the measurements are in points, not centimetres. There’s a converter here which will help.


It would be great if you would consider adding a method which takes centimetres in a future release (since that is what we see in Word).

Hi Marc,


Thanks for your inquiry. Please note that 1 inch is equal to 72 points. There is a ConvertUtil class in Aspose.Words namespace that provides helper functions to convert between various measurement units. Hope, this helps.

In case the problem still remains, please attach your input Word document and expected Word document here for our reference. We will investigate the structure of your expected document as to how you want your final output be generated like. You can create expected document using Microsoft Word. We will then provide you code to achieve the same using Aspose.Words.

Best regards,

I’ve got it all sorted now, thanks. Once I realised I should use points, things started falling into place. I still get tripped up occasionally because when you tell Word to switch between showing an absolute position “to the right of” whatever, the figure it shows in the absolute position box does not (always?) update accordingly to reflect the position in the new format. I think that’s mostly why I end up generating documents where things don’t position correctly, it’s because Word is lying to me!


However, a method which takes centimetres and not points would be very convenient in future.

Thanks again.
Hi Marc,

Thanks for your inquiry. The DocumentBuilder.InsertImage method returns a Shape object and you can use various Shape properties to adjust its position/dimension. Also, you can use the following equation if you need to pass values in centimeters:

1cm = 72/2.54 or
x * (72 / 2.54) where x is value in centimeters.

Hope, this helps.

Best regards,