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

Free Support Forum - aspose.com

Changing the anchor of a shape

is there a way to change the anchor position of a shape like a textbox (as in “anchor_textbox.png” and “anchor_textbox_2.png”). In Microsoft Word 2013 you can simply drag an drop the anchor to the paragraph you want it to be related to. This feature is important if you want to change the wrapping of the text (WrapType in Aspose.Words) in relation to the textbox (as in “anchor_textbox_3.png” and “anchor_textbox_4.png”). The only feature with anchors in Aspose.Words I have discovered so far is switching the locking of the anchor on/off in the shape object, but no clear way how I could possibly attach it to another paragraph inside the document. Thank you so much in advance.

Best regards.

Edit: I have attached the two Word Documents. If you select the textbox, you will see that its anchor is attached to a different paragraph in each document.

Hi Dolten,

Thanks for your inquiry. Could you please attach your input Word document and expected Word document here for testing? Please create your expected Word document using MS Word, we will then provide you code to achieve the same using Aspose.Words.

Best regards,

Thank you for your quick reply. I have updated my original post with the two Word Documents attached.
Best regards.

Hi Dolten,

Thanks for your inquiry.

Anchor points are used to tie a graphic object such as a Shape or DrawingML to specific paragraphs in a Word document. The anchors don't exist apart from these Shapes or DrawingML nodes, so the only way to insert them in a document is to create a Shape or DrawingML inside a Paragraph. In your case, the DrawingML is child of first Paragraph and you need to make it child of last Paragraph to be able to move anchor to the last para. Please see the following code:
Document doc = new Document(getMyDir() + "input_document.docx");

DrawingML dml = (DrawingML)doc.getFirstSection().getBody().getFirstParagraph().getFirstChild();

doc.save(getMyDir() + “out.docx”);

I hope, this helps.

Best regards,