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

image not exporting on radgrid exporttopdf

3 Answers 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mehreen
Top achievements
Rank 1
Mehreen asked on 04 Jun 2015, 04:23 PM

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,

3 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 09 Jun 2015, 08:50 AM
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
0
Mehreen
Top achievements
Rank 1
answered on 19 Jun 2015, 07:57 PM

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?

0
Maria Ilieva
Telerik team
answered on 24 Jun 2015, 11:48 AM
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
Tags
Grid
Asked by
Mehreen
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Mehreen
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or