Free Support Forum - aspose.com

Inserting Image at Bookmark doesn't maintain horizontal position

I have some simple code attempting to insert an image at a certain bookmark, like this:
Stream stream = new MemoryStream(document);
Aspose.Words.Document doc = new Aspose.Words.Document(stream);
Aspose.Words.DocumentBuilder docbuild = new Aspose.Words.DocumentBuilder(doc);
docbuild.MoveToBookmark(bookmark, true, false);
Aspose.Words.Drawing.Shape shape = docbuild.InsertImage(signature);
shape.WrapType = Aspose.Words.Drawing.WrapType.None;
shape.Width = (shape.Width / shape.Height) * height;
shape.Height = height;

doc.Save(outStream, Aspose.Words.SaveFormat.Docx);

Instead of inserting it at the correct position in the document, it inserts the image at the left margin, ignoring the horizontal position. This is as though it inserts it at the beginning of the paragraph the bookmark is in, not at the actuall bookmark.

The place I am trying to insert it at is after a chunk of text that has several tabs before it on the line.

This seems like it may be a bug to me, or I do not exactly understand the system
Thank you for any help.

Brock

@blumbard,

Thanks for your inquiry. Please ZIP and attach the following resources here for testing:

  • Input Word document
  • Aspose.Words generated output DOCX file showing the undesired behavior.
  • Your expected 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 by using Microsoft Word.
  • Create a standalone console application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing.

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

Hi Awais, Thank you for your help. Attached is what you requested. Like I said, the problem is the image will not insert at the bookmark but instead floats all the way left of it. ApplyImageTesting.zip (24.5 KB)

@blumbard,

I am afraid, we do not see any Bookmarks in your “TestDocInput.docx” and “TestDocOutput.docx” documents. Please provide documents that have Bookmarks. Also, please create a standalone console application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing.

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