Export a report to PDF

ReportViewerHost normally shows the report viewer. Add PdfReady when your app needs PDF bytes instead.

@using Benevia.Core.Reports.Blazor.Components

<ReportViewerHost @key="exportRequestId"
                  ODataClient="@client"
                  ReportGuid="@reportGuid"
                  ReportName="@reportName"
                  Entity="@entityName"
                  EntityGuid="@entityGuid"
                  PdfReady="HandlePdfReady"
                  RenderFailed="HandleRenderFailed" />

@code {
    private byte[]? pdfBytes;
    private string? errorMessage;

    private void HandlePdfReady(byte[] bytes) => pdfBytes = bytes;
    private void HandleRenderFailed(string message) => errorMessage = message;
}

Use the same authenticated IODataClient as the page. The host uses it to load the report and data. This keeps workflow context and field permissions.

Set TemplateJson to render an inline template. The host still checks access to ReportGuid.

Each host exports once after its first interactive render. Change @key or mount a new host to export again.

PdfReady receives the PDF as byte[]. RenderFailed receives a message when load, render, or export fails. Missing entity data fails instead of exporting a blank PDF.

PDF export does not show the viewer. Your app owns download, print, and browser error handling. Exporting a PDF does not prove that a printer printed the document.

Omit PdfReady to show the normal viewer.