galkahana / HummusJS

Node.js module for high performance creation, modification and parsing of PDF files and streams
http://www.pdfhummus.com
Other
1.14k stars 169 forks source link

How to update an annotation? #289

Closed itechbear closed 6 years ago

itechbear commented 6 years ago

Hi, thanks for such an amazing library. I'm trying to integrate it to my own software, which manipulates annotations of PDF files.

I've figured out how to add a highlight annotation, with PdfWriter, FormXObject, ObjectContext etc. But for updating annotations, specifically, updating some field of an annotation (for example, the /Comment field), I didn't find much useful information. Can you please guide me on how to do it?

itechbear commented 6 years ago

I think I've found some clues.

Firstly, use pageObject['Annots'] to obtain the Annotation Object Array. Given the annotation object id annotationObjectID, use pdfReader.queryArrayObject(pageObject['Annots'], annotationObjectID) to obtain the original annotation. pdfReader.queryArrayObject(pageObject['Annots'], annotationObjectID).toJSObject() can be used to inspect fields information of the old annotation. Then I can create a new annotation, copy the information of the old annotation to it and write it to the pdfPage.