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

Export to PDF - How to handle <BR> in raw HTML

6 Answers 370 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kellie
Top achievements
Rank 1
Kellie asked on 09 Dec 2010, 06:11 PM
Re: RadGrid Export to Pdf

My PDF won't open in Adobe Reader when I have <BR> present in my HTML (says the file is damaged)

How (and which event) should this be handled in?

Here is the code that I extracted from e.RawHTML in the PdfExporting event. When I exclude the records with the <BR> the PDF forms correctly.

<table cellspacing="0" border="0" id="RadGridSearchResults_ctl00" style="width:100%;table-layout:auto;empty-cells:show;">
    <colgroup>
        <col style="width:75px" />
        <col style="width:75px" />
        <col style="width:150px" />
        <col style="width:75px" />
        <col style="width:100px" />
        <col  />
    </colgroup>
<thead>
        <tr>
            <th scope="col">Title Nbr</th><th scope="col">Reg Date</th><th scope="col">Type</th><th scope="col">Linc Nbr</th><th scope="col">Short Legal</th><th scope="col">Owner</th>
        </tr>
    </thead><tbody>
    <tr>
        <td>32T43      .</td><td>
                            1925-02-06
                        </td><td>
                            CONVERSION
                        </td><td>
                            0023045991
                        </td><td>
                            4;6;13;5;NE
                        </td><td>
                            THE TOWN OF SOMEWHERE.
                        </td>
    </tr><tr>
        <td>48E12      .</td><td>
                            1933-09-22
                        </td><td>
                            CONVERSION
                        </td><td>
                            0023045975<br>0023045983
                        </td><td>
                            4;6;13;5;NE<br>4;6;13;5;SW
                        </td><td>
                            THE TOWN OF SOMEWHERE.
                        </td>
    </tr><tr>
        <td>791042549</td><td>
                            1979-03-21
                        </td><td>
                            CONVERSION
                        </td><td>
                            0023046774
                        </td><td>
                            4;6;13;4;SW
                        </td><td>
                            THE TOWN OF SOMEWHERE.
                        </td>
    </tr><tr>
        <td>891015298B .</td><td>
                            1989-01-26
                        </td><td>
                            CONVERSION
                        </td><td>
                            0023044720
                        </td><td>
                            4;6;13;5;NW
                        </td><td>
                            THE TOWN OF SOMEWHERE.
                        </td>
    </tr><tr>
        <td>901047011</td><td>
                            1990-02-20
                        </td><td>
                            CONVERSION
                        </td><td>
                            0023045967
                        </td><td>
                            4;6;13;5;NE
                        </td><td>
                            THE TOWN OF SOMEWHERE.
                        </td>
    </tr>
    </tbody>
  
</table>

Here's my Export to PDF settings:
protected void RadGridSearchResults_ItemCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExportToExcelCommandName || e.CommandName == RadGrid.ExportToPdfCommandName 
        || e.CommandName == RadGrid.ExportToCsvCommandName || e.CommandName == RadGrid.ExportToWordCommandName)
    {
        RadGridSearchResults.ExportSettings.FileName = "Titles_Summary_Export_" + DateTime.Now.ToShortDateString();
        RadGridSearchResults.PageSize = RadGridSearchResults.MasterTableView.VirtualItemCount;
        RadGridSearchResults.ExportSettings.IgnorePaging = true;
  
        if (e.CommandName == RadGrid.ExportToPdfCommandName)
        {
            isPdfExport = true;
            RadGridSearchResults.ClientSettings.Scrolling.UseStaticHeaders = false;
            RadGridSearchResults.ClientSettings.Scrolling.AllowScroll = false;
            RadGridSearchResults.ExportSettings.ExportOnlyData = true;
            RadGridSearchResults.MasterTableView.ExportToPdf();
        }
  
    }
}

6 Answers, 1 is accepted

Sort by
0
Accepted
Cori
Top achievements
Rank 2
answered on 09 Dec 2010, 07:59 PM
Hello Kellie,

If you handle the OnPdfExporting event, you can do this to remove all the <br> tags:

e.RawHTML = e.RawHTML.Replace("<br>",Environment.NewLine);

It just replaces the breaks with a normal line break.

I hope that helps.

0
Kellie
Top achievements
Rank 1
answered on 09 Dec 2010, 09:20 PM
Thanks so much Cori, you are a Superstar.
Works perfectly and my PDF now creates successfully!
0
Daniel
Telerik team
answered on 09 Dec 2010, 10:38 PM
Hello Kellie,

Please note that the PDF export requires strict XHTML-compliant code. This means that:
<br> is INVALID
<BR> is INVALID
<BR/> is INVALID

The only valid way to include line break is  <br/>

Regards,
Daniel
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
bharath
Top achievements
Rank 1
answered on 03 Oct 2013, 02:41 PM


i have some special charecters in my html code.when iam trying to export to pdf it thows some parser error saying XHTML error.
when iam changing rawhtml in radgridexporting event total html table is exporting in pdf.(pdf file have html code), but the original data is not 
exported.

with regards
Bharath
0
bharath
Top achievements
Rank 1
answered on 03 Oct 2013, 02:45 PM


i have some special charecters in my html code.when iam trying to export to pdf it thows some parser error saying XHTML error.
when iam changing rawhtml in radgridexporting event total html table is exporting in pdf.(pdf file have html code), but the original data is not 
exported.

with regards
Bharath
0
Daniel
Telerik team
answered on 08 Oct 2013, 08:38 AM
Hello Bharath,

This simply means that your code is not XHTML compliant. I would recommend that you use html entity codes instead of inserting these special characters directly.
&lt; and &gt; instead of < and >

RadGrid PDF Export documentation

Regards,
Daniel
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Kellie
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Kellie
Top achievements
Rank 1
Daniel
Telerik team
bharath
Top achievements
Rank 1
Share this question
or