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.
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"); } ); |
To edit annotation timestamp via UI:
JavaScript |
Copy Code
|
---|---|
var viewer = new DsPdfViewer("#host", { supportApi: 'api/pdf-viewer', allowModificationDateEdit: true }); |
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"); } ); |