Undo and Redo in .NET MAUI PDF Viewer (SfPdfViewer)

If you performed any undesired actions when on adding, removing, moving, resizing or editing annotations, you can undo and redo the action to restore the previous state. This section will go through how to perform the undo and redo the changes made on the annotations.

For desktop platforms such as Windows and macOS, you can also use the following shortcut keys to perform the actions.

Action & Shortcut keys Windows macOS
Undo Ctrl + z Command + z
Redo Ctrl + y Command + y

Undo

You can perform undo to reverse the most recent action performed on the annotations using the UndoCommand of the SfPdfViewer. The following code examples explains how to bind the command to a button in XAML to perform the action on button click and also executing the command programmatically as well.

<syncfusion:SfPdfViewer x:Name="PdfViewer"/>
<Button x:Name="Undo" Command="{Binding Path=UndoCommand,Source={x:Reference PdfViewer}}"/>
void PerformUndo()
{
    // Undo the last operation using the UndoCommand of `SfPdfViewer` instance.
    PdfViewer.UndoCommand.Execute(true);
}

Redo

You can perform redo to restore the last undone function using the RedoCommand of the SfPdfViewer.. The following code examples explains how to bind the command to a button in XAML to perform the action on button click and also executing the command programmatically as well.

<syncfusion:SfPdfViewer x:Name="PdfViewer"/>
<Button x:Name="Redo" Command="{Binding Path=RedoCommand,Source={x:Reference PdfViewer}}"/>
void PerformRedo()
{
    // Redo the last operation using the RedoCommand of `SfPdfViewer` instance.
    PdfViewer.RedoCommand.Execute(true);
}