Undo and Redo in .NET MAUI PDF Viewer (SfPdfViewer)
17 Jul 20262 minutes to read
If you performed any undesired actions when adding, removing, moving, resizing, or editing annotations, you can undo and redo the action to restore the previous state. This section explains how to undo and redo changes made to 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 undo the most recent action performed on the annotations using the UndoCommand of the SfPdfViewer. The following code examples show how to bind the command to a button in XAML to perform the action on button click, and how to execute the command programmatically.
<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 redo the last undone action using the RedoCommand of the SfPdfViewer. The following code examples show how to bind the command to a button in XAML to perform the action on button click, and how to execute the command programmatically.
<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);
}Limitations
The undo and redo history covers annotation changes only. The following operations cannot be undone:
- Saving a document using SaveDocumentAsync.
- Applying redaction using RedactAsync.
- Unloading a document using UnloadDocument. Unloading clears the undo/redo history entirely.
NOTE
The undo/redo stack is also cleared when a new document is loaded.