Export to Pdf images not rendered

12 posts, 0 answers
  1. Steven
    Steven avatar
    4 posts
    Member since:
    Jul 2010

    Posted 11 Jan 2011 Link to this post

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

  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 12 Jan 2011 Link to this post

    Hello,

    As far as I'm aware, the ExportToPDF only currently supports rendering values that can be converted to string.
    Regards,
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 14 Jan 2011 Link to this post

    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.
  5. Steven
    Steven avatar
    4 posts
    Member since:
    Jul 2010

    Posted 14 Jan 2011 Link to this post

    Thank you for the replies. I have opted to send the image into a report viewer and use the exporting function from that instead. 
  6. Ludovic
    Ludovic avatar
    12 posts
    Member since:
    Nov 2011

    Posted 29 Oct 2012 Link to this post

    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
  7. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 01 Nov 2012 Link to this post

    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.
  8. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 08 Nov 2012 Link to this post

    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
  9. AD
    AD avatar
    6 posts
    Member since:
    Jul 2008

    Posted 01 Mar in reply to Ivan Petrov Link to this post

    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?
  10. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 02 Mar Link to this post

    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
  11. AD
    AD avatar
    6 posts
    Member since:
    Jul 2008

    Posted 02 Mar in reply to Stefan Link to this post

    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!
  12. AD
    AD avatar
    6 posts
    Member since:
    Jul 2008

    Posted 02 Mar in reply to AD Link to this post

    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?

     

  13. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 03 Mar Link to this post

    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 (backcolor, 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
Back to Top
UI for WinForms is Visual Studio 2017 Ready