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

Add HTML table to Export to PDF

2 Answers 453 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 21 May 2013, 05:34 PM

I have a RadGrid on an aspx page with a HTML table above it with some customer information.  I am able to export the HTML table and prepend it to the export by using a memory stream.  But, I cannot get it to work when exporting to PDF. 

protected void RadGrid1_GridExporting(object source, GridExportingArgs e)
  {
  StringBuilder customHTML = new StringBuilder();       
  if (e.ExportType == ExportType.Excel)
    
   customHTML.Append("<table style='font-size: 11px; font-family:Verdana;width:500px;' >");
   customHTML.Append("<tr><td><strong>Volunteer:</strong></td><td style=text-align:left;>" + _volunteer + "</td></tr>");
   customHTML.Append("</table>");
 
  e.ExportOutput = e.ExportOutput.Replace("<body>", String.Format("<body>{0}", customHTML));
  MemoryStream gridMemoryStream = new MemoryStream(new ASCIIEncoding().GetBytes(e.ExportOutput));
  gridMemoryStream.Close();
    }
 
  if (e.ExportType == ExportType.Pdf)
  {
    // How do I add HTML to the PDF Export?  The Excel Export doesn't work
     }

 

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 22 May 2013, 05:34 AM
Hi,

Rules that should be followed when exporting HTML tables to PDF:
  • The table should define <colgroup> and <col> elements

  • The number of col elements should be equal to the number of the columns in the table body

  • Width in pixels (or another absolute units) should be set to the table.


Please examine the Exporting HTML tables section in the following documentation:
PDF Export

Thanks,
Princy.
0
Mike
Top achievements
Rank 1
answered on 24 May 2013, 02:59 PM
Princy,

I GOT IT!!!

You have to be real careful about the font and make sure it's one that acrobat recognized.  I simply replaced all the settings of

Arial Unicode MS with Courier and it works!

 

Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mike
Top achievements
Rank 1
Share this question
or