Click here to Skip to main content
Licence 
First Posted 6 Apr 2005
Views 205,272
Downloads 2,815
Bookmarked 133 times

DaReport PrintDocument - a printing utility for .NET

By Predrag Dukanac | 20 Apr 2006
A printing utility for .NET.
3 votes, 5.6%
1

2
4 votes, 7.4%
3
6 votes, 11.1%
4
41 votes, 75.9%
5
4.72/5 - 54 votes
3 removed
μ 4.48, σa 1.84 [?]

Screenshot

Introduction

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.

Background

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).

Template file overview

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.

Using the code

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);

Using tables

  • Static tables: static tables have data defined in an XML template file (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).
  • Dynamic tables: dynamic tables present data calculated in your program (like database reports). The 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 print

Take a look at reportStatic.xml, reportDynamic.xml, reportCharts.xml, and the ReportTest project (all in the download package) for a deeper insight.

Latest update

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Predrag Dukanac

Web Developer

Yugoslavia Yugoslavia

Member
Working at Mihajlo Pupin Institute, Belgrade, Serbia.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionThanks a lot for this nice utility. PinmemberSunil Apte22:02 13 Oct '11  
Questionparameter in static table PinmemberMCY2:43 5 Dec '10  
GeneralMy vote of 5 PinmemberAnirudha_baba0:22 5 Jul '10  
QuestionMem usage problem!!!!!!!!!!! [Report design] Pinmemberutehn0:37 9 Jan '09  
QuestionUSE FREE PinmemberMember 32338166:00 31 Dec '08  
Generalprinters on c#.net Pinmemberbalu123458:41 30 Jul '08  
QuestionHow can I draw text or table only at the end of last page? PinmemberJM ® - DE CASTRO12:58 11 Jun '08  
GeneralVery nice PinmemberHugo Faselo12:16 13 Dec '07  
QuestionRe: Very nice Pinmemberdimazoid9:34 16 Oct '08  
Hello, I have the same issue...If you have already figured it out, could please let me know how, or at least point me in the right direction. Thanks a banch!
 
-Dave
QuestionMonday's date at the top of the report. Pinmemberdamonhogan6:48 16 Nov '07  
Questionmultple page in staticContent [modified] Pinmemberabhishek nath21:28 5 Feb '07  
AnswerRe: multple page in staticContent Pinmembernegleden15:46 25 May '09  
QuestionWhat royalties do i need to add into the help file? PinmemberNarutoFan#120:50 31 Oct '06  
AnswerRe: What royalties do i need to add into the help file? PinmemberPredrag Dukanac0:36 1 Nov '06  
GeneralRe: What royalties do i need to add into the help file? PinmemberNarutoFan#14:58 1 Nov '06  
GeneralHow to add image path? PinmemberNarutoFan#123:41 28 Feb '07  
QuestionReportDesigner Pinmemberbszom12:38 13 Oct '06  
QuestionFromPage/ToPage question Pinmemberbp00311:13 21 Jul '06  
GeneralFormatMask question Pinmembercalvin_cch16:40 3 Jun '06  
QuestionHow to print page numbers? Pinmembersteve_dee5:10 25 May '06  
AnswerRe: How to print page numbers? PinmemberPredrag Dukanac5:22 25 May '06  
GeneralRe: How to print page numbers? Pinmembersteve_dee5:37 25 May '06  
AnswerRe: How to print page numbers? PinmemberPredrag Dukanac21:23 25 May '06  
Generalnice job Pinmemberclody0:48 24 May '06  
QuestionMargin Pinmembercalvin_cch9:29 23 May '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120210.1 | Last Updated 20 Apr 2006
Article Copyright 2005 by Predrag Dukanac
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid