Unplanned
Last Updated: 28 Aug 2024 12:49 by Sam
Sam
Created on: 28 Aug 2024 10:52
Category: PDFViewer
Type: Bug Report
1
PDF Viewer opens new file at the scroll position of the previous file

When the user scrolls the PDF Viewer down and then opens another PDF file, the new document should display on the first page. Currently, the new file displays scrolled to the page from the previous file and the user must scroll to the top manually.

===

A possible workaround is to scroll the PDF file with JavaScript in the PDF Viewer OnOpen event:

 

@inject IJSRuntime js

<TelerikPdfViewer Data="@PdfSource"
                  Height="600px"
                  OnOpen="@OnPdfViewerOpen"
                  Class="@PdfViewerClass">
</TelerikPdfViewer>

<script suppress-error="BL9992">
    function scrollPdfToTop(selector) {
        var pdfCanvas = document.querySelector(selector);
        if (pdfCanvas) {
            pdfCanvas.scrollTop = 0;
        }
    }
</script>

@code {
    private byte[]? PdfSource { get; set; }

    private string PdfViewerClass { get; set; } = "scrollable-pdf-viewer";

    private async Task OnPdfViewerOpen()
    {
        await js.InvokeVoidAsync("scrollPdfToTop", $".{PdfViewerClass} .k-pdf-viewer-canvas");
    }
}

 

1 comment
Sam
Posted on: 28 Aug 2024 12:49
I was able to use the workaround provided, but needed to integrate differently.  I'm not using the OPEN process, so I added the calling of the JS function to my "OnAfterRenderAsync" handler.