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

Invalid XHTML. RadGrid has to render correct XHTML in order to export to PDF.

17 Answers 399 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mehmet
Top achievements
Rank 1
Mehmet asked on 10 Jul 2014, 01:16 AM
Hi there,

I have been searching all over the forum, however, couldn't find out the solution to fix my similar case as follow:

Invalid XHTML. RadGrid has to render correct XHTML in order to export to PDF.
Parse error:
The 'body' start tag on line 674 position 6 does not match the end tag of 'td'. Line 689, position 39.
at line:
</td><td style="white-space:nowrap;">

I will paste my code below:

ASPX:
001.<div id="print_area">
002.                    <asp:ImageButton ID="DownloadCSV" ImageUrl="images/file-extension-csv-icon.png"
003.                        OnClick="DownloadCSV_Click" runat="server" CssClass="ImageButtons" />
004.                    <asp:ImageButton ID="DownloadPDF" runat="server" OnClick="DownloadPDF_Click" ImageUrl="images/file-extension-pdf-icon.png"
005.                        CssClass="pdfButton"></asp:ImageButton>
006.                    <br />
007.                    <telerik:RadGrid AutoGenerateColumns="False" ID="RadGrid1" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" runat="server" OnItemCommand="RadGrid1_ItemCommand" OnItemCreated="RadGrid1_ItemCreated" EnableLinqExpressions="true" HtmlEncode="true" OnPdfExporting="RadGrid1_PdfExporting"
008.                        ShowGroupPanel="True" CellSpacing="-1" GridLines="Both" Skin="Office2010Silver" Width="100%">
009.                        <PagerStyle Mode="NextPrevAndNumeric" />
010.                        <GroupingSettings CaseSensitive="false" />
011.                        <ClientSettings AllowKeyboardNavigation="true">
012.                        </ClientSettings>
013.                        <ExportSettings IgnorePaging="true" OpenInNewWindow="true">
014.                            <Pdf PageHeight="210mm" PageWidth="297mm" DefaultFontFamily="Arial Unicode MS" PageTopMargin="45mm"
015.                                BorderStyle="Medium" BorderColor="#666666" PaperSize="A4">
016.                            </Pdf>
017.                        </ExportSettings>
018.                        <MasterTableView Width="100%" DataKeyNames="JobID" HierarchyLoadMode="ServerOnDemand">
019.                            <Columns>
020.                                <telerik:GridMaskedColumn DataField="JobID" HeaderText="JobID#"
021.                                    FilterControlWidth="50px" AutoPostBackOnFilter="false" CurrentFilterFunction="EqualTo"
022.                                    FilterDelay="2000" ShowFilterIcon="false" Mask="#####">
023.                                    <ColumnValidationSettings>
024.                                        <ModelErrorMessage Text=""></ModelErrorMessage>
025.                                    </ColumnValidationSettings>
026.                                </telerik:GridMaskedColumn>
027.                                <telerik:GridBoundColumn HeaderText="Customer Ref No" DataField="JobCustomerRefNo" UniqueName="JobCustomerRefNo"
028.                                    SortExpression="JobCustomerRefNo" HeaderStyle-Width="180px" FilterControlAltText="Filter JobCustomerRefNo column">
029.                                    <ColumnValidationSettings>
030.                                        <ModelErrorMessage Text=""></ModelErrorMessage>
031.                                    </ColumnValidationSettings>
032. 
033.                                </telerik:GridBoundColumn>
034.                                <telerik:GridBoundColumn DataField="JobTitle" FilterControlAltText="Filter JobTitle column" HeaderText="Job Title" SortExpression="JobTitle" UniqueName="JobTitle">
035.                                    <ColumnValidationSettings>
036.                                        <ModelErrorMessage Text="" />
037.                                    </ColumnValidationSettings>
038.                                </telerik:GridBoundColumn>
039.                                <telerik:GridDateTimeColumn DataField="JobBookedDate" PickerType="DatePicker" EnableTimeIndependentFiltering="true"
040.                                    DataFormatString="{0:dd/MM/yyyy HH:mm }" DataType="System.DateTime" FilterControlAltText="Filter JobBookedDate column" HeaderText="Job Booked Date" SortExpression="JobBookedDate" UniqueName="JobBookedDate">
041.                                    <ColumnValidationSettings>
042.                                        <ModelErrorMessage Text="" />
043.                                    </ColumnValidationSettings>
044.                                </telerik:GridDateTimeColumn>
045.                                <telerik:GridBoundColumn DataField="JobAddress1" FilterControlAltText="Filter JobAddress1 column" HeaderText="Address" SortExpression="JobAddress1" UniqueName="JobAddress1">
046.                                    <ColumnValidationSettings>
047.                                        <ModelErrorMessage Text="" />
048.                                    </ColumnValidationSettings>
049.                                </telerik:GridBoundColumn>
050.                                <telerik:GridBoundColumn DataField="JobSuburb" FilterControlAltText="Filter JobSuburb column" HeaderText="Suburb" SortExpression="JobSuburb" UniqueName="JobSuburb">
051.                                    <ColumnValidationSettings>
052.                                        <ModelErrorMessage Text="" />
053.                                    </ColumnValidationSettings>
054.                                </telerik:GridBoundColumn>
055.                                <telerik:GridBoundColumn DataField="JobPostCode" FilterControlAltText="Filter JobPostCode column" HeaderText="PostCode" SortExpression="JobPostCode" UniqueName="JobPostCode">
056.                                    <ColumnValidationSettings>
057.                                        <ModelErrorMessage Text="" />
058.                                    </ColumnValidationSettings>
059.                                </telerik:GridBoundColumn>
060.                                <telerik:GridBoundColumn DataField="JobState" FilterControlAltText="Filter JobState column" HeaderText="State" SortExpression="JobState" UniqueName="JobState">
061.                                    <ColumnValidationSettings>
062.                                        <ModelErrorMessage Text="" />
063.                                    </ColumnValidationSettings>
064.                                </telerik:GridBoundColumn>
065.                                <telerik:GridTemplateColumn DataField="JobStatusID" HeaderText="Status Type" UniqueName="JobStatusID"
066.                                    HeaderStyle-Width="200px" SortExpression="JobStatusID">
067.                                    <FilterTemplate>
068.                                        <telerik:RadComboBox ID="comboJobStatus" DataTextField="JobStatusName"
069.                                            DataValueField="JobStatusID" Height="100px" AppendDataBoundItems="true" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("JobStatusID").CurrentFilterValue %>'
070.                                            runat="server" OnClientSelectedIndexChanged="JobStatusIndexChanged">
071.                                            <Items>
072.                                                <telerik:RadComboBoxItem Text="All" />
073.                                            </Items>
074.                                        </telerik:RadComboBox>
075.                                        <telerik:RadScriptBlock ID="RadScriptBlock3" runat="server">
076.                                            <script type="text/javascript">
077.                                                function JobStatusIndexChanged(sender, args) {
078.                                                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
079.                                                    tableView.filter("JobStatusID", args.get_item().get_value(), "EqualTo");
080.                                                }
081.                                            </script>
082.                                        </telerik:RadScriptBlock>
083.                                    </FilterTemplate>
084.                                    <ItemTemplate>
085.                                        <%# Eval("JobStatus") %>
086.                                    </ItemTemplate>
087.                                </telerik:GridTemplateColumn>
088.                                                               <telerik:GridTemplateColumn DataField="ClientID" HeaderText="Client" UniqueName="ClientID"
089.                                    HeaderStyle-Width="200px" SortExpression="ClientID">
090.                                    <FilterTemplate>
091.                                        <telerik:RadComboBox ID="comboClient" DataTextField="ClientName"
092.                                            DataValueField="ClientID" Height="100px" AppendDataBoundItems="true" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("ClientID").CurrentFilterValue %>'
093.                                            runat="server" OnClientSelectedIndexChanged="ClientIndexChanged">
094.                                            <Items>
095.                                                <telerik:RadComboBoxItem Text="All" />
096.                                            </Items>
097.                                        </telerik:RadComboBox>
098.                                        <telerik:RadScriptBlock ID="RadScriptBlock2" runat="server">
099.                                            <script type="text/javascript">
100.                                                function ClientIndexChanged(sender, args) {
101.                                                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
102.                                                    tableView.filter("ClientID", args.get_item().get_value(), "EqualTo");
103.                                                }
104.                                            </script>
105.                                        </telerik:RadScriptBlock>
106.                                    </FilterTemplate>
107.                                    <ItemTemplate>
108.                                        <%# Eval("Client") %>
109.                                    </ItemTemplate>
110.                                </telerik:GridTemplateColumn>
111.                                <telerik:GridTemplateColumn DataField="AssignedStaffID" HeaderText="Staff" UniqueName="AssignedStaffID"
112.                                    HeaderStyle-Width="200px" SortExpression="AssignedStaffID">
113.                                    <FilterTemplate>
114.                                        <telerik:RadComboBox ID="comboStaff" DataTextField="StaffName"
115.                                            DataValueField="StaffID" Height="100px" AppendDataBoundItems="true" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("AssignedStaffID").CurrentFilterValue %>'
116.                                            runat="server" OnClientSelectedIndexChanged="StaffIndexChanged">
117.                                            <Items>
118.                                                <telerik:RadComboBoxItem Text="All" />
119.                                            </Items>
120.                                        </telerik:RadComboBox>
121.                                        <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
122.                                            <script type="text/javascript">
123.                                                function StaffIndexChanged(sender, args) {
124.                                                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
125.                                                    tableView.filter("AssignedStaffID", args.get_item().get_value(), "EqualTo");
126.                                                }
127.                                            </script>
128.                                        </telerik:RadScriptBlock>
129.                                    </FilterTemplate>
130.                                    <ItemTemplate>
131.                                        <%# Eval("AssignedStaff") %>
132.                                    </ItemTemplate>
133.                                </telerik:GridTemplateColumn>
134.                            </Columns>
135.                            <NestedViewTemplate>
136.                                <asp:Panel runat="server" ID="InnerContainer" CssClass="viewWrap" Visible="false">
137.                                    <telerik:RadMultiPage runat="server" ID="Multipage1" SelectedIndex="0" RenderSelectedPageOnly="false">
138.                                        <telerik:RadPageView runat="server" ID="PageView1">
139.                                            <telerik:RadGrid runat="server" ID="JobStatusGrid">
140.                                                <MasterTableView ShowHeader="true" AutoGenerateColumns="False" AllowPaging="true"
141.                                                    DataKeyNames="JobStatusHistoryID" PageSize="7" HierarchyLoadMode="ServerOnDemand">
142.                                                    <Columns>
143.                                                        <telerik:GridBoundColumn HeaderText="Status Type" HeaderButtonType="TextButton"
144.                                                            DataField="JobStatus" UniqueName="JobStatusID">
145.                                                        </telerik:GridBoundColumn>
146.                                                        <telerik:GridBoundColumn HeaderText="Created By" HeaderButtonType="TextButton"
147.                                                            DataField="CreatedBy" UniqueName="CreatedBy">
148.                                                        </telerik:GridBoundColumn>
149.                                                        <telerik:GridBoundColumn HeaderText="Created On" HeaderButtonType="TextButton"
150.                                                            DataField="CreatedOn" UniqueName="CreatedOn">
151.                                                        </telerik:GridBoundColumn>
152.                                                    </Columns>
153.                                                </MasterTableView>
154.                                            </telerik:RadGrid>
155.                                        </telerik:RadPageView>
156.                                    </telerik:RadMultiPage>
157.                                </asp:Panel>
158.                            </NestedViewTemplate>
159.                        </MasterTableView>
160.                        <ClientSettings AllowDragToGroup="true">
161.                            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
162.                        </ClientSettings>
163.                    </telerik:RadGrid>
164.                </div>

