We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Set "move object with text" property

Thread ID:





141335 Dec 6,2018 11:16 AM UTC Dec 12,2018 05:16 PM UTC ASP.NET Web Forms 3
Tags: DocIO
Pio Luca Valvona
Asked On December 6, 2018 11:16 AM UTC

How can I set this property, as in the attached image?


Attachment: image_2a313e43.zip

Dilli Babu Nandha Gopal [Syncfusion]
Replied On December 11, 2018 10:29 AM UTC

Hi Pio, 
Greetings from Syncfusion. 
Yes, you can set move object with text for picture, textbox and shapes in the Word document using VerticalOrigin API of DocIO. To enable the move object with text option in the Word document, we suggest you to set VerticalOrigin as paragraph and also set wrapping style (other than inline wrapping style) for the element.

Please refer the below example code snippet and let us know if it helps.:  
//Creates a Word document.  
WordDocument document = new WordDocument();  
//Adds a section and paragraph in the document.  
//Appends picture in the paragraph.  
IWPicture picture = document.LastParagraph.AppendPicture(Image.FromFile("image.jpg"));  
//Sets vertical origin as paragraph to enable move with text property.  
picture.VerticalOrigin = VerticalOrigin.Paragraph;  
//Sets wrapping style for picture.  
picture.TextWrappingStyle = TextWrappingStyle.Square;  
//Appends shape in the paragraph.  
Shape shape = document.LastParagraph.AppendShape(AutoShapeType.Rectangle, 70, 50);  
//Sets vertical origin as paragraph to enable move with text property.  
shape.VerticalOrigin = VerticalOrigin.Paragraph;  
//Sets wrapping style for shape.  
shape.WrapFormat.TextWrappingStyle = TextWrappingStyle.Square;  
//Appends textbox in the paragraph.  
IWTextBox textBox = document.LastParagraph.AppendTextBox(70, 50);  
//Sets vertical origin as paragraph to enable move with text property.  
textBox.TextBoxFormat.VerticalOrigin = VerticalOrigin.Paragraph;  
//Sets wrapping style for textbox.  
textBox.TextBoxFormat.TextWrappingStyle = TextWrappingStyle.Square;  
//Saves the Word document.  
//Closes the Word document.  

Please let us know if you have any questions. 
Dilli babu. 

Pio Luca Valvona
Replied On December 11, 2018 02:24 PM UTC

Fine, but in the case of replace of a placeholder with an image using the following text?

 WordDocument document = new WordDocument("../../Data/Input.docx");
            WParagraph paragraph = new WParagraph(document);
            TextBodyPart bodyPart = new TextBodyPart(document);
            //Replaces a particular text with the text body part
            document.Replace("Replace", bodyPart, false, true, true);
            document.Save("Output.docx", FormatType.Docx);

Dilli Babu Nandha Gopal [Syncfusion]
Replied On December 12, 2018 05:16 PM UTC

Hi Pio, 

Thank you for your update. 

Yes, VerticalOrigin property of Picture will be considered in Replace functionality which is illustrated in the following code example. 
 WordDocument document = new WordDocument(@"../../Data/Input.docx"); 
 WParagraph paragraph = new WParagraph(document); 
 IWPicture pic = paragraph.AppendPicture(Image.FromFile(@"../../Data/input.jpg")); 
 pic.VerticalOrigin = VerticalOrigin.Paragraph; 
 pic.TextWrappingStyle = TextWrappingStyle.Square;   
 TextBodyPart bodyPart = new TextBodyPart(document); 
 //Replaces a particular text with the text body part 
 document.Replace("Replace", bodyPart, false, true, true); 
 document.Save(@"Output.docx", FormatType.Docx); 

Please let us know if your requirement is fulfilled else kindly share us the complete scenario so that we can provide a solution in-line with your requirement. 

Dilli babu. 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon