How can I help you?
Undo and Redo in .NET MAUI PDF Viewer (SfPdfViewer)
25 Mar 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 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 explain how to bind the command to a button in XAML to perform the action on button click, and also execute 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 explain how to bind the command to a button in XAML to perform the action on button click, and also 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.