ASPX.CS

01.protected void DownloadPDF_Click(object sender, System.EventArgs e)
02.        {
03.            isPdfExport = true;
04.            RadGrid Grid1 = (RadGrid)Page.Master.FindControl("MainContent").FindControl("RadGrid1");
05.            Grid1.ExportSettings.Pdf.AllowPrinting = true;
06.            Grid1.ExportSettings.Pdf.AllowModify = true;
07.            Grid1.ExportSettings.Pdf.AllowCopy = true;
08.            Grid1.ExportSettings.Pdf.AllowAdd = true;
09.            Grid1.ExportSettings.Pdf.DefaultFontFamily = "Helvetica";
10.            Grid1.ExportSettings.Pdf.PageLeftMargin = new Unit(2, UnitType.Mm);
11.            Grid1.ExportSettings.Pdf.PageRightMargin = new Unit(2, UnitType.Mm);
12.            Grid1.ExportSettings.Pdf.PageHeaderMargin = new Unit(0, UnitType.Mm);
13.            Grid1.ExportSettings.Pdf.PaperSize = GridPaperSize.Legal;
14.            Grid1.ExportSettings.Pdf.PageHeight = Unit.Parse("210mm");
15.            Grid1.ExportSettings.Pdf.PageWidth = Unit.Parse("420mm");
16. 
17.            foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns)
18.            {
19.                if (col.UniqueName != "MiddleInitial")
20.                {
21.                    col.HeaderStyle.Width = Unit.Pixel(50);
22.                }
23.            }
24.            Grid1.MasterTableView.ExportToPdf();
25.        }
01.protected void RadGrid1_PdfExporting(object sender, GridPdfExportingArgs e)
02.{
03.    StringBuilder customHTML = new StringBuilder();
04.    customHTML.Append("<p style='color: red; font-weight: bold; font-size: 10pt;'>Title Page</p>");
05.    customHTML.Append("<table style='font-family:Helvetica;font-size:9pt;width:500px;'>");
06.    customHTML.Append("<tr><td>Customer: aaa 1</td><td>Date: bbbb 2</td></tr>");
07.    customHTML.Append("<tr><td>Address: aaa 1</td><td>Email: bbbb 2 </td></tr>");
08.    customHTML.Append("<tr><td>City: aaa 1</td><td>Phone: bbbb 2 </td></tr>");
09.    customHTML.Append("<tr><td>State: aaa 1</td><td>Zip: bbbb 2 </td></tr>");
10.    customHTML.Append("</table>");
11.    e.RawHTML = customHTML + e.RawHTML;
12.}

