Perform undo and redo in JavaScript
14 Jan 20262 minutes to read
The PDF Viewer supports undo and redo for Annotations.

Undo and redo actions can be performed in the following ways:
- Using keyboard shortcuts:
After performing a highlight annotation action, press Ctrl+Z to undo and Ctrl+Y to redo. - Using the toolbar:
Use the Undo and Redo tools in the toolbar.
Refer to the following code snippet to call undo and redo actions from the client side.
<!--Element to call undo-->
<button id="undo">Undo</button>
<!--Element to call redo-->
<button id="redo"> Redo</button>ej.pdfviewer.PdfViewer.Inject(
ej.pdfviewer.Toolbar,
ej.pdfviewer.Magnification,
ej.pdfviewer.Navigation,
ej.pdfviewer.LinkAnnotation,
ej.pdfviewer.ThumbnailView,
ej.pdfviewer.BookmarkView,
ej.pdfviewer.TextSelection,
ej.pdfviewer.Annotation,
ej.pdfviewer.FormDesigner,
ej.pdfviewer.FormFields
);
var pdfviewer = new ej.pdfviewer.PdfViewer();
pdfviewer.documentPath = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
pdfviewer.resourceUrl = 'https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib';
pdfviewer.appendTo('#PdfViewer');
document.getElementById('undo').addEventListener('click', function () {
pdfviewer.undo();
});
document.getElementById('redo').addEventListener('click', function () {
pdfviewer.redo();
});NOTE
To set up the server-backed PDF Viewer,
Add the belowserviceUrlin theindex.jsfile
pdfviewer.serviceUrl = 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer/';