Syncfusion AI Assistant

How can I help you?

Scroll to the Exact Annotation position Using Scrollbar

1 Oct 20251 minute to read

Use the Syncfusion® Blazor SfPdfViewer component to scroll to the location of an annotation in a loaded PDF by calling the GoToBookmarkAsync() method with the target page number and vertical offset (from the top of the page).

The following example shows how to scroll to an annotation.

@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.