Render the report in .NET MAUI and export it directly from code, without opening the viewer.

Loading the report. A Razor page loads a report template from the app package on initialization:
private StiReport Report = new StiReport();

protected override async Task OnInitializedAsync()
{
    var reportStream = await FileSystem.OpenAppPackageFileAsync("SimpleList.mrt");
    Report.Load(reportStream);
}

Exporting and sharing. The report is rendered and written to the cache directory, then opened or passed to the native share dialog:
private async Task ExportDocument(StiExportFormat format, string fileName, bool shareFile = false)
{
    await Task.Run(() => Report.Render());

    var filePath = Path.Combine(FileSystem.Current.CacheDirectory, fileName);
    using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
    {
        Report.ExportDocument(StiExportFormat.Pdf, fileStream);
    }

    if (shareFile)
    {
        var file = new ShareFile(filePath);
        await Share.Default.RequestAsync(new ShareFileRequest(fileName, file));
    }
    else
    {
        var file = new ReadOnlyFile(filePath);
        await Launcher.OpenAsync(new OpenFileRequest(filePath, file));
    }
}

FileSystem.OpenAppPackageFileAsync reads the template shipped with the app, Report.Render() builds the document, and Report.ExportDocument writes it to the device. The rendered file is then opened with Launcher or handed to Share.Default for the platform share sheet.

Используя этот сайт, вы соглашаетесь на использование файлов Cookie для аналитики и персонализированного контента. Файлы Cookie хранят полезную информацию на вашем компьютере, чтобы помочь нам повысить эффективность и удобство использования. Для получения дополнительной информации, пожалуйста, прочтите Конфиденциальность и Использование Cookie.