highkite / pdfAnnotate

Javascript library for creating annotations in PDF documents
MIT License
556 stars 90 forks source link

Pdf not generated as expected #45

Open cuzzea opened 3 years ago

cuzzea commented 3 years ago

I am trying to edit some annotations in a pdf, but it doesn't work as expected (at least as I expect it to work). When I change the content of an annotation, the content dose not get updated. Also I tried to delete the annotation and create a new one, but even that one is not showing up properly.

factory.createFreeTextAnnotation(0, [100, 100, 300, 300], '3', 'vlad', {r: 250,g: 0,b: 0,});

This create the annotation, but it seems to only show up when opening the pdf with adobe pdf. Chrome and pdf.js dose not render the annotation.

Browser (and pdf.js) image

Adobe reader: image

I have created a minimal repo to duplicate the issue I am having (also includes the pdf I am using). https://github.com/cuzzea/test-annopdf

highkite commented 3 years ago

Hello @cuzzea,

pdf.js has no full support for freetext annotations: https://github.com/mozilla/pdf.js/issues/6246 and I think the chrome pdf renderer has the same problem. Not every annotation type is fully supported by every pdf renderer.

cuzzea commented 3 years ago

Thanks for the info. It dose seem to be the case for when creating a new annotation, but the other 2 annotations that I am trying to edit are of the same type. Those are visible in pdf.js, chrome and pdf reader.

factory.createFreeTextAnnotation(0, [100, 100, 300, 300], '3', 'vlad', {r: 250,g: 0,b: 0});
        factory.getAnnotations().then((res2) => {
          console.log(res2[0].map(r => [r.id, r.type]))
        });

[ '01F76F5Q9ET44TQGBF85MTA6HE', '/FreeText' ], // annotation test
[ '01F791J899TSSPWSJGEYA93ER3', '/FreeText' ], // second annotation test
[ 'pdfAnnotate-0210613202656-0', '/FreeText' ] // 3 - newly created

Can you point me in the right direction on what I should look for in order to make the annotation I am trying to create work as the ones already in the pdf?

Also I was under the impression if I get an annotation, I can just change the content property and it would be updated in the document, am I wrong? (If create would work I would just delete it and attach it again, edited).

highkite commented 3 years ago

Hello @cuzzea,

the existing annotations work, since they define AppearanceStream objects. This basically describes how annotations are displayed. This is not yet implemented in the library (however, it is currently in development). Unfortunately, pdfjs and the chrome variant do not implement the common fallback to just use a default appearance stream.

At the time being, for "updating" an annotation the approach of deleting and then creating a new annotation is the way to go. However, the community extensively increased my awareness that a convenient update function should be part of the library and it jumped a long stride up in my todo list.