Cheers

17 Answers, 1 is accepted

Sort by
0
Mehmet
Top achievements
Rank 1
answered on 10 Jul 2014, 10:14 PM
helloo , is there anybody ?
0
Mehmet
Top achievements
Rank 1
answered on 12 Jul 2014, 11:58 AM
please a respond for it.
thank you
0
Daniel
Telerik team
answered on 14 Jul 2014, 07:15 AM
Hello Mehmet,

I would recommend that you first try to comment out the custom HTML code (in PdfExporting).
If this fixes the problem, please try HTML encoding that piece of code as shown in the example below:
customHTML.Append(Server.HtmlEncode("<tr><td>State: aaa 1</td><td>Zip: bbbb 2 </td></tr>"));

Regards,
Daniel
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Mehmet
Top achievements
Rank 1
answered on 14 Jul 2014, 10:03 PM
It didn't work - I will keep it up with the ticket issue.
0
Daniel
Telerik team
answered on 15 Jul 2014, 08:01 AM
Hi Mehmet,

The best way to diagnose problems with validation is to handle the PdfExporting event and copy the contents of the e.RawHTML property. You can then paste this HTML code in the W3C validator to see what causes the problem.

Regards,
Daniel
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Brian Clark
Top achievements
Rank 1
answered on 14 Jan 2015, 07:16 PM
I have the same issue.  I tracked this down to a GridTemplateColumn 

