Horizontal and Vertical Alignment of WPicture.

I have a image on a Word Document. I want to adjust the Vertical Position /Alignment/ Vertical Origin of the picture so that it fits inside the gold borders. Please see sample attached. I am using the following code.

Best Regards.

WordDocument document = new WordDocument();
WPicture picture = new WPicture(document);

picture.Width = 1900f;
picture.Height = 365f;

 picture.HorizontalAlignment = ShapeHorizontalAlignment.Center;
 picture.VerticalAlignment = ShapeVerticalAlignment.Center;

picture.VerticalPosition = 200;
picture.HorizontalPosition = 150;

 // Sets horizontal and vertical origin
 picture.HorizontalOrigin = HorizontalOrigin.Page;
 picture.VerticalOrigin = VerticalOrigin.Margin;

Attachment: Sample_8d2a29ad.zip

2 Replies

DB Dilli Babu Nandha Gopal Syncfusion Team July 9, 2018 02:25 PM UTC

Hi Mangesh, 

Thank you for contacting Syncfusion support. 

To achieve your requirement, we have prepared a sample application to set image inside the gold borders. Please find the sample from the below link:
http://www.syncfusion.com/downloads/support/forum/138587/ze/SampleApplication2012571398.zip

To preserve the picture exactly inside the gold borders, it is need to set rotation for the picture in the Word document. Currently DocIO doesn’t provide API to set rotation for picture in the Word document. We have already logged this as a feature request in our database. We will include this feature in our 2018 Volume 2 SP1 release which is expected to be available at end of July, 2018. 

Regards, 
Dilli babu. 



DB Dilli Babu Nandha Gopal Syncfusion Team January 9, 2019 06:08 PM UTC

Hi Mangesh, 

We have provided an API to rotate picture in our 2018 Volume 2 release. We are glad to announce that our Essential Studio Volume 4, 2018 release (v16.4.0.42) is rolled out and is available for download under the following link. 

  
  
Please refer the below code snippet to achieve image rotation using DocIO: 
//Creates a new Word document  
WordDocument document = new WordDocument(); 
//Adds new section to the document 
IWSection section = document.AddSection(); 
//Adds new text to the paragraph  
IWParagraph paragraph = section.AddParagraph(); 
//Gets the image and convert to byte array   
Image image = Image.FromFile("Image.png"); 
MemoryStream imageStream = new MemoryStream(); 
image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png); 
byte[] imageBytes = imageStream.ToArray(); 
//Initializes new picture  
WPicture picture = new WPicture(document); 
//Loads an image from the byte array   
picture.LoadImage(imageBytes); 
//Sets height and width for the image  
picture.Height = 100; 
picture.Width = 150; 
//Sets picture rotation in degree   
picture.Rotation = 90; 
//Adds image to the paragraph  
paragraph.Items.Add(picture); 
//Saves the Word document   
document.Save("Sample.docx", FormatType.Docx); 
//Closes the document   
document.Close(); 
 

We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance. 

Regards, 
Dilli babu. 


Loader.
Up arrow icon