Skip to content

Export Without GUI

Peter Gill edited this page Jun 8, 2026 · 3 revisions

This page covers server-side report export: loading a report, running its data query, and writing output to a file or memory stream.

For the full list of supported output types see Output Formats. For streaming output to an HTTP response without writing to disk see Streaming PDF — ASP.NET Core.

Export to PDF

This requires the following nuget packages.

dotnet add package Majorsilence.Reporting.RdlEngine
dotnet add package Majorsilence.Reporting.RdlCri

# or

dotnet add package Majorsilence.Reporting.RdlEngine.SkiaSharp
dotnet add package Majorsilence.Reporting.RdlCri.SkiaSharp

Reads an RDL file, parses it, runs the data query, and exports to PDF.

using System;
using Majorsilence.Reporting.Rdl;

namespace NoGuiExample
{
    class Program
    {
        static async Task Main(string[] args)
        {
            // One time per app instance
            RdlEngineConfig.RdlEngineConfigInit();

            var rpt = await GetReport(new Uri(@"C:\The\Report\Directory\SimpleTest1.rdl"));
            await SaveReport(@"C:\The\Report\Directory\simpletest1.pdf", rpt);
        }
        private static async Task SaveReport(string savePath, Report rpt)
        {
            await rpt.RunGetData(null);
            var sg = new Majorsilence.Reporting.Rdl.OneFileStreamGen(savePath, true);
            await rpt.RunRender(sg,  OutputPresentationType.PDF);
        }

        private static async Task<Report> GetReport(Uri sourcefile)
        {
            var reportSource = await System.IO.File.ReadAllTextAsync(sourcefile.AbsolutePath);
            var rdlp = new RDLParser(reportSource);
            var r = await rdlp.Parse();

            if (r.ErrorMaxSeverity > 0)
            {
                foreach (string emsg in r.ErrorItems)
                {
                    Console.WriteLine(emsg);
                }

                int severity = r.ErrorMaxSeverity;
                r.ErrorReset();
                if (severity > 4)
                {
                    r = null; // don't return when severe errors
                }
            }

            return r;
        }
    }
}

Export to Excel, CSV, HTML and other formats

Change the OutputPresentationType and output file path. All other code stays the same.

using Majorsilence.Reporting.Rdl;

RdlEngineConfig.RdlEngineConfigInit();

var rdlp = new RDLParser(await System.IO.File.ReadAllTextAsync(@"C:\reports\report.rdl"))
{
    Folder = @"C:\reports"
};
using var report = await rdlp.Parse();

if (report.ErrorMaxSeverity > 4)
    return; // see Error-Handling wiki page

await report.RunGetData(null);

// Excel workbook (full formatting)
using var xlsx = new OneFileStreamGen(@"C:\output\report.xlsx", true);
await report.RunRender(xlsx, OutputPresentationType.Excel2007);

// Excel — data rows only, no report chrome
using var xlsxData = new OneFileStreamGen(@"C:\output\report-data.xlsx", true);
await report.RunRender(xlsxData, OutputPresentationType.Excel2007DataOnly);

// CSV
using var csv = new OneFileStreamGen(@"C:\output\report.csv", true);
await report.RunRender(csv, OutputPresentationType.CSV);

// HTML
using var html = new OneFileStreamGen(@"C:\output\report.html", true);
await report.RunRender(html, OutputPresentationType.HTML);

// RTF
using var rtf = new OneFileStreamGen(@"C:\output\report.rtf", true);
await report.RunRender(rtf, OutputPresentationType.RTF);

// Multi-page TIFF (colour)
using var tif = new OneFileStreamGen(@"C:\output\report.tif", true);
await report.RunRender(tif, OutputPresentationType.TIF);

// Multi-page TIFF (black and white)
using var tifBw = new OneFileStreamGen(@"C:\output\report-bw.tif", true);
await report.RunRender(tifBw, OutputPresentationType.TIFBW);

Export to multiple formats from one data query

BuildPages() separates the data query from the rendering step. Call it once to run the query and lay out all pages, then render to as many output formats as you need from the same in-memory pages — no repeated database round-trips.

using Majorsilence.Reporting.Rdl;

RdlEngineConfig.RdlEngineConfigInit();

var rdlp = new RDLParser(await File.ReadAllTextAsync(@"C:\reports\report.rdl"))
{
    Folder = @"C:\reports"
};
using var report = await rdlp.Parse();
await report.RunGetData(null);      // query the database once

// Build the page layout — this is the expensive step
var pages = await report.BuildPages();

// Render to multiple formats from the cached pages — no extra DB calls
var pdfSg = new OneFileStreamGen(@"C:\output\report.pdf", true);
await report.RunRenderPdf(pdfSg, pages);

var tifSg = new OneFileStreamGen(@"C:\output\report.tif", true);
await report.RunRenderTif(tifSg, pages, bColor: true);   // true = colour

var tifBwSg = new OneFileStreamGen(@"C:\output\report-bw.tif", true);
await report.RunRenderTif(tifBwSg, pages, bColor: false); // false = B&W

This pattern is most valuable when:

  • Generating PDF + Excel + HTML in the same request (e.g. an API that returns all three)
  • The dataset query is slow and you want to avoid running it multiple times
  • You need both colour and black-and-white TIFF variants

Clone this wiki locally