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

How to preserve the aspect ratio of the image in PdfGrid

Platform: WinForms |
Control: PDF
Tags: pdf, pdfgrid

Preserve the aspect ratio of the image in PdfGrid

The aspect ratio of an image can be preserved in PdfGrid by using ImagePosition property which must be set to “fit” in the PdfGrid cell.

Assemblies Required



The below code snippet illustrates how to preserve the aspect ratio of the image in PDF Grid.

Code Snippet:

//Creates a new PDF document.
PdfDocument doc = new PdfDocument();
//Adds a page.
PdfPage page = doc.Pages.Add();
//Creates a PdfGrid.
PdfGrid pdfGrid = new PdfGrid();
//Creates a DataTable.
DataTable dataTable = new DataTable();
//Adds columns to the DataTable.
//Adds rows to the DataTable.
 dataTable.Rows.Add(new object[] { " ", "Clay" });
dataTable.Rows.Add(new object[] { "E02", "Thomas" });
//Assigns data source.
pdfGrid.DataSource = dataTable;
//Gets the Image
PdfBitmap pBmp = new PdfBitmap(@"..\..\Data\logo.png");
pdfGrid.Rows[0].Cells[0].Style.BackgroundImage = pBmp;
//Fit the image inorder to preserve the aspect ratio.
pdfGrid.Rows[0].Cells[0].ImagePosition = PdfGridImagePosition.Fit;
   // pdfGrid.Rows[0].Cells[0].ImagePosition = PdfGridImagePosition.Center;
      // pdfGrid.Rows[0].Cells[0].ImagePosition = PdfGridImagePosition.Stretch;
   // pdfGrid.Rows[0].Cells[0].ImagePosition = PdfGridImagePosition.Tile
//Draws grid to the page of PDF document.
pdfGrid.Draw(page, new PointF(10, 10));
//Saves the document and dispose it


The working sample can be downloaded from the below link:


2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

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

Live Chat Icon For mobile