Document Solutions for PDF
Document Solutions PDF Viewer Overview / Edit PDF / Features / Edit Annotation Timestamp
In This Topic
    Edit Annotation Timestamp
    In This Topic

    When you add or modify annotations to the PDF document, the timestamps store the date and time information. These timestamps help in keeping track of any additions or changes you make. DsPdfViewer's modificationDate property stores the timestamps of the annotations when adding or modifying them. These timestamps automatically appear in the annotations, Modified property of the Property Panel, and Comment Panel. Moreover, these timestamps update automatically when you make changes to the annotation.

    The modificationDate property is a string type that can either be empty (meaning that the date and time are not specified) or contain the date and time in internal PDF format or as per the system locale settings. By default, this property is read-only. However, DsPdfViewer allows you to set the value of modificationDate property via the built-in UI calendar by enabling the allowModificationDateEdit option. Furthermore, DsPdfViewer also allows you to set the timestamp programmatically using pdfStringToDate, dateToPdfString, and updateAnnotation methods. The pdfStringToDate method converts the PDF date string to a JavaScript Date object, whereas the dateToPdfString method converts the JavaScript Date object to a PDF date string. The updateAnnotation method updates the annotations.

    Note: If you modify any other annotation property, the “Modified” property will automatically update to the current date and time.

    Edit Annotation Timestamp Programmatically

    Refer to the following example code to edit the annotation timestamp programmatically:

    JavaScript
    Copy Code
    viewer.open("wetlands.pdf").then(
        res => {
            
            // Find the annotation by its subject field.
            // The search retrieves the first annotation that matches the specified subject.
            viewer.findAnnotations("test subject", { findField: 'subject', findAll: true }).then(function (dataArray) {
                if (dataArray) {
    
                    
                    // Retrieve the current modification date of the annotation.
                    // The date is converted from PDF string format to a JavaScript Date object.
                    const oldDate = viewer.pdfStringToDate(dataArray[0].annotation.modificationDate);
                    
                    // Create a new date by adding 1 day to the old date.
                    // This ensures that the date manipulation properly handles month and year boundaries.
                    const newDate = new Date(oldDate);
                    newDate.setDate(newDate.getDate() + 1); // Increment the date by one day.
    
                    // Update the annotation's modification date to the new date.
                    // The date is converted back to PDF string format before being assigned.
                    dataArray[0].annotation.modificationDate = viewer.dateToPdfString(newDate);
    
                    // Notify the viewer about the updated annotation.
                    // Passing the propertyName ("modificationDate") ensures that the API doesn't overwrite
                    // the modification date automatically with the current date.
                    viewer.updateAnnotation(dataArray[0].pageIndex, dataArray[0].annotation, { propertyName: "modificationDate" });
                } else {
                    console.error("Annotation not found.");
                }
    
            });
            
    
            viewer.save("UpdateModificationDate.pdf");
        }
    );
    

    Edit Annotation Timestamp via UI

    To edit annotation timestamp via UI:

    1. Set allowModificationDateEdit option to true to allow editing of the modification date via the Annotation Editor UI.

      JavaScript
      Copy Code
      var viewer = new DsPdfViewer("#host", { supportApi: 'api/pdf-viewer', allowModificationDateEdit: true });
      
    2. Edit the timestamp using Modified property in Property Panel of the Annotation Editor.

    Remove Annotation Timestamp

    Refer to the following example code to remove the annotation timestamp programmatically:

    JavaScript
    Copy Code
    viewer.open("wetlands.pdf").then(
            res => {
            // Retrieve the annotation data for the specified user "John" by searching for annotations with a title field
            viewer.findAnnotations("test subject", { findField: "subject" }).then(function (dataArray) {
                // Check if the annotation data was found
                if (dataArray) {
                // Set the modification date to null to remove the timestamp from the annotation comments
                    dataArray[0].annotation.modificationDate = null;
                // Update the annotation in the viewer with the modified property
                // Passing the propertyName ("modificationDate") ensures that the API doesn't overwrite
                // the modification date automatically with the current date.
                    viewer.updateAnnotation(dataArray[0].pageIndex, dataArray[0].annotation, { propertyName: "modificationDate" });
            } else {
                // Log an error if the annotation was not found
                console.error("Annotation not found.");
            }
            });
                
    
                viewer.save("RemoveModificationDate.pdf");
            }
        );