Search code examples
javaannotationscommentspdfbox

Apache PDFBox 2.0.18 - Comments/Annotations status linking


I need to merge comments taken from many versions of the same pdf file but with different comments, into one PDF file containing all comments.

I take all the comments from the pages and create an arrayList of them, then I simply set this array of comments on the new pdf file and it works pretty well.

The problem is that I also need to create an Excel with all the comments found and together with their "status" (accepted, cancelled, rejected, ecc...).

The status seems to be managed as a separate annotation/comment from PDFBox and I can't find any relation between a comment and its status.

Example:

I have a PDAnnotation object with content "COMMENT 1".

And I have another PDAnnotation object with content "Accepted by user XX" (the status of COMMENT 1).

On Acrobat Reader I see the comment "COMMENT 1" with the status set on "Accepted", so there must be a relation between the two objects, but I can't find it.

Any ideas?


Solution

  • Using the PDFDebugger is a good suggestion, it should give to you an overview of how objects (including PDAnnotations) are linked to each other

    Anyway, check if in your child PDAnnotation in the COSDictionary you have a COSBase{IRT} key, that key should contain as value the parent COSObject

    So if you do something link this:

    COSDictionary parentDict = (COSDictionary) childDict.getDictionaryObject("IRT");

    You should get the parent PDAnnotation dictionary and you can take all the data you need

    Please notice the cast is necessary since getDictionaryObject returns a COSBase, but the object returned for the IRT key is actually a COSDictionary