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

PdfGrid in PdfGrid.Cell and PdfBitmap in PdfGrid.Cell

Thread ID:

Created:

Updated:

Platform:

Replies:

142941 Feb 26,2019 12:49 PM UTC Feb 27,2019 01:24 PM UTC ASP.NET Core - EJ 2 1
loading
Tags: PDF
SirLanceLang
Asked On February 26, 2019 12:49 PM UTC

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;
                        }
                    }
                }
            }
        }

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


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

;