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

Problem show image in PdfLightTable

Good afternoon

I need the image in the "Image" column on my grid

//string imageAsString = "/9j/4Rc7RXhpZgAATU0AKgAAAAgA.....";
            byte[] data = new byte[imageAsString.Length];
            MemoryStream stream = new MemoryStream(data);

            PdfColumn colImagem = new PdfColumn("IMAGEM");
            colImagem.StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            colImagem.Width = 100;

            PdfColumn colCodigo = new PdfColumn("CÓDIGO");
            colCodigo.StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            colCodigo.Width = 40;
string Codigo = "ABC";
pdfLightTable.Rows.Add(new object[] { stream, Codigo);
It occurs that when sending to the PDF, it does not show the image. 

This showing only the string "System.IO.MemoryStream...

Can someone help me....

Thank you

3 Replies

SL Sowmiya Loganathan Syncfusion Team November 27, 2019 08:36 AM

Hi Marcelo, 

Thank you for contacting Syncfusion support.  

We can able to add the image in PDF table cell by using BeginCellLayout event handler. Please refer the below code snippet for more details, 

//Create a new PDF document 
PdfDocument document = new PdfDocument(); 
//Add a page 
PdfPage page = document.Pages.Add(); 
//Create a PdfLightTable 
PdfLightTable pdfLightTable = new PdfLightTable(); 
//Create a data table 
DataTable dataTable = new DataTable(); 
//Add columns to data table 
//Add rows to data table  
dataTable.Rows.Add("Adventure Cycle", ""); 
//Assign data source 
pdfLightTable.DataSource = dataTable; 
pdfLightTable.BeginCellLayout += pdfLightTable_BeginCellLayout; 
pdfLightTable.BeginRowLayout += PdfLightTable_BeginRowLayout; 
pdfLightTable.Style.ShowHeader = true; 
//Draw light table to the page of PDF document 
pdfLightTable.Draw(page, new RectangleF(0, 50, page.GetClientSize().Width, page.GetClientSize().Height));  

Event handlers:  

private void PdfLightTable_BeginRowLayout(object sender, BeginRowLayoutEventArgs args) 
    if (args.RowIndex == 0) 
        args.MinimalHeight = 100; 
private void pdfLightTable_BeginCellLayout(object sender, BeginCellLayoutEventArgs args) 
    //Draw image in the same cell 
    if (args.RowIndex==0 && args.CellIndex == 1) 
        //Load the image as stream 
        Stream imageStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.Image.jpg"); 
        PdfBitmap image = new PdfBitmap(imageStream); 
        //Draw image  
        args.Graphics.DrawImage(image, args.Bounds.X, args.Bounds.Y , args.Bounds.Width, args.Bounds.Height); 

Please try the above solution in your end and let us know the result. 

Sowmiya Loganathan 

SS Sarasilmiya Shahul Hameed Syncfusion Team November 28, 2019 12:03 AM

From: marcelo 
Sent: Wednesday, November 27, 2019 12:05 PM
Subject: RES: Syncfusion support community forum 149448, Problem show image in PdfLightTable, has been updated. 
Good afternoon. 

The example sent is working perfectly, but if there is more than one image does not appear the others. only the first image. In case I have a list of products with your images and as an example sent, it would be only for one image. 

I need some help. 

Thank you 

SL Sowmiya Loganathan Syncfusion Team January 3, 2020 06:32 AM

Hi Marcelo, 

We have created the sample to add two images in one PDF table cell. Please find the sample for the same from below, 

Please try the above solution in your end and let us know the result.  

Sowmiya Loganathan 

Live Chat Icon For mobile
Up arrow icon