Print Search Rate
    
   06-25-2008, 3:30 PM
HOWTO: Use the PrintDocumentRenderingExtension to Print a Report
Attachment: PrintingAPI.zip

Introduction

The Data Dynamics Reports PrintDocumentRenderingExtension allows developers to use standard .NET Printing objects to programmatically print reports without using the ReportPreview control.

Programmatically rendering a report to any rendering extension requires the report definition to be loaded into a ReportRuntime object. Also, most rendering extensions require a StreamProvider and a NameValueCollection can be supplied to the Render method which specifies the rendering extension specific settings. The PrintDocumentRenderingExtension renders the report to a System.Drawing.Printing.PrintDocument in memory, therefore, a StreamProvider is not necessary.

The following references are required by the sample code:

  • DataDynamics.Reports
  • DataDynamics.Reports.Extensibility
  • DataDynamics.Reports.Rendering.Graphics

Objects from the following namespaces are used:

  • System.IO
  • System.Drawing.Printing
  • System.Collections.Specialized
  • DataDynamics.Reports
  • DataDynamics.Reports.Extensibility.Rendering
  • DataDynamics.Reports.Rendering.Graphics

PrintDocumentRenderingExtension Sample Rendering Code (C#.NET)

First, the report needs to be loaded into a ReportRuntime object. A Stream or FileInfo object can be used to load the RDL into the ReportDefinition object, which is then passed into the ReportRuntime's constructor.

// Load report file into a ReportRuntime object
FileInfo reportFile = new FileInfo(@"C:\Report.rdlx");
ReportDefinition rdl = new ReportDefinition(reportFile);
ReportRuntime runtime = new ReportRuntime(rdl);

Next, use the following code to create and configure the PrintDocumentRenderingExtension. Also, the default settings for the rendering extension are provided by calling the ISettings.GetSettings() method.

// Set up rendering extension
PrintDocumentRenderingExtension renderer = new PrintDocumentRenderingExtension();
ISettings supportedSettings = renderer.GetSupportedSettings();
NameValueCollection settings = supportedSettings.GetSettings();

// Set the printer name (the printer name must match a name 
// in the PrinterSettings.InstalledPrinters StringCollection)
settings["PrinterName"] = "NameOfPrinter";

// Ensure the proper page orientation
if (rdl.Report.PageWidth > rdl.Report.PageHeight)
    settings["Orientation"] = "Landscape";

Now the report is ready to be rendered. Once rendering is complete, the PrintDocument's Print method can be called.

// Render the report
runtime.Render(renderer, null, settings);

// The default PrintController is a PrintControllerWithStatusDialog,
// to avoid displaying the status use the StandardPrintController.
renderer.Document.PrintController = new StandardPrintController();

// Set the printer name for the PrintDocument, then print
renderer.Document.PrinterSettings.PrinterName = settings["PrinterName"];
renderer.Document.Print();

See the attached sample for a runnable project demonstrating the printing API in Data Dynamics Reports.



Applies To:
Data Dynamics Reports 1.0
GrapeCity » Knowledge Base » KnowledgeBase f... » HOWTO: Use the PrintDocumentRenderingExtension to Print a Report
Privacy Policy | Copyright © 1997-2012 — GrapeCity, inc.
All trademarks mentioned are the property of their respective owners.