MindFusion.Wpf Pack Programmer's Guide
Exporting Reports

Exporting to image

Reports can be exported to an image by rendering them using an ImageRenderTarget object. Before the report can be rendered, it needs to be processed and laid out. To learn more about these operations, check Running, Laying Out and Rendering topic. Once the report is rendered in an ImageRenderTarget object, it can be saved in a variety of image formats by calling the Save of the ImageRenderTarget. All standard image formats are supported, including BMP, GIF, JPEG, TIFF, PNG and WMP.

The following code illustrates how to export an existing report as a multi-frame TIFF. The example assumes that the report is already processed by a call to its Run method.

C#  Copy Code

// Layout the report
ReportLayout layout = report.Layout(
    new Size(8.5 * 96, 11 * 96), new Thickness(0.5 * 96),
    MindFusion.Reporting.PageOrientation.Portrait);

// Create and setup the rendering target
ImageRenderTarget renderTarget = new ImageRenderTarget()
{
    PageBackground = Brushes.White,
    PageBorderBrush = Brushes.Black,
    IsMultipage = true,
};

// Perform the rendering
layout.RenderAllPages(renderTarget);

renderTarget.Save("myreport.tif", new TiffBitmapEncoder());

Visual Basic  Copy Code

' Layout the report
Dim layout As ReportLayout = report.Layout( _
    New Size(8.5 * 96, 11 * 96), New Thickness(0.5 * 96), _
    MindFusion.Reporting.PageOrientation.Portrait)

' Create and setup the rendering target
Dim renderTarget As New ImageRenderTarget() With _
{ _
    .PageBackground = Brushes.White, _
    .PageBorderBrush = Brushes.Black, _
    .IsMultipage = True _
}

' Perform the rendering
layout.RenderAllPages(renderTarget)

renderTarget.Save("myreport.tif", New TiffBitmapEncoder())

ImageRenderTarget provides several useful properties. The IsMultipage property specifies whether the report pages should be rendered to separate bitmap frames or whether all pages should be rendered in a single frame one below the other. Many image formats do not support multiple frames. If IsMultipage is true and the target format does not support multiple frames, only the first page will be exported.

The Dpi property can be used to specify custom DPI for the output image. If this property is set to 0 (the default value), the output image will have the DPI of the screen.

The PageBackground and PageBorderBrush properties specify the appearance for pages, which do not explicitly specify Background and BorderBrush. If a page does not have background and PageBackground is not set, the page will be rendered as either transparent or using the default background color of the target image format, usually black.

Exporting as PDF

Reports can be easily exported to PDF by using the PdfExporter class. The reports being exported must have been previously processed by a call to their Run method but do not necessarily need to be laid out. The PDF exporter performs internal layouting according to the specified settings.

To export a report to PDF, instantiate from the PdfExporter class and call the Export method. This method takes two arguments - the report to be exported and the file name of the output PDF. Several options can be specified on the PdfExporter object before calling Export, such as the page size and orientation.

 Note

The PdfExporter class is located in the MindFusion.Reporting.Wpf.PdfExport.dll assembly. In order to use this class, you have to add a reference to this assembly to your project. In addition, the MindFusion.Reporting.Wpf.PdfExport.dll is dependent on the MindFusion.Common.dll and MindFusion.Pdf.dll assemblies, so you will have to deploy those two as well (although it might not be necessary to reference them directly in your project).

Several enumerations used by the PdfExporter class, such as PageSize and PageOrientation are located in MindFusion.Pdf.dll.

The following code illustrates how to export an existing report (identified by the report variable) to a PDF:

C#  Copy Code

PdfExporter exporter = new PdfExporter();
exporter.PageSize = MindFusion.Pdf.PageSize.A3;
exporter.PageOrientation = MindFusion.Pdf.PageOrientation.Landscape;
exporter.Export(report, "report.pdf");

Visual Basic  Copy Code

Dim exporter As New PdfExporter()
exporter.PageSize = MindFusion.Pdf.PageSize.A3
exporter.PageOrientation = MindFusion.Pdf.PageOrientation.Landscape
exporter.Export(report, "report.pdf")

Exporting as HTML/MHTML

Exporting to HTML/MHTML is very similar to exporting to PDF - you create an instance of the HtmlExporter/MhtmlExporter class, set the desired options and call the Export method. As is usual, the exported report must have been previously run by a call to its Run method. Several options can be specified on the exporter including page size and margins.

 Note

The HtmlExporter and MhtmlExporter classes are located in the MindFusion.Reporting.Wpf.HtmlExport.dll assembly. In order to use these classes, you have to add a reference to this assembly to your project.

During the export to HTML all images are exported to a special folder, as specified by the imageFolder argument of the Export method. Various other report elements can be exported as image as well. Prime example are the elements filled with gradient brushes and CustomReportItem elements.

The following code illustrates how to export an existing report to an HTML:

C#  Copy Code

HtmlExporter exporter = new HtmlExporter();
exporter.PageSize = new Size(11 * 96, 17 * 96);
exporter.Export(report, "report.html", "");

Visual Basic  Copy Code

Dim exporter As New HtmlExporter()
exporter.PageSize = New Size(11 * 96, 17 * 96)
exporter.Export(report, "report.html", "");

Exporting as XLSX

Similarly to the other exporters, create an instance of the ExcelExporter class, set the desired options and call the Export method. As is usual, the exported report must have been previously run by a call to its Run method. Several options can be specified on the ExcelExporter including page size and margins.

 Note

The ExcelExporter class is located in the MindFusion.Reporting.Wpf.ExcelExport.dll assembly. In order to use this class, you have to add a reference to this assembly to your project.

The following code illustrates how to export an existing report to an XLSX:

C#  Copy Code

ExcelExporter exporter = new ExcelExporter();
exporter.Export(report, "report.xlsx");

VB.NET  Copy Code

Dim exporter As New ExcelExporter()
exporter.Export(report, "report.xlsx")