Unplanned
Last Updated: 03 Feb 2026 16:07 by Nicola
Nicola
Created on: 03 Feb 2026 16:07
Category: PDFViewer
Type: Bug Report
0
PDFViewer GetFileAsync method returns a different byte array based on the method of loading the file

Description

The byte array returned by the GetFileAsync method is different when the file is opened through the PDFViewer's toolbar, and when the file is loaded initially using the Data parameter of the PDFViewer.

Steps To Reproduce

  1. Use the example below and the attached exemplary .pdf document.
  2. Place a breakpoint in OnDownloadExportedFileClick
  3. Run the example.
    Scenario 1: when the page loads and the attached file is loaded in the PDFViewer, click the button above the PDFViewer.
    Scenario 2: when the page loads, open the attached file in the PDFViewer, through the Open toolbar tool. Click the button above the PDFViewer.
@using System.IO
@inject IJSRuntime JSRuntimeInstance
@inject HttpClient HttpClient
@inject NavigationManager NavigationManager

<PageTitle>Home</PageTitle>

<p>
    <TelerikButton OnClick="@OnDownloadExportedFileClick">Get file with GetFileAsync and download</TelerikButton>
</p>

<strong>@TestResult</strong>

<br />
<br />

<TelerikPdfViewer @ref="@PdfViewerRef"
                    Data="@PdfViewerData"
                    AnnotationMode="@PdfViewerAnnotationMode.EnableForms"
                    Height="400px">
</TelerikPdfViewer>

@code {
    #nullable enable

    private TelerikPdfViewer? PdfViewerRef { get; set; }
    private byte[]? PdfViewerData { get; set; }

    private string TestResult { get; set; } = string.Empty;

    public async Task OnDownloadExportedFileClick()
    {
        var result = await PdfViewerRef.GetFileAsync();

        TestResult = $"First PDF Viewer GetFileAsync() returned {result} at {DateTime.Now.ToString("HH:mm:ss")}";

        var base64String = Convert.ToBase64String(result);
        var dataUrl = ToDataUrl("application/pdf", base64String);
        _ = SaveFileAsDataUrlAsync("export.pdf", dataUrl);
    }

    private protected ValueTask SaveFileAsDataUrlAsync(string fileName, string dataUrl)
    {
        return InvokeVoidAsync("saveFile", fileName, dataUrl);
    }

    protected virtual ValueTask InvokeVoidAsync(string methodName, params object[] args)
    {
        try
        {
            return JSRuntimeInstance.InvokeVoidAsync($"TelerikBlazor.{methodName}", args);
        }
        catch (Exception)
        {
            return default;
        }
    }

    private protected string ToDataUrl(string mimeType, string base64String)
    {
        return $"data:{mimeType};base64,{base64String}";
    }

    protected override async Task OnInitializedAsync()
    {
        PdfViewerData = System.IO.File.ReadAllBytes(@"pdf-viewer-form-filling-original.pdf");
        await Task.Delay(1);
    }
}

pdf-viewer-form-filling-original.pdf

Actual Behavior

The breakpoint in OnDownloadExportedFileClick is hit. Observe the difference in the byte array returned by the GetFileAsync method and saved in the "result" variable:

Image Image

Expected Behavior

The byte array should be identical, regardless of the method of opening the file in the PDFViewer.

Browser

All

Last working version of Telerik UI for Blazor (if regression)

No response

0 comments