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

PdfGrid in PdfGrid.Cell and PdfBitmap in PdfGrid.Cell

I am trying to achieve the above mentioned, but cant figure out if it is possible.
So basically - can I put content in the gridCells in any way?

     private static PdfLayoutResult AddAssetReport(PdfPage page, RectangleF bounds, Report report)
        {
            foreach (var gAssetGroup in report.AssetGroups)
            {
                var groupGrid = new PdfGrid();
                groupGrid.Columns.Add(1);
                var groupRow = groupGrid.Rows.Add();
                groupRow.Cells[0].Value = $"{gAssetGroup.Name} - {gAssetGroup.AverageRating}";

                foreach (var subGroup in gAssetGroup.AssetSubGroupList)
                {
                    groupGrid.Rows.Add();
                    var subGroupRow = groupGrid.Rows.Add();
                    subGroupRow.Cells[0].Value = $"{subGroup.Name} - {subGroup.AverageRating}";

                    foreach (var asset in subGroup.AssetList)
                    {
                        groupGrid.Rows.Add();
                        var assetRow = groupGrid.Rows.Add();
                        assetRow.Cells[0].Value = $"{asset.Name} - {asset.ReportAsset.Rating}";
                        var remarkRow = groupGrid.Rows.Add();
                        remarkRow.Cells[0].Value = asset.ReportAsset.Remark;

                        foreach (var image in asset.ReportAsset.Images)
                        {
                            
                            var imageStream = new FileStream(image, FileMode.Open, FileAccess.Read);
                            var bitmap = new PdfBitmap(imageStream);
                            groupGrid.Rows.Add();
                            var imageRow = groupGrid.Rows.Add();
                            imageRow.Cells[0].Value = bitmap;
                        }
                    }
                }
            }
        }

1 Reply

DB Dilli Babu Nandha Gopal Syncfusion Team February 27, 2019 01:24 PM UTC

Hi Jesper, 

Greetings from Syncfusion. 

The code example which you have used in the previous update is correct and we can use the same code snippet for adding the image as the content of the Grid cell.  

Code example: 
//Create a new PDF document 
PdfDocument pdfDocument = new PdfDocument(); 
//Add page to the PDF document 
PdfPage pdfPage = pdfDocument.Pages.Add(); 
//Create a new PdfGrid 
PdfGrid pdfGrid = new PdfGrid(); 
//Add three columns 
pdfGrid.Columns.Add(3); 
//Add header 
pdfGrid.Headers.Add(1); 
PdfGridRow pdfGridHeader = pdfGrid.Headers[0]; 
pdfGridHeader.Cells[0].Value = "Employee ID"; 
pdfGridHeader.Cells[1].Value = "Employee Name"; 
pdfGridHeader.Cells[2].Value = "Salary"; 
//Add rows 
PdfGridRow pdfGridRow = pdfGrid.Rows.Add(); 
pdfGridRow.Cells[0].Value = "E01"; 
pdfGridRow.Cells[1].Value = "Clay"; 
pdfGridRow.Cells[2].Value = "$10,000"; 
//Load the image from the stream 
FileStream fs = new FileStream(@"Image file path", FileMode.Open); 
            
//Apply style 
PdfGridCell pdfGridCell = pdfGrid.Rows[0].Cells[0]; 
//Set the cell value as the bitmap image 
pdfGridCell.Value = new PdfBitmap(fs); 
 
pdfGrid.Rows[0].Height = 50; 
//Draw the PdfGrid 
pdfGrid.Draw(pdfPage, PointF.Empty); 
 
MemoryStream ms = new MemoryStream(); 
//Save the document 
pdfDocument.Save(ms); 
//Close the document 
pdfDocument.Close(true); 

We have created a sample for the same and we have attached the same below: 

Please let us know if you need any further information in this. 

Regards, 
Dilli babu. 


Loader.
Live Chat Icon For mobile
Up arrow icon