<telerik:GridTemplateColumn UniqueName="Description" HeaderText="Description">
<ItemTemplate>
    <%#GetDescriptionColumn((DataRowView) Container.DataItem) %>
</ItemTemplate>
</telerik:GridTemplateColumn>

​
0
Daniel
Telerik team
answered on 19 Jan 2015, 09:30 AM
Hello Brian,

Please check the output of the GetDescriptionColumn method. You can try to validate the HTML using the W3C validator I mentioned in my previous answer. You may need to HTML encode the string to avoid errors caused due to unclosed angular brackets, ampersand characters and the like.
HtmlEncode Method (String)

Let me know if you need more information.

Regards,
Daniel
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jeff
Top achievements
Rank 1
answered on 22 Sep 2015, 11:30 PM

I am also getting this error.  I encountered it with an app that I was developing first.  Then I built the Telerik demos and tried it using the Grid - Export to PDF example.  The demo also fails with the same error:

Invalid XHTML. RadGrid has to render correct XHTML in order to export to PDF.
Parse error:
The 'body' start tag on line 674 position 6 does not match the end tag of 'td'. Line 675, position 19.
at line:
</td>

I have version 2015.2.826 of UI for ASP.NET AJAX installed and I'm using VS 2013.  Any thoughts on what might be going wrong ?

 

