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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Image in PdfGridCell keeping aspect ratio

Thread ID:

Created:

Updated:

Platform:

Replies:

113776 Oct 8,2013 11:13 AM UTC Oct 14,2013 09:59 AM UTC ASP.NET MVC (Classic) 3
loading
Tags: PDF
Truls Rødfjell
Asked On October 8, 2013 11:13 AM UTC

Hey,

I have a PDF with a grid and I want to have different images in different cells. These images have different size and aspect ratio, but all the cells are the same size. I want to add the images to cells and keep the same aspect ratio as the original image, but when you insert them as background images they are resized and streched to fit the cell.

I.e. have a picture that's 1000x500 px and a cell that's squared (same width and height). If i put this inside a PdfGridCell as a background image, it's streched so that the width and height is the same, and looks distorted. 

Is there any way I can insert it into a PdfGridCell and force it to keep the same aspect ratio ? Or do I have to find out the height and width of a PdfGridCell in pixels, resize the image with the same aspect ratio to a Image that will fit the cell and then add it ? Or perhaps PdfLightTable have any support for inserting images into cells keeping the aspect ratio ?

Thanks in advance :)

KarthikeyanC [Syncfusion]
Replied On October 11, 2013 05:32 AM UTC

Hi Truls,

Thank you for using Syncfusion Products.

 

We can able to keep the same Aspect Ratio of the image into the Pdf Grid cell, please use the below property to position the background image to center with the same aspect ratio. Please let us know if this code snippet satisfied your requirement.

Code Snippet:

            pdfGrid.Rows[0].Cells[1].ImagePosition = PdfGridImagePosition.Center;

 

Please let us know if you need any further assistance.

 

Thanks,

Karthikeyan.C


Truls Rødfjell
Replied On October 11, 2013 06:33 AM UTC

Hey,

On images that can fit the cell, the image is centered in the cell, but on images larger then the cell itself - the image is just rescaled to the max height and width of the cell (ignoring the aspect ratio). 

Example: Image is 100x50 and the cell is 50x50 px... the image will be resized to 50x50 - I want the image to be resized to 50x25 before it's inserted into the cell.

Is there any way I can find the height and the width of a cell, and the image that I'm going to insert into the cell, in points so I can resize it before inserting it ?

If this is not supported, any other components I can use instead of the PdfGridCell for this purpose ?

Thanks,
Truls

KarthikeyanC [Syncfusion]
Replied On October 14, 2013 09:59 AM UTC

Hi Truls,

Thank you for your update.

 

The image can be fit into the Pdf Grid cell by using the following code snippet.

Please use the below code snippet:

            pdfGrid.Rows[0].Cells[1].ImagePosition = PdfGridImagePosition.Fit;

Also we have found an issue in our product that when the image width is greater than the image height Fit is not working properly. Please create a Direct trac incident with the title “Forum- 113776- Image in PdfGridCell keeping aspect ratio” for getting the patch for this issue.

 

Please let us know if you have any concern.

 

Thanks,

Karthikeyan.C


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.

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

;