Rotate ,Crop Image using WPicture class in DocIO

I have a image which I need to place it on a Word Document. After the image is inserted on Word Document , I need to rotate or Crop the image to fit it in Word Document as per shown in the zip file. Do WPicture class have properties/methods with which I can rotate & crop the image.
How can I set the image at a particular X & Y location? Can I rotate the image.?
I have attached the sample image to be changed and the sample word document with image position and size I want.
Best Regards.

Attachment: Sample_9a976b13.zip

2 Replies

MJ Mohanaselvam Jothi Syncfusion Team June 28, 2018 11:13 AM UTC

Hi Mangesh,

Thank you for contacting Syncfusion support.

Regarding to set the image at a particular X & Y location:
Please refer the below UG documentation link to set positions for image in the Word document using DocIO:
https://help.syncfusion.com/file-formats/docio/working-with-paragraph#working-with-images

Regarding to crop the image:
Currently DocIO does not have API to crop the image in the Word document. We will consider this as a feature request at our end. We will implement this feature in any of our upcoming releases. At present, we cannot provide any concrete timeline for this feature implementation. We will let you know once this feature is implemented.

Regarding to rotate the image:
We already logged this requirement (API to rotate image) as a feature request in our database. This feature will be included in our 2018 Volume 2 SP1 release which is expected to be available at the end of July, tentatively.

Please let us know if you have any other questions.

Regards,
Mohanaselvam J
 



DB Dilli Babu Nandha Gopal Syncfusion Team January 9, 2019 06:34 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