Thanks -- Jeff Gaiche

0
Jeff
Top achievements
Rank 1
answered on 23 Sep 2015, 02:21 PM
I recompiled the demos in VS2012 and it does work in that environment.   So, it seems to be related to which version of Visual Studio that is being used.   Any thoughts as to what the problem might be in the VS2013 build ?  Thank you -- Jeff
0
Mitch
Top achievements
Rank 1
answered on 23 Sep 2015, 02:30 PM

I have this same issue with Telerik.Web.UI 2015.1.401.45

However, I have 2 different projects (with similar code - UserControls have identical markup, same data source/query) - one works, the other gets this error.  Same version of VS for each.  Going to trawl through project settings/app pool settings for differences.

 

0
Kostadin
Telerik team
answered on 25 Sep 2015, 12:01 PM
Hello Jeff and Mitch,

Please note that the VS version should not impact the export behavior. I would recommend you to get the exported XHTML and check for an error in the document. For this purpose you can access the RowHTML from the PdfExporting event arguments and use the W3C validator.
protected void RadGrid1_PdfExporting(object sender, GridPdfExportingArgs e)
{
    string xhtml = e.RawHTML;
}


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
Jeff
Top achievements
Rank 1
answered on 25 Sep 2015, 01:21 PM

Hi Kostadin,

In my case, it was the CommandItemTemplate section in my RadGrid that was causing the issue.   I had a simple button that I was using to reset the sorting.   Telerik's demo also failed in exactly the same way using the image link control.   I was able to work around it by hiding the CommandItemTemplate when exporting to PDF although it's still a bit of a mystery why this part of the Telerik demo project worked in VS2012 and not in VS2013.   At least, I've been able to move on.

Thanks for your reply -- Jeff

0
Mitch
Top achievements
Rank 1
answered on 29 Sep 2015, 02:40 PM

I have spent some time with this.  Some times I can get it to work by changing the web.config file

<compilation debug="false" targetFramework="4.5" />

to

<compilation debug="true" targetFramework="4.5" />​​

but then you can't debug.  Also, just by modifying white space in my ascx file I can make the error occur.  I have submitted a formal support ticket.

0
Mitch
Top achievements
Rank 1
answered on 29 Sep 2015, 02:40 PM
I have spent some time with this.  Some times I can get it to work by changing the web.config file
<compilation debug="true" targetFramework="4.5" />

to

<compilation debug="false" targetFramework="4.5" />​​


but then you can't debug.  Also, just by modifying white space in my ascx file I can make the error occur.  I have submitted a formal support ticket.

0
Kostadin
Telerik team
answered on 30 Sep 2015, 10:06 AM
Hello Jeff,

Could you please try with SP2 of VS2013 and let me know whether the issue remains. Note that in VS2013 there is an issue with the page inspector which was fixed later.

Hello Mitch.

I checked the code that you have provided in the support ticket but I was unable to replicate it. Could you please provide more information about the version of VS and UI for ASP.NET you are using.

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
Jeff
Top achievements
Rank 1
answered on 30 Sep 2015, 10:41 PM

Hi Kostadin,
I was running VS Community 2013 Update 4 and I upgraded to Update 5 and re-ran the sample project I had created.   With update 5 in place, the pdf export worked.   I did run my test project before the update just to be sure that it failed to export as pdf.   So, it looks like update 5 addresses this issue somehow.    -- Jeff

 

0
Kostadin
Telerik team
answered on 05 Oct 2015, 11:04 AM
Hello Jeff,

I am glad the update works in your case. Keep in mind that we have other issues with the previous version of VS 2013, so it looks like a problem with the program.

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
Tags
Grid
Asked by
Mehmet
Top achievements
Rank 1
Answers by
Mehmet
Top achievements
Rank 1
Daniel
Telerik team
Brian Clark
Top achievements
Rank 1
Jeff
Top achievements
Rank 1
Mitch
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or