This is a migrated thread and some comments may be shown as answers.

Export to Pdf images not rendered

11 Answers 339 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 11 Jan 2011, 11:04 PM
I have tried searching everywhere and I have found no mention of the issue I am running into. Using a winforms application I add a png image to a radgridview. Then I export the Radgridview to a pdf file. However, in the pdf the image only shows up as the text "System.Drawing.Bitmap". Any idea what could cause the image to not render for the pdf? It looks just fine within the radgridview. I'm currently using version 2010.2.10.914 of the winform controls. Any help would be greatly appreciated.


This is the code I used to produce the Pdf.
private void AddImage(RadGridView TheGrid, MemoryStream mStream)
        {
            Image TheImage = System.Drawing.Image.FromStream(mStream);
            GridViewImageColumn ImageColumn = new GridViewImageColumn();
            ImageColumn.ImageLayout = ImageLayout.Stretch;
            ImageColumn.Width = 1095;
            ImageColumn.IsVisible = true;
 
            radGridView1.MasterGridViewTemplate.Columns.Add(ImageColumn);
            radGridView1.MasterGridViewTemplate.Rows.Add(TheImage);
            radGridView1.Refresh();
        }
 
            radGridView1.MasterGridViewTemplate.Columns.Add(Chart);
            radGridView1.MasterGridViewTemplate.Rows.Add(ChartImage.Image);
            radGridView1.Refresh();
        }
 
 
 
 
private void radGridView1_Click(object sender, EventArgs e)
        {
             
            if (this.radGridView1.Rows.Count != 0)
            {
                ExportToPDF exporter = new ExportToPDF(this.radGridView1);
                exporter.FileExtension = "pdf";
                exporter.ExportVisualSettings = true;
                exporter.PageTitle = "Chart";
                exporter.FitToPageWidth = true;
                exporter.PdfExportSettings.EnableCopy = true;
                 
 
                exporter.SummariesExportOption = SummariesOption.ExportAll;
 
                string fileName = "C:\\ExportedData.pdf";
                exporter.RunExport(fileName);
 
            }

11 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 12 Jan 2011, 01:06 PM
Hello,

As far as I'm aware, the ExportToPDF only currently supports rendering values that can be converted to string.
Regards,
Richard
0
Martin Vasilev
Telerik team
answered on 14 Jan 2011, 10:04 AM
Hi Steven,

We do not support exporting images to PDF and Richard is right about the string rendering.

Do not hesitate to contact us again if you have any additional questions.

Greetings,
Martin Vasilev
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
0
Steven
Top achievements
Rank 1
answered on 14 Jan 2011, 06:26 PM
Thank you for the replies. I have opted to send the image into a report viewer and use the exporting function from that instead. 
0
Ludovic
Top achievements
Rank 2
answered on 29 Oct 2012, 03:23 PM
Hello,

I am writing here since I am having the same issue as Steven. I am using the latest components for Winforms (2012.3.1017.40).

I want to export all columns from my radgridiview to Excel and PDF and also print it. Printing is working well but I can't manage to export the GridViewImageColumn to Excel and PDF.

If this feature is not supported, could you please advise me how to export the radgridview to Excel and PDF with the images? Can we add it to the PITS?

Best regards,
Ludovic
0
Ivan Petrov
Telerik team
answered on 01 Nov 2012, 10:29 AM
Hi Ludovic,

Thank you for writing.

Currently the export to HTML/PDF does not support exporting images. I have added a feature request to our Public Issue Tracking System. You can track its progress, subscribe for status change alerts and add your vote/comment on the following link - PITS Feature.

Excel does not support importing images into cells. You can try and import an image into an excel file and you will see that the image is actually floating over the table and is not contained in a particular cell.

I have updated your Telerik points for the good suggestion.

I hope this is useful. Should you have further questions, I would be glad to help.
 
All the best,
Ivan Petrov
the Telerik team
Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Emanuel Varga
Top achievements
Rank 1
answered on 08 Nov 2012, 07:27 AM
Hello,

Maybe you should consider taking a look at telerik reporting exporting to pdf (here)

Adobe PDF

PDF is used for representing two-dimensional documents in a manner independent of the application software, hardware, and operating system. Each PDF file encapsulates a complete description of a fixed-layout 2D document that includes the text, fonts, images, and 2D vector graphics which composeRTF the documents.

Hope this helps

Best Regards,
Emanuel Varga
WinForms MVP
0
AD
Top achievements
Rank 1
answered on 01 Mar 2016, 11:05 PM
Is there any update to this issue? Is it possible to print or save a radgridview that contains an image column? I get "System.Byte[]" on the column of the pdf, instead of the image. Am I doing something wrong?
0
Stefan
Telerik team
answered on 02 Mar 2016, 07:00 AM
Hello Apostolos,

As of Q2 2015, we have introduced new export providers utilizing our document processing libraries. The GridViewPdfExport class is used to export RadGridView to a pdf and the images will be exported as expected. More information about this provider is available here: http://docs.telerik.com/devtools/winforms/gridview/exporting-data/export-to-pdf

I hope that you find this information useful.

Regards,
Stefan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
AD
Top achievements
Rank 1
answered on 02 Mar 2016, 05:02 PM

Hello Stefan,

could you please attach a sample code, because I keep getting the error that I attached on my previous post (error.jpg). In the pdf instead of displaying the image, I get the "System.Byte[]".

Maybe there is something wrong with the code that I use to create the image column on the radgridview? The images are displayed properly on the radgridview, but on the final exported pdf. Part of the code that I use to create the radgridview is the following:

 

DataTable dataTable_radGridView = new DataTable();

System.Data.DataColumn Column1 = new System.Data.DataColumn("img_fileID", typeof(byte[]));
Column1.Caption = "Image";

dataTable_radGridView.Columns.Add(Column1);

 

//I get the image raw data from the database

dataTable_radGridView.BeginLoadData();

UInt32 FileSize;
byte[] rawData;
Image ret_image = null;
FileSize = rdr.GetUInt32(rdr.GetOrdinal("img_size"));
rawData = new byte[FileSize];
rdr.GetBytes(rdr.GetOrdinal("img_file"), 0, rawData, 0, (int)FileSize);

MemoryStream ms = new MemoryStream(rawData);
ret_image = new Bitmap(ms);
if (ret_image != null) {

       row["img_fileID"] = imageToByteArray(ret_image);

}
ms.Close();
ms.Dispose();
 }
