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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Set "move object with text" property

Thread ID:

Created:

Updated:

Platform:

Replies:

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

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

Thanks.



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.  
document.EnsureMinimal();  
  
//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.  
document.Save("Sample.docx");  
//Closes the Word document.  
document.Close();  

Please let us know if you have any questions. 
 
Regards, 
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);
            paragraph.AppendPicture(Image.FromFile("../../Data/input.jpg"));
            TextBodyPart bodyPart = new TextBodyPart(document);
            bodyPart.BodyItems.Add(paragraph);
            //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); 
 bodyPart.BodyItems.Add(paragraph); 
 //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. 

Regards, 
Dilli babu. 


CONFIRMATION

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

;