image not exporting on radgrid exporttopdf

4 posts, 0 answers
  1. Mehreen
    Mehreen avatar
    13 posts
    Member since:
    Mar 2014

    Posted 04 Jun 2015 Link to this post

    I am unable to get the image to export on the pdf. Here is my code:

    protected void RadGrid1_PdfExporting(object sender, GridPdfExportingArgs e)
    {

    string tableWrapper = string.Empty;
    tableWrapper = "<table><colgroup><col style='width:550px;' /></colgroup>";
    tableWrapper += "<thead></thead><tbody><tr><td>" + e.RawHTML + "</td></tr>";
    tableWrapper += "<tr><td>&nbsp;</td></tr>";
    tableWrapper += "<tr><td>&nbsp;</td></tr>";
    tableWrapper += "<tr><td style='padding-left:5px;'>" + AddPDFTables() + "</td></tr>";
    tableWrapper += "</tbody><tfoot></tfoot></table>";

    e.RawHTML = tableWrapper;
    }

    private string AddPDFTables()
    {
    string tables = string.Empty;

    tables += "<?hard-pagebreak?>";
    tables += "<table style='border-style:none; width:550px; font-size:8px; padding-left:2px; padding-right:2px; padding-top:2px;'>";
    tables += "<colgroup><col style='width:200px; vertical-align:top;' /><col style='width:20px;' /><col style='width:200px; vertical-align:top;' /></colgroup>";
    tables += "<thead></thead><tbody>";
    tables += "<tr><td>" + CreateLegendPDF() + "</td><td>&nbsp;</td><td>" + CreateRejectCodePDF() + "</td></tr>";
    tables += "</tbody></table>";

    return tables;
    }

    private string CreateLegendPDF()
    {
    string legend = string.Empty;

    legend += "<table style='border-style:solid; border-color:#5d8cc9; border-width:1px; width:200px; font-size:8px; padding-left:2px; padding-right:2px; padding-top:2px; padding-bottom:2px;'>";
    legend += "<colgroup><col style='width:30px;' /><col style='width:150px;' /></colgroup>";
    legend += "<thead><tr><th colspan='2' style='background-color:#bdcbde; font-weight:bold; font-size:9px; text-align:left; padding-left:2px;'>Content Areas</th></tr></thead>";
    legend += "<tbody>";

    if (listLegendRows.Count <= 0)
    {
    listLegendRows = (List<string>)ViewState["LegendList"];
    }

    if (listLegendRows.Count > 0)
    {
    foreach (string item in listLegendRows)
    {
    legend += item;
    }
    }
    legend += "</tbody></table>";

    return legend;
    }

    private string CreateRejectCodePDF()
    {
    string rejectString = string.Empty;
    List<string> listRejectRows = new List<string>();

    if (ViewState["RejectList"] != null)
    {
    listRejectRows = (List<string>)ViewState["RejectList"];
    }

    if (listRejectRows.Count > 0)
    {
    rejectString += "<table style='border-style:solid; border-color:#5d8cc9; border-width:1px; width:200px; font-size:8px; padding-left:2px; padding-right:2px; padding-top:2px; padding-bottom:2px;'>";
    rejectString += "<colgroup><col style='width:30px;' /><col style='width:150px;' /></colgroup>";
    rejectString += "<thead><tr><th colspan='2' style='background-color:#bdcbde; font-weight:bold; font-size:9px; text-align:left; padding-left:2px;'>ARDMS Reject Codes</th></tr></thead>";
    rejectString += "<tbody>";

    foreach (string item in listRejectRows)
    {
    rejectString += item;
    }
    rejectString += "</tbody></table>";
    }
    return rejectString;
    }

     

     

    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
    if (isPdfExport)
    {
    GridItem item = e.Item as GridItem;
    item.Style["font-family"] = "Segoe UI";
    item.Style["font-size"] = "8px";

    switch (item.ItemType) //Mimic RadGrid appearance for the exported PDF file
    {
    case GridItemType.CommandItem:
    item.Style["display"] = "none";
    item.Visible = true;
    item.Style["background-color"] = "#000000";
    break;
    case GridItemType.Item:
    item.Style["background-color"] = "#FFFFFF";
    break;
    case GridItemType.AlternatingItem:
    item.Style["background-color"] = "#e8f1fc";
    break;
    case GridItemType.Header:
    item.Style["background-color"] = "#bdcbde";
    break;
    case GridItemType.FilteringItem:
    item.Style["display"] = "none";
    item.Visible = false;
    break;
    case GridItemType.Footer:
    item.Style["background-color"] = "#c3d8f1";
    break;
    }

    if (item is GridCommandItem)
    {
    item.PrepareItemStyle(); //needed to span the image over the CommandItem cells
    }
    }
    }

     

     

     

     This is the error I am getting

    [GridPdfExportException: Invalid XHTML. RadGrid has to render correct XHTML in order to export to PDF.
    Parse error:
    The 'tbody' start tag on line 674 position 83 does not match the end tag of 'thead'. Line 687, position 4.
    at line:
    </thead><tbody>]

     

     

     

    I checked all the tags and they seem fine to me.

    How do I correct this?

    Thanks,

  2. Kostadin
    Admin
    Kostadin avatar
    1733 posts

    Posted 09 Jun 2015 Link to this post

    Hello Mehreen,

    This error occurs when there is a forgotten closing/opening tags and the XHTML validation fails. I would recommended to get the modified RawHTML and use the W3C validator to check for errors in the HTML.

    Regards,
    Kostadin
    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
  3. Mehreen
    Mehreen avatar
    13 posts
    Member since:
    Mar 2014

    Posted 19 Jun 2015 in reply to Kostadin Link to this post

    For some reason, I am not able to modify the margins on the exported grid. Its moved to the right  of the page. I used

    PageLeftMargin="20mm" 
                            PageRightMargin="20mm" 

    but its ignoring anything i put in these settings. How can I center justify the grid on the exported pdf?

  4. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 24 Jun 2015 Link to this post

    Hi Mehreen,

    In order to center the RadGrid control you should simply remove its width instead of setting any page properties. This way the RadGrid will be with width 100% and will automatically center on the page.

    Regards,
    Maria Ilieva
    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