Report Document is XML file containing information about printing objects. Default file extension is .xml, yet, this is not obligatory. Report document uses it's own (generic) XML namespace, and strictly conforms to XML standard.
Being a XML document, Report Document is tree-like based. The simplest way to describe it is : document contains sections, and sections contain elements (printing objects). Simply put, section is one or more pages. More technicly, section is design-mode entity that produces pages during document printing. Each element (text, table, picture) belongs to exactly one section. The relationship between sections and pages is described in more details in chapter Sections and Pages.
Reports become dynamic when using report parameters. Parameters are placeholders for string values, waiting to be initialized from your program. More on parameters in chapter Parameters.
Report elements are actual visible objects on report pages. There are 13 types of report elements: TextField, PictureBox,
StyledTable, ChartBox, Timeline, Line, Box, Elipse, Barcode, Map, Scatter, RichText and UserPaint, each having different inherent data type and display behaviour. Read more in Report Elements.
Document root folder is the folder where .xml Report Document resides. This folder is always resolved while loading document,
either for printing or design purpose. All relative paths are resolved with respect to this folder. The reason for this kind of resolving
is fact that reports are usualy part of another application (generaly, with unknown path at the design time). So, to keep the reporting
subsystem consistent, it is best practice to group report with it's resources (images) within one directory (or one directory with subdirectories).
The XML structure on a document level follows the next pattern :
Note :
The basic class in Stampa package is ReportDocument. It inherits from the standard .NET class PrintDocument.
Therefore, you can use it pretty much the same way as PrintDocument class.
First, add a reference to Stampa.dll file (provided in the distribution) to your project.
If you feel like it, you can also put this component in your Control Toolbar.
Second, add an instance of Stampa.ReportDocument to your module (form); if you have previously attached it in your control toolbar, simply drag it to your form:
At the point where you wish to print some report, set the template file and fill in the parameters (if any):
To use ReportDocument in ASP.NET, create an instance of document in your ASP.NET page:
Second step is to set document content:
Last step is to serialize your report to PDF stream and send the response back to web user:
In order to get HTML report output in your ASP.NET environment, you sholud use HttpReportHandler utility class.
Use HttpReportHandler.Process(HttpContext context, Stampa.ReportDocument report, string reportName) method to obtain desired output.
In order to use custom printing sizes, you have to set PaperType property to Custom. In that scenario customWidth and customHeight attributes
are used to determine paper size. The measure unit is determined by CustomUnit property. Valid values are Pixels, Inches and Millimeters.
Custom paper size is limited at (4500,4500) Pixels, (45,45) Inches and (1100,1100) Millimeters.
Since version 1.12, the report engine has the ability to preload database data for you before report generation. Reports are extended with
database connection and the list of queries that need to be executed against the database in order to retreive neccessarry report data. Preloding
data feature is enabled by setting ReportDocument.StartInfo.PreloadData property to True (by default, this is set to False, due to the backward compatibility).
Read more about establishing database connection and specifying report queries.
Document Root Folder
XML file structure
<stampa name="documentName" papersize="A4" layout="Portrait" customUnit="Inches" customWidth="10" customHeight="12">
<!-- Margins setup (optional) -->
<margins left="50" top="50" right="50" bottom="50" />
<!-- Report startup options -->
<startInfo>
<preloadData value="True" />
<ignorePreloadExceptions value="True" />
</startInfo>
<!-- Report database connection. Meaningfull only if PreloadData is set to True. -->
<connection>
<name value="dbConnection" />
<assembly value="System.Data" />
<type value="System.Data.Odbc.OdbcConnection" />
<connectionString value="Driver={Microsoft Access driver (*.mdb)}; Dbq=e:\demo.mdb;" />
</connection>
<!-- List of documents parameters (optional if no parameters defined) -->
<parameters>
<parameter name="myParameter" defaultValue="10" />
...
<parameters>
<!-- List of report queries -->
<queries>
<query dataSource="myTable" selectCommand="select * from customers where id>$P{id}" />
</queries>
<sections>
<!-- At least one section must be present -->
<section name="Section1">
<flow value="4,0,3" />
<content>
<!-- The list of section objects definitions (text-fields, tables, pictures) goes here. -->
</content>
</section>
...
</sections>
</stampa>
Using ReportDocument in .NET
private Stampa.ReportDocument document = new Stampa.ReportDocument();
// set .xml file for printing
document.setXML("report.xml");
// fill in declared parameters (if any)
// (parameter names are case sensitive)
Hashtable parameters = new Hashtable();
parameters.Add("author","John Smith");
document.SetParameters(parameters);
// finally, choose what to do with your report :
// A. show print preview dialog
PrintPreviewDialog printPreview = new PrintPreviewDialog();
printPreview.Document = document;
printPreview.WindowState = FormWindowState.Maximized;
printPreview.ShowDialog();
// B. show print dialog
// PrintDialog printDialog = new PrintDialog();
// printDialog.Document = document;
// if (DialogResult.OK == printDialog.ShowDialog())
// document.Print();
// C. immediate print
// document.Print();
// D. PDF file serialization
// document.SerializeToPdfFile("myFile.pdf");
Using ReportDocument in ASP.NET (PDF output)
private Stampa.ReportDocument document = new Stampa.ReportDocument();
// set full path of the .xml template
string xmlPath = this.MapPath(this.ResolveUrl("reportStatic.xml"));
document.setXML(xmlPath);
// do some processing here, if necessary
// add parameters, dynamic tables, pictures
byte[] response = document.SerializeToPdfStream();
Response.ContentType = "application/pdf";
Response.OutputStreamWrite(content, 0, content.Length);
Response.End();
Using ReportDocument in ASP.NET (HTML output)
using System;
using System.Web;
using System.Web.SessionState;
using Stampa;
using System.Collections;
using System.Drawing;
public class Handler : IHttpHandler, IRequiresSessionState
{
HttpReportHandler handler = new HttpReportHandler();
public void ProcessRequest(HttpContext context)
{
string reportName = "myReport";
if (context.Request.Params["stampaImage"] != null)
{
handler.Process(context, null, reportName);
}
else
{
Stampa.ReportDocument report = new ReportDocument();
report.setXML(context.Request.MapPath("testingReport.xml"));
handler.Process(context, report, reportName);
}
}
}
Setting custom report size
Preloading database data