Move the scrollbar to the exact location of annotations

5 Dec 20241 minute to read

The Syncfusion® Blazor SfPdfViewer component allows you to move the scrollbar to the exact location of annotations present in a loaded PDF document using the GoToBookmarkAsync() method.

The following code example shows how to move the scrollbar to annotation location.

@using Syncfusion.Blazor.SfPdfViewer

<button @onclick="navigate">Navigation</button>

<SfPdfViewer2 @ref="PdfViewer" DocumentPath="@DocumentPath">
    <PdfViewerEvents DocumentLoaded="DocumentLoad"></PdfViewerEvents>
</SfPdfViewer2>

@code {
    SfPdfViewer2 PdfViewer;
    public string DocumentPath { get; set; } = "wwwroot/data/PDF Succinctly.pdf";
    public Dictionary<int, System.Drawing.SizeF> pageSize { get; set; }

    private void DocumentLoad(LoadEventArgs args)
    {
        pageSize = args.PageData.PageSizes;
    }

    private async void navigate()
    {
        var annotationCollection = await PdfViewer.GetAnnotationsAsync();
        var pageNumber = (annotationCollection[0].PageNumber);
        var Y = annotationCollection[0].Bound.Top;
        await PdfViewer.GoToBookmarkAsync(pageNumber, (pageSize[pageNumber].Height - Y));
    }

}

View sample in GitHub.