FlexReport for WPF | ComponentOne
In This Topic
    Export FlexReports
    In This Topic

    Instead of printing the report, you may want to export it into a file and distribute it to your clients or co-workers. To export a file in FlexReportDesigner, select Export option from the File menu and use the Export Report to File dialog box to specify the location, File name and Save as type.

    The FlexReportDesigner supports the following export formats:

    Format Description
    Paged HTML (*.html) Creates one HTML file for each page in the report. The HTML pages contain links that let the user navigate the report.
    Plain HTML (*.html) Creates a single HTML file with no drill-down functionality.
    PDF with non-embedded (linked) fonts (*.pdf) Creates a PDF file that can be viewed on any computer equipped with Adobe's Acrobat viewer or browser plug-ins.
    PDF/A  with embedded fonts (*.pdf) Creates a PDF file with embedded font information for extra portability.
    RTF (*.rtf) Creates an RTF file that can be opened by most popular word processors (for example, Microsoft Word, WordPad). It can be saved as Paged or Open XML document.
    Microsoft Excel 97 (*.xls) Creates an XLS file that can be opened by Microsoft Excel.
    Microsoft Excel Open XML (*.xlsx) Creates an XLS file that can be opened by Microsoft Excel 2007 and later.
    Open XML Word (*.docx) Creates a DOCX file that can be opened by Microsoft Word 2007 and later.
    Compressed Metafile (*.zip) Creates a compressed metafile file, of the type EmfOnly, EmfPlusOnly,and EmfPlusDual.
    TIFF (*.tiff), BMP, PNG, JPEG, GIF images Create image file of type TIFF (Tag Image File Format), BMP (Bitmap Images), PNG(Portable Network Graphic), JPEG or GIF.

    Render FlexReport using PdfFilter class

    FlexReport allows you to render a report to PDF format using PdfFilter class. The PdfFilter class renders the report into PDF streams or files.

    To render a FlexReport in PDF format, use the following code. This example uses sample created in FlexReport Quick Start.

    PdfFilter f = new PdfFilter();
    f.FileName = @"..\..\ProductsReport.pdf";
    rep.RenderToFilter(f);
    System.Diagnostics.Process.Start(f.OutputFiles[0]);
    

    You can also use the following properties of PdfFilter class:

    Properties Description
    EmbedFonts Used to embed font information in PDF document.
    PdfACompatible Used to generate PDF/A compatible document.
    PdfSecurityOptions Used to specify who can use the Pdf document and what actions are allowed on it.
    UseCompression Used for PDF document compression.
    UseOutlines Used to include an outline tree.

    Render FlexReport using HTMLFilter class

    FlexReport allows you to render a report to HTML format using HtmlFilter class. The HtmlFilter class renders the report into HTML streams or files.

    To render a FlexReport to HTML format, use the following code. This example uses sample created in FlexReport Quick Start.

    HtmlFilter f = new HtmlFilter();
    f.FileName = @"..\..\ProductsReport.html";
    rep.RenderToFilter(f);
    System.Diagnostics.Process.Start(f.OutputFiles[0]);
    

    Render FlexReport using Different Export Filters for Images

    FlexReport allows you to render a report to various image file formats, such as PNG, JPG, BMP, GIF, and TIFF. Each of these image file formats have an exclusive export filter for a particular format. PngFilter class can be used to render a report to PNG format. Similarly, JpegFilter class is used to render a report to JPEG format, GifFilter class is used to render a report to GIF format, BmpFilter class is used to render a report to BMP format, and TiffFilter class is used to render a report to TIFF format.

    To render a FlexReport in PNG format, use the following code. This example uses sample created in FlexReport Quick Start.

    PngFilter f = new PngFilter();
    f.FileName = @"..\..\ProductsReport.png";
    rep.RenderToFilter(f);
    System.Diagnostics.Process.Start(f.OutputFiles[0]);
    

    Export FlexReport using RTFFilter class

    FlexReport allows you to export a report to RTF format using RtfFilter class. The RtfFilter class exports the report into RTF streams or files.

    To export a FlexReport to RTF format, use the following code. The example uses sample created in FlexReport Quick Start.

    RtfFilter f = new RtfFilter();
    f.FileName = @"..\..\ProductsReport.rtf";
    rep.RenderToFilter(f);
    System.Diagnostics.Process.Start(f.OutputFiles[0]);
    

    You can also use the following properties of RtfFilter class:

    Properties Description
    OpenXML Used to export the file in OpenXML format.
    Paged Used to preserve the page layout of the original report.
    ShapesWord2007Compatible Used to indicate the Word 2007 shapes format compatibility in a report to be saved to DOCX format.

    Export Reports using ExportFilter Class

    As an alternative to using a specific format filter (for example, PdfFilter) for exporting a report to a particular format ( say, PDF format), FlexReport allows you to export a report to different formats using ExportFilter class. The ExportFilter class is an abstract base class for all exporter classes. An object of ExportFilter class is used to export a report to different formats. The ExportFilter class accesses the ExportProvider abstract class which describes supported export formats.

    In the following code, we have used the ExportFilter class that accesses the ExportProvider class to list all the export formats in a ComboBox, which are described in the ExportProvider class. To do so, a ComboBox control is added in the design view to show the list of available export formats and its name is set to cbxExportFormat.

    1. Add the reference to the C1.WPF.4.dll, C1.WPF.Document.4.dll, and C1.WPF.FlexReport.4.dll.
    2. Add the following namespaces in the code:
      using C1.WPF.Document.Export;
      using C1.WPF.FlexReport;
      using System.IO;
      
    3. Add the following code in the code view to create an instance of C1FlexReport:
      private C1FlexReport _report = new C1FlexReport();
      
    4. Add the following code beneath InitializeComponent() method in the interaction logic for XAML:
      // build list of supported export filters
      foreach (var e in _report.SupportedExportProviders)
      {
          cbxExportFormat.Items.Add(e.FormatName);
      }
      cbxExportFormat.SelectedIndex = 0;
      
    5. Add a Button control to the MainWindow for exporting a FlexReport to different formats using ExportFilter and ExportProvider class, use the following code:
      string[] reports = C1FlexReport.GetReportList(@"..\..\FlexCommonTasks_WPF.flxr");
      ExportProvider ep = _report.SupportedExportProviders[cbxExportFormat.SelectedIndex];
      ExportFilter ef = ep.NewExporter() as ExportFilter;
      if (!Directory.Exists(@"..\..\ExportResults"))
          Directory.CreateDirectory(@"..\..\ExportResults");
      
      foreach (string reportName in reports)
      {
          using (C1FlexReport rep = new C1FlexReport())
          {
              rep.Load(@"..\..\FlexCommonTasks_WPF.flxr", reportName);
              ef.FileName = string.Format(@"..\..\ExportResults\{0}.{1}",
              reportName, ep.DefaultExtension);
              try
              {
                  rep.RenderToFilter(ef);
              }
              catch (Exception ex)
              {
                  MessageBox.Show(string.Format
                  ("Exception while export [{0}] report:\r\n{1}", reportName, ex.Message),
                  "Error", MessageBoxButton.OK, MessageBoxImage.Error);
              }
          }
      }
      

    You can also use the following properties available in ExportFilter class:

    Properties Description
    FileName Used to name the output file.
    MultiFile Used to indicate whether multiple files were generated during export.
    OutputFiles Used to show the list of files which were generated by the call to Export(string).
    PageSettings Used to specify the settings that apply to a page.
    Preview Used to indicate whether the exported document should be opened after exporting it to a disk file.
    Range Used to represent the range of pages to be exported.
    ShowOptions Used to indicate whether the options dialog should be shown before exporting the document.
    Stream Used to specify the output stream.
    UseZipForMultipleFiles Used to indicate whether the output (stream or file) should be a zipped archive with the generated files, if multiple files are created during export.