dataTable_radGridView.Rows.Add(row);

rdr.Close();
rdr.Dispose();
command.Dispose();
dataTable_radGridView.EndLoadData();

 

 

radGridView1.MasterTemplate.BeginUpdate();
radGridView1.DataSource = dataTable_radGridView;
radGridView1.MasterTemplate.EndUpdate();

 

public static byte[] imageToByteArray(System.Drawing.Image imageIn)
{
    MemoryStream ms = new MemoryStream();
    imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
    return ms.ToArray();
}

 

//Then I use the code that you suggested (http://docs.telerik.com/devtools/winforms/gridview/exporting-data/export-to-pdf) in order to create the pdf, but with NO success.

 

Thank you in advance!
0
AD
Top achievements
Rank 1
answered on 02 Mar 2016, 07:22 PM

my mistake was that I using ExportToPDF instead of GridViewPdfExport that you suggested (sorry... they were both displayed on the same link...)

Please let me know how I can:

1) set the orientation of the page

2) set the page margins

3) wrapText of cells

when GridViewPdfExport is used?

 

0
Stefan
Telerik team
answered on 03 Mar 2016, 08:34 AM
Hello Apostolos,

Directly to your questions.

1. GridViewPdfExport features PageSize property where you can determine the size of the page: 
exporter.PageSize = new System.Drawing.SizeF(297, 210);

2. It also features PageMargins property to set the desired margins:
exporter.PageMargins = new System.Windows.Forms.Padding(10, 10, 10, 10);

3. To set the text wrap, you can handle the CellFormatting event of the exporter.
void exporter_CellFormatting(object sender, PdfExportCellFormattingEventArgs e)
{
    e.CellElement.TextWrap = true;
}

This would also require setting the ExportVisualSettings to true.

In general, if in your grid you have set the text wrapping for the cells, just enabling the visual settings will also transfer this setting, along with all other visual settings (, forecolor, row height, etc) to the exporter file. 

I hope that you find this information useful.

Regards,
Stefan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Steven
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Martin Vasilev
Telerik team
Steven
Top achievements
Rank 1
Ludovic
Top achievements
Rank 2
Ivan Petrov
Telerik team
Emanuel Varga
Top achievements
Rank 1
AD
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or