User timestamp annotation date issue

53 views
Skip to first unread message

Tim McElwee

unread,
Nov 2, 2017, 6:32:50 PM11/2/17
to PDFTron WebViewer
I'm trying to create a user timestamp annotation that has the user name and date/time that the annotation was created. The problem that I'm running into is that if I set the date in the annotation's draw function, it updates every time I click on the annotation. So, I can create an annotation and come back to move it, etc, and the time updates. How can I set the date/time to be only the time that the initial user adds the annotation to the document?

Here's the code for the annotation prototype.

UserTimestamp.prototype = $.extend(new Annotations.MarkupAnnotation(), {
elementName: 'userTimestamp',
draw: function (ctx) {
var annotManager = readerControl.docViewer.getAnnotationManager();
var userName = annotManager.getCurrentUser();
var now = new Date();
var dateFormatted = now.toLocaleDateString("en-us", {month: 'short'}) + " " + now.getDate() + ", " + now.getFullYear().toString();
var hours = now.getHours();
var hoursTwelve;
var dayHalf;
if (hours >=12) {
hoursTwelve = hours - 12;
dayHalf = "PM";
} else {
hoursTwelve = hours;
dayHalf = "AM";
}
var timeFormatted = hoursTwelve + ":" + now.getMinutes() + " " + dayHalf;

ctx.strokeStyle = 'rgba(255, 0, 0, 1)';
ctx.fillStyle = 'rgba(255, 0, 0, 1)';
ctx.strokeRect(this.X, this.Y, 175, 90)
ctx.font = '21px sans-serif';
ctx.fillText('' + userName + '', this.X + 10, this.Y + 25, 175);
ctx.fillText(dateFormatted, this.X + 10, this.Y + 50, 175);
ctx.fillText(timeFormatted, this.X + 10, this.Y + 75, 175);
ctx.fillStyle = 'rgba(255, 0, 0, 0.2)';
ctx.fillRect(this.X, this.Y, 175, 90);
}
});
 

Justin Jung

unread,
Nov 3, 2017, 4:19:34 PM11/3/17
to PDFTron WebViewer
Hello,

The annotation should have DateCreated by default. You can switch

var now = new Date();

to

var now = this.DateCreated;

Justin Jung
Software Developer
PDFTron Systems Inc.
Message has been deleted

Tim McElwee

unread,
Nov 6, 2017, 11:40:38 AM11/6/17
to PDFTron WebViewer
Thank you, Justin! That's exactly what I needed. I knew I was missing something.

Tim

Tim McElwee

unread,
Nov 7, 2017, 3:26:48 PM11/7/17
to PDFTron WebViewer
One more question, Justin. Is there a similar "created by user" method or variable? Looking at how I've written this, I'm wondering if I'll run into the same rewrite problems for the user portion.


Tim

On Friday, November 3, 2017 at 4:19:34 PM UTC-4, Justin Jung wrote:

Justin Jung

unread,
Nov 8, 2017, 7:09:48 PM11/8/17
to PDFTron WebViewer
Yup, there is an Author property that you could refer to:

var userName = this.Author;
Reply all
Reply to author
Forward
0 new messages