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

Put picture in cell & resize it

Thread ID:

Created:

Updated:

Platform:

Replies:

143044 Mar 1,2019 04:08 PM UTC Mar 8,2019 10:23 AM UTC WinForms 4
loading
Tags: DocIO
AtliDev
Asked On March 1, 2019 04:27 PM UTC

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.

Dilli Babu Nandha Gopal [Syncfusion]
Replied On 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. 


AtliDev
Replied On 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

AtliDev
Replied On 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

Dilli Babu Nandha Gopal [Syncfusion]
Replied On 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. 


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

;