Table of Contents

Export without a browser

A batch job needs no Blazor and no host: the data providers resolve the report's data source, DocWright runs and paginates the report, and its renderers and exporters write the files. This is the ReportWright.Samples.HeadlessExport sample.

In process

using DocWright.Fonts;
using DocWright.Renderers.Pdf;
using DocWright.Reporting;
using DocWright.Reporting.Export;
using DocWright.Reporting.Pagination;
using DocWright.Reporting.Processing;
using DocWright.Reporting.Rdl;
using ReportWright.Data;
using ReportWright.Data.Csv;

// The host's side of the data seam: the report's "Files" source is a folder of CSV files.
var resolver = new StaticDataSourceResolver()
    .Add("Files", new ResolvedDataSource(CsvDataSourceProvider.ProviderKind, "Files") { ConnectionString = dataDirectory });
var router = new DataSourceRouter(resolver, new DataSourceRegistry().Add(new CsvDataSourceProvider()),
    new DataSourceRouterOptions { MaxRows = 100000, DefaultTimeout = TimeSpan.FromSeconds(10) });

ReportDefinition definition;
using (FileStream input = File.OpenRead("sales.rdl"))
{
    definition = new RdlReader().Read(input);
}

var fonts = new FontEngine();
using ReportInstance instance = ReportProcessor.Process(definition, router, new ReportRunOptions());
ReportPageModel pages = ReportPaginator.Paginate(instance, fonts);

using (FileStream pdf = File.Create("sales.pdf"))
{
    new PdfLayoutRenderer(fonts).Render(pages.ToLayoutDocument(), pdf, new RenderOptions(), NullConversionDiagnostics.Instance);
}

using (FileStream xlsx = File.Create("sales.xlsx"))
{
    ReportXlsxExporter.Export(pages, fonts, xlsx);
}

using (FileStream csv = File.Create("sales.csv"))
{
    ReportCsvExporter.Export(pages, csv);
}

The page model is paginated once and every export reads it; pages.Diagnostics lists what the engine did not draw and why, with its code.

Through the host

With the REST API mapped, one request does the same from anywhere:

POST /reporting/reports/export/PDF/sales.rdl
Content-Type: application/json

{ "parameters": { "Region": "North" } }

GET /reporting/exports lists the formats the host registered (PDF, PDF/A, PNG, JPEG, DOCX, XLSX, CSV, text by default). A scheduler that used to call the report server's URL access calls this instead.

Parameters and the clock

ReportRunOptions.Parameters takes the values; ExecutionTime fixes Globals!ExecutionTime for reproducible output, which the sample does so its files compare equal run to run.