Planned
Last Updated: 29 Aug 2025 08:28 by ADMIN
Scheduled for 2025 Q4 (Nov)

We are experiencing an issue where the ExportToPdfAsync() method on TelerikGrid is returning Excel data (XLSX format) instead of PDF data. This is causing MIME type errors when trying to process the exported data as a PDF.

 

===ADMIN EDIT===

Workaround

In the meantime, a possible workaround would be to use the document processing library (make sure the correct packages are installed for it) and import the xlsx file to a workbook, and then export the workbook to PDF. Here is an improvised example that demonstrates this by saving the file in your wwwroot folder as a pdf.

@inject IWebHostEnvironment HostingEnvironment

<TelerikGrid Data="@svcItemList" Height="75svh" Resizable="true" Sortable="true" Pageable="true" PageSize="15" FilterMode="@GridFilterMode.FilterMenu" SelectionMode="@GridSelectionMode.Multiple" SelectedItems="@SelectedSvcItems" @ref="@SvcItemGrid" SelectedItemsChanged="@( (IEnumerable<ArCustomersServiceItemInfo> sel) => OnRowSelect(sel) )">
    <GridToolBarTemplate>
        <TelerikButton OnClick="@GenerateReport">Generate PDF</TelerikButton>
    </GridToolBarTemplate>
    <GridExport>
        <GridPdfExport AllPages="true" PageOrientation="GridPdfExportPageOrientation.Landscape" PaperSize="GridPdfExportPaperSize.A3" />
    </GridExport>
    <GridColumns>
        <GridCheckboxColumn CheckBoxOnlySelection="true"></GridCheckboxColumn>
        <GridColumn Field="SerialNumber">
            <HeaderTemplate><b>SerialNumber</b></HeaderTemplate>
        </GridColumn>
        <GridColumn Field="Manufacturer">
            <HeaderTemplate><b>Manufacturer</b></HeaderTemplate>
        </GridColumn>
        <GridColumn Field="EquipmentModelNumber">
            <HeaderTemplate><b>Model</b></HeaderTemplate>
        </GridColumn>
        <GridColumn Field="TagDescription">
            <HeaderTemplate><b>Description</b></HeaderTemplate>
        </GridColumn>
        <GridColumn Field="TagID">
            <HeaderTemplate><b>TagID</b></HeaderTemplate>
        </GridColumn>
        <GridColumn Field="Quantity">
            <HeaderTemplate><b>Quantity</b></HeaderTemplate>
        </GridColumn>
    </GridColumns>
</TelerikGrid>

@code {
    private async Task GenerateReport()
    {
        isLoading = true;
        var pdfStream = await SvcItemGrid.ExportToPdfAsync();

        // The stream is actually XLSX, so convert it to PDF
        using var ms = new MemoryStream(pdfStream.ToArray());

        // Import XLSX to Workbook
        var xlsxProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider();
        var workbook = xlsxProvider.Import(ms);

        // Export Workbook to PDF
        var rootPath = HostingEnvironment.WebRootPath;
        var saveLocation = Path.Combine(rootPath, "test.pdf");
        var pdfProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.PdfFormatProvider();
        using (var fileStream = new FileStream(saveLocation, FileMode.Create))
        {
            pdfProvider.Export(workbook, fileStream);
        }
    }

    public class ArCustomersServiceItemInfo
    {
        public string SiteID { get; set; }
        public string CompanyCode { get; set; }
        public string ARSubledgerCode { get; set; }
        public string CustomerCode { get; set; }
        public string LineNumber { get; set; }
        public string LineNumberUnique { get; set; }
        public string TagID { get; set; }
        public string TagDescription { get; set; }
        public string Manufacturer { get; set; }
        public string EquipmentModelNumber { get; set; }
        public string SerialNumber { get; set; }
        public string UnitType { get; set; }
        public string Location { get; set; }
        public DateTime? InstallationDate { get; set; }
        public int? WarrantyPeriod1 { get; set; }
        public DateTime? ExpiryDate1 { get; set; }
        public int? WarrantyPeriod2 { get; set; }
        public DateTime? ExpiryDate2 { get; set; }
        public int? WarrantyPeriod3 { get; set; }
        public DateTime? ExpiryDate3 { get; set; }
        public string Status { get; set; }
        public string Area { get; set; }
        public string Installer { get; set; }
        public int? Quantity { get; set; }
        public DateTime? LastModified { get; set; }
        public string Comments { get; set; }
    }

    private List<ArCustomersServiceItemInfo> svcItemList = new()
    {
        new ArCustomersServiceItemInfo { SiteID = "ZGJC-QAADV", CompanyCode = "UN", ARSubledgerCode = "A/R", CustomerCode = "1", LineNumber = "00035", LineNumberUnique = "00035", TagID = "ID20240620L", TagDescription = "desctr", Manufacturer = "MAN20240620L45", EquipmentModelNumber = "MOD20240620L45", SerialNumber = "SER20240620L45", UnitType = "", Location = "", InstallationDate = null, WarrantyPeriod1 = 0, ExpiryDate1 = null, WarrantyPeriod2 = 0, ExpiryDate2 = null, WarrantyPeriod3 = 0, ExpiryDate3 = null },
        new ArCustomersServiceItemInfo { SiteID = "ZGJC-QAADV", CompanyCode = "UN", ARSubledgerCode = "A/R", CustomerCode = "1", LineNumber = "00034", LineNumberUnique = "00034", TagID = "ID20240620A", TagDescription = "Description", Manufacturer = "MAN20240620A", EquipmentModelNumber = "MOD20240620A", SerialNumber = "SER20240620A", UnitType = "", Location = "LOC2024062", InstallationDate = null, WarrantyPeriod1 = 0, ExpiryDate1 = null, WarrantyPeriod2 = 0, ExpiryDate2 = null, WarrantyPeriod3 = 0, ExpiryDate3 = null },
        new ArCustomersServiceItemInfo { SiteID = "ZGJC-QAADV", CompanyCode = "UN", ARSubledgerCode = "A/R", CustomerCode = "1", LineNumber = "00033", LineNumberUnique = "00033", TagID = "test", TagDescription = "descripcion", Manufacturer = "MAN20240617A", EquipmentModelNumber = "MOD20240617A", SerialNumber = "SER20240617A", UnitType = "", Location = "LOC2024061", InstallationDate = null, WarrantyPeriod1 = 0, ExpiryDate1 = null, WarrantyPeriod2 = 0, ExpiryDate2 = null, WarrantyPeriod3 = 0, ExpiryDate3 = null }
    };

    private TelerikGrid<ArCustomersServiceItemInfo> SvcItemGrid;
    private List<ArCustomersServiceItemInfo> SelectedSvcItems = new();
    private string base64Pdf = string.Empty;
    private string email = string.Empty;
    private string subject = "Service Item PDF Report";
    private string emailStatus = string.Empty;
    private bool isLoading = false;

    private void OnRowSelect(IEnumerable<ArCustomersServiceItemInfo> selected)
    {
        SelectedSvcItems = selected.ToList();
    }
}