Question

The company I'm with is likely to obtain an ActiveReports 7 license. There's a new project requirement that several webgrids (not actually webgrids, but more like html rendered with zurb) need to be converted into pdfs. At one point in the code behind they're effectively datasets or can be created into such. Is there a way to shuttle the data from the datasets into active reports, then render it out as a PDF. I'd like to keep the report as generic as possible, and thus have one active report for all the datatables, so doing using active reports as its usually done is kind of out of the question.

The only thing I can think of at the moment is a single textbox in the group header into which I could concatenate all the headers, and a single textbox in the details into which I could throw all the data for each row. The problem here is that I'd run into many formatting issues as nothing would line up properly - as tab delimiting would solve nothing here. I could have multiple textboxes with various spacing, but then it would eventually devolve into a different report for each dataset. Is it possible to apply some sort of markup so that I could keep the spacing of columns as I feed the data in. Do active reports richtextboxes honor html markup? Or is there another solution altogether?

I'd use Itextsharp, but its not free for commercial products.

Thanks, Sam

Was it helpful?

Solution

You can dynamically build a report that will output a simple table based on a specified DataSet, well actually a System.Data.DataTable. Basically for each column in the DataTable, add a textbox to the header to hold the name of the column and add another textbox to the Detail section to hold the value.

For the textbox in the detail section set its DataField property to the name of the column. With the binding in place, you can set the report's DataSource property to the DataTable and then run the report and export it to PDF.

The following code is a basic example:

var left = 0f;
var width = 1f;
var height = .25f;
var space = .25f;

var rpt = new SectionReport();
rpt.Sections.Add(SectionType.ReportHeader, "rh").Height = height;
rpt.Sections.Add(SectionType.Detail, "detail").Height = height;
rpt.Sections.Add(SectionType.ReportFooter, "rf").Height = height;

foreach (System.Data.DataColumn col in dataTable.Columns)
{
    var txt = new TextBox { Location = new PointF(left, 0), Size = new SizeF(width, height) };
    txt.Text = col.ColumnName;
    rpt.Sections["rh"].Controls.Add(txt);

    txt = new TextBox { Location = new PointF(left, 0), Size = new SizeF(width, height) };
    txt.DataField = col.ColumnName;
    rpt.Sections["detail"].Controls.Add(txt);
    left += width + space;
}

rpt.DataSource = dataTable;
rpt.Run();
var pdf = new PdfExport();
pdf.Export(rpt.Document, @"c:\Users\scott\downloads\test.pdf");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top