Hi:
I have an ASP.NET application that uses tabs and grids to display data to the end user, and they want the ability to click a button and have all the data on the web page generated to a PDF file. There are some images, some data in grids, and some text in text boxes.
Is it possible to build a report step-by-step from the data on the page, and then pass that report to the Export method to generate the PDF? So for example something like:
Report report1 = new Report();
report1.addImage( image):
table table1 = new table();
for (int i=0; i<radGrid.Rows.Count; i++)
{
For each row of data, add a row to the table
}
report1.add(table);
And so on until all the data is added to a report, and then use
ExportToPdf(report1)
Is this possible and/or is there another way to send all the data from the ASPX page to a PDF using the component?
Here is some code I used to try this, and I did get a PDF file, but it was empty:
void ExportToPDF(Telerik.Reporting.Report reportToExport)
{
ReportProcessor reportProcessor = new ReportProcessor();
RenderingResult result = reportProcessor.RenderReport("PDF", reportToExport, null);
string fileName = result.DocumentName + ".pdf";
Response.Clear();
Response.ContentType = result.MimeType;
Response.Cache.SetCacheability(HttpCacheability.Private);
Response.Expires = -1;
Response.Buffer = true;
Response.AddHeader("Content-Disposition",
string.Format("{0};FileName=\"{1}\"",
"attachment",
fileName));
//Response.Write("test");
Response.BinaryWrite(result.DocumentBytes);
Response.End();
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
Telerik.Reporting.Report report1 = new Telerik.Reporting.Report();
DataTable dt = new DataTable();
DataColumn column1 = new DataColumn();
column1.ColumnName = "1";
column1.ReadOnly = true;
dt.Columns.Add(column1);
DataColumn column2 = new DataColumn();
column2.ColumnName = "2";
column2.ReadOnly = true;
dt.Columns.Add(column2);
for (int i = 0; i < 25; i++)
{
DataRow theRow = dt.NewRow();
theRow["1"] = i.ToString();
int z = i + 5;
theRow["2"] = z.ToString();
dt.Rows.Add(theRow);
}
report1.DataSource = dt;
ExportToPDF(report1);
}
catch (Exception ex)
{
txtMessage.Text += "Error: " + ex.ToString();
}
}