Undo and redo annotations in Blazor SfPdfViewer

12 May 20261 minute to read

The Blazor SfPdfViewer supports undo and redo for annotations.

Undo-redo

Undo and redo actions can be performed by using either of the following methods:

  1. Using keyboard shortcuts (desktop):
    After performing an annotation action, press Ctrl+Z to undo and Ctrl+Y to redo on Windows and Linux. On macOS, use Command+Z to undo and Command+Shift+Z to redo.
  2. Using the toolbar:
    Use the Undo and Redo tools in the toolbar.
  3. Programmatically:
    Call the UndoAsync and RedoAsync methods from the client side.

Programmatic Undo and Redo

Refer to the following code snippet to call undo and redo actions programmatically.

@using Syncfusion.Blazor.Buttons
@using Syncfusion.Blazor.SfPdfViewer

<div style="margin-bottom: 8px;">
    <SfButton OnClick="UndoAnnotation">Undo</SfButton>
    <SfButton OnClick="RedoAnnotation">Redo</SfButton>
</div>

<SfPdfViewer2 @ref="viewer"
              DocumentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
              Height="650px"
              Width="100%">
</SfPdfViewer2>

@code {
    SfPdfViewer2 viewer;

    public async void UndoAnnotation(MouseEventArgs args)
    {
        await viewer.UndoAsync();
    }

    public async void RedoAnnotation(MouseEventArgs args)
    {
        await viewer.RedoAsync();
    }
}

See also