How to keep the top-level note/comment of an annotation with its original date?

PDF.js Express Version

UI Version: 7.3.0
Core Version: 7.3.1

Detailed description of issue
When an annotation gets added, its initial comment in the notes panel has the original date/time in which the annotation was added. When new comments are added to the annotation though, the original/first comment’s date always updates to the latest comment’s date. Is there a way to keep the original date of the first comment of annotations?

Does your issue happen with every document, or just one?
Happens with every document/annotation.

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hi psilva,

You can change the appearance of the notes individually by using the dangerouslySetNoteTransformFunction API Please read about the documentation for that to see if it is the right choice for you. Here is a small snippet to show how you could do that:

  instance.dangerouslySetNoteTransformFunction((wrapper, state, createElement) => {
    const noteId = wrapper.id.split('_')[1];
    const noteAnnot = annotationManager.getAnnotationsById(noteId)[0];
    wrapper.querySelector('.author-and-time .date-and-num-replies .date-and-time').innerHTML = noteAnnot.DateCreated;
  })

You still may need to parse the date your liking as we DayJs in our UI code.

Alternatively, if this solution does not work for you, you could fork our open source UI you can find a guide how to that here. Here you’ll want to edit this line to be the date of the first date created rather than the latestActivityDate.

Cheers,
Dustin

Hey Dustin,

Thanks for the help. This would work perfectly, but wrapper.id seems to always be an empty string, so it doesn’t work. Is this a bug on the definition of dangerouslySetNoteTransformFunction?

I looked at every member and method of wrapper but I can’t find another way to get the annotation it wraps from it. This would work if I could grab the annotation from the wrapper somehow.

(I couldn’t find a way to make this work with getAnnotationsList() either).

Lucas

Hi Lucas,

It looks like that we added the note id to the wrapper in a later version of PDF.js Express, it looks like my original approach will work in the current version - 7.3.7. However, after looking more at the problem, I may have given you an unnecessarily over-complicated solution, I believe this code snippet should work in older versions:

    instance.dangerouslySetNoteTransformFunction((wrapper, state, createElement) => {
    wrapper.querySelector('.author-and-time .date-and-num-replies .date-and-time').innerHTML = state.annotation.DateCreated;
  })

Let me know if that works for you.

Cheers,
Dustin

Dustin,

Worked perfectly. Thanks for the help.

Cheers,

Lucas

1 Like