Skip to content

Output Formats

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

Output Formats

All report rendering methods accept an OutputPresentationType value from the Majorsilence.Reporting.Rdl namespace.

using Majorsilence.Reporting.Rdl;

await report.RunRender(streamGen, OutputPresentationType.PDF);

Supported formats

Value Extension Notes
PDF .pdf Recommended PDF output via SkiaSharp (v5+).
Excel2007 .xlsx Excel workbook with full report formatting.
Excel2007DataOnly .xlsx Excel workbook — data rows only, no headers/footers/formatting. Useful for data export.
HTML .html HTML fragment. Can be embedded in a web page.
MHTML .mht / .mhtml MHTML archive — HTML with embedded images, suitable for email.
CSV .csv Comma-separated values.
XML .xml Report data as XML.
RTF .rtf Rich Text Format.
Word .doc Word-compatible rich text.
TIF .tif Multi-page TIFF image (colour).
TIFBW .tif Multi-page TIFF image (black and white).

Legacy / internal values

These values exist for backward compatibility or internal use. Avoid them in new code.

Value Notes
PDFOldStyle Legacy PDF path. Use PDF instead.
RenderPdf_iTextSharp v4-era iTextSharp rendering. Use PDF instead.
Excel2003 Old binary Excel format. Use Excel2007 instead.
ExcelTableOnly Older Excel table-only export. Use Excel2007DataOnly instead.
ASPHTML ASP.NET-specific HTML rendering for the v4 ASP.NET control.
Internal Used by the viewer control to render to screen. Do not use for file export.

Code example — export to multiple formats

using Majorsilence.Reporting.Rdl;

RdlEngineConfig.RdlEngineConfigInit();

var rdlp = new RDLParser(await System.IO.File.ReadAllTextAsync("report.rdl"));
using var report = await rdlp.Parse();
await report.RunGetData(null);

// PDF
using var pdf = new OneFileStreamGen("report.pdf", true);
await report.RunRender(pdf, OutputPresentationType.PDF);

// Excel
using var xlsx = new OneFileStreamGen("report.xlsx", true);
await report.RunRender(xlsx, OutputPresentationType.Excel2007);

// CSV
using var csv = new OneFileStreamGen("report.csv", true);
await report.RunRender(csv, OutputPresentationType.CSV);

HTML output — accessing CSS and JavaScript

After rendering to HTML, the Report object exposes the CSS and JavaScript needed to embed the output fragment into a larger page:

using var ms = new MemoryStreamGen();
await report.RunRender(ms, OutputPresentationType.HTML);

string htmlFragment = ms.GetText();
string css          = report.CSS;        // stylesheet for this report
string javascript   = report.JavaScript; // JS for interactive elements

To embed multiple reports on the same page, use the prefix overload to generate unique CSS class names:

await report.RunRender(ms, OutputPresentationType.HTML, "report1_");

Stream generators

Two built-in IStreamGen implementations are available:

Class Use for
OneFileStreamGen(path, overwrite) Write directly to a file on disk.
MemoryStreamGen() Buffer in memory — for HTTP streaming, in-process use. Call GetStream() to access the result. See Streaming PDF — ASP.NET Core.

Custom output targets — IStreamGen

Both built-in classes implement IStreamGen. You can implement the interface yourself to stream output to any target — Azure Blob Storage, Amazon S3, a network socket, or a custom pipeline — without writing to disk or holding the full output in memory.

public class AzureBlobStreamGen : IStreamGen, IDisposable
{
    private readonly MemoryStream _buffer = new();

    public Stream GetStream() => _buffer;
    public TextWriter GetTextWriter() => new StreamWriter(_buffer);
    public Stream GetIOStream(out string relativeName, string extension)
    {
        relativeName = $"resource{extension}";
        return _buffer;
    }
    public void CloseMainStream() { }

    public async Task UploadAsync(BlobClient blob)
    {
        _buffer.Position = 0;
        await blob.UploadAsync(_buffer, overwrite: true);
    }

    public void Dispose() => _buffer.Dispose();
}

// Usage
using var sg = new AzureBlobStreamGen();
await report.RunRender(sg, OutputPresentationType.PDF);
await sg.UploadAsync(blobClient);

See Advanced Data Sources and Output Targets for more patterns.

Clone this wiki locally