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

Put picture in cell & resize it

Hi
I have a table of rows and i want to put picture in one cell,
i want to change the width of picture    taking account the width of the current cell and the height change automatically.
I want the image to be position well in a cell without overflowing.


Thanks.

4 Replies

DB Dilli Babu Nandha Gopal Syncfusion Team March 4, 2019 01:27 PM UTC

Hi AtliDev, 

Greetings from Syncfusion. 

We have prepared a sample application to resize the image inside the table cell. Please find the sample from the below link and let us know if it helps: 

In this sample, we have done the following things: 

1. Loads an existing Word document. 
2. Gets the table in the document. 
3. Get the width of cell excluding the spacings and margins. 
4. Resize the picture width as per width of cell. 
5. Get the height of cell excluding spacings and margins. 
6. Resize the picture height as per height of cell. 
7. Add picture in the table cell and saves the Word document. 

Please let us know if you have any questions. 

Regards, 
Dilli babu. 



AT AtliDev March 7, 2019 01:33 PM UTC

hi,
thanks for answer, your sample work great, but what i need ,
i want just to change the width and the height change automaticly ( and the picture keep the same definition )
the same when  i change the height.
thanks


AT AtliDev March 8, 2019 08:39 AM UTC

 HI,
I found a some thing,if i change the height of my row (height=10) i have a little picture
and it's not good for client
thanks


DB Dilli Babu Nandha Gopal Syncfusion Team March 8, 2019 10:23 AM UTC

Hi AtliDev, 

To achieve your requirement, we suggest you to set values in WidthScale and HeightScale values of WPicture based on the width and height value of picture. When changing Width of the WPicture, DocIO changes the scaling factor WidthScale of the WPicture  as per new values.

So, if you need to change the height based on the given width, we suggest you to set width (custom width) for the picture and then set the modified WidthScale value to HeightScale. Thus, picture height will be changed as per the scaling factor of height.

Please refer the below code example to meet your requirements:
1. To change height automatically, based on width value of picture: 
 
//Loads existing Word document.  
WordDocument document = new WordDocument("Template.docx");  
WParagraph paragraph = document.LastParagraph;  
//Get the picture in the Word document.  
WPicture picture = paragraph.ChildEntities[1] as WPicture;  
//Set width for picture.  
picture.Width = 200;  
//Set height scale based on the width scale factor.  
picture.HeightScale = picture.WidthScale;  
//Saves and closes the document instance  
document.Save("Result.docx");  
document.Close();  
  

2. To change width automatically, based on height value of picture:  
//Loads existing Word document.  
WordDocument document = new WordDocument("Template.docx");  
WParagraph paragraph = document.LastParagraph;  
//Get the picture in the Word document.  
WPicture picture = paragraph.ChildEntities[1] as WPicture;  
//Set height for picture.  
picture.Height = 300;  
//Set width scale based on the height scale factor.  
picture.WidthScale = picture.HeightScale;  
//Saves and closes the document instance  
document.Save("Result.docx");  
document.Close();  

Regards, 
Dilli babu. 


Loader.
Live Chat Icon For mobile
Up arrow icon