![]() |
Desktop Development »
Printing »
General
Intermediate
DaReport PrintDocument - a printing utility for .NETBy Predrag DukanacA printing utility for .NET. |
C#, Windows, .NET 1.1VS.NET2003, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

This component helps you generate simple but useful reports for printing in .NET. The idea is to generate XML-based templates, and then to call them from your program, and eventually to fill them with the data required. This is appropriate for generating small and simple printing documents.
The basic class of this project is DaPrintDocument. It inherits from the standard .NET class PrintDocument. Therefore, you can use it pretty much the same way as the PrintDocument class.
This class simply paints attached drawing objects within its PrintPage() method. For simplicity, there are only four types of drawing objects supported: TextField (simple formatted text), PictureBox (images), ChartBox (simple charts), and StyledTable (table with static or dynamically loaded data).
DaPrintDocument makes use of template files written in XML syntax. Those provide all static information relevant for printing a page.
You can write template files in any text editor, or alternatively, use the DaReport Designer (beta) provided in the distribution (it's a separate application: DaReportDesigner.exe).
The brief overview of the XML structure:
<daReport>
<parameters>
<parameter name="parameter1_name" />
<parameter name="parameter2_name" />
</parameters>
<content>
<!-- Static objects are evaluated once per report -->
<staticContent>
<!-- The list of static objects goes here.
Check in reportStatic.xml (in download package). -->
</staticContent>
<!-- Dynamic objects are evaluated once per page of report
(like data table segment or page number) -->
<dynamicContent>
<!-- The list of dynamic objects goes here.
Check in reportDynamic.xml (in download package). -->
</dynamicContent>
</content>
</daReport>
Once again, the preferred way for XML template file generation is by using the DaReport Designer (beta) provided in the distribution.
First, add a reference to the daReport.dll file (provided in the distribution) to your project. If you feel like it, you can also put this component in your controls toolbar.
Second, add an instance of DaPrintDocument to your module (form); if you have previously attached it in your controls toolbar, simply drag it to your form:
private daReport.DaPrintDocument daPrintDocument =
new daReport.DaPrintDocument();
At the point where you wish to print some report, set the template file and fill in the parameters (if any):
// set .xml file for printing
daPrintDocument.setXML("reportStatic.xml");
// fill in declared parameters (if any)
// (parameter names are case sensitive)
Hashtable parameters = new Hashtable();
parameters.Add("author","Predrag Dukanac");
daPrintDocument.SetParameters(parameters);
DATA tag). The DataSource property for these tables is not set. No specific action is required in code for these tables to print correctly (everything is done in the .xml file).
DataSource property is set, and must correspond to the DataTable.Name property in your code. Do it like this: // myTable is DataTable previously filled from database
// (using DataAdapter.Fill method, for instance)
DataTable printTable = myTable.Copy();
printTable.Name = "printTable";
// this is the DataSource attribute of my table in XML file
// attach DataTable to printing document
daPrintDocument.AddData(printTable);
// now you're ready for printTake a look at reportStatic.xml, reportDynamic.xml, reportCharts.xml, and the ReportTest project (all in the download package) for a deeper insight.
The DaReport print engine has turned into a commercial product - Stampa Reports System�. A Stampa Reports demo is available for download here. Stampa designer features backward compatibility with daReport in design mode. The Stampa printing engine can be used free of charge.
The DaReport project at this address is still an open-source project by all means.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 20 Apr 2006 Editor: Smitha Vijayan |
Copyright 2005 by Predrag Dukanac Everything else Copyright © CodeProject, 1999-2009 Web20 | Advertise on the Code Project |