Determine if SfPdfViewer has values in the undo and redo collections
17 Jul 20261 minute to read
The Blazor SfPdfViewer exposes the CanUndo and CanRedo properties to indicate whether undo and redo history is available. In SfPdfViewer, bind these properties to boolean fields to reflect availability in the UI.
The following example binds these properties and enables or disables the buttons as the undo and redo history changes.
@using Syncfusion.Blazor.SfPdfViewer
@using Syncfusion.Blazor.Buttons
@if (canUndo)
{
<button @onclick="undo">Undo</button>
}
else
{
<button @onclick="undo" disabled>Undo</button>
}
@if (canRedo)
{
<button @onclick="redo">Redo</button>
}
else
{
<button @onclick="redo" disabled>Redo</button>
}
<SfPdfViewer2 @ref="@viewer"
@bind-CanUndo="@canUndo"
@bind-CanRedo="@canRedo"
DocumentPath="@DocumentPath"
Height="100%"
Width="100%">
</SfPdfViewer2>
@code
{
private SfPdfViewer2 viewer;
private bool canUndo = true;
private bool canRedo = true;
private string DocumentPath { get; set; } = "wwwroot/Data/PDF_Succinctly.pdf";
// Triggered when the Undo button is clicked.
private async Task undo()
{
// Performs the Undo action.
await viewer.UndoAsync();
}
// Triggered when the Redo button is clicked.
private async Task redo()
{
// Performs the Redo action.
await viewer.RedoAsync();
}
}