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> </td></tr>";
tableWrapper += "<tr><td> </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> </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,