7

I have two versions of the same PDF document. One has annotations that I did on it while reading it on my laptop, while the other has annotations that I did on a tablet. Now I want to merge these annotations into the same file.

I know that Adobe Acrobat allows me to do this (see for example this answer on Ask Different). Is there any software I can use in Ubuntu that will allow me to do this?

For what it is worth, I am using Xodo on the tablet.

8

1 Answer 1

1
+50

At least okular stores comments as objects of /Type/Annot, see these examples for the syntax:

17 0 obj
<<
/Type/Annot
/Rect[67.023 756.168 85.203 774.333]
/Subtype/Text
/M(D:20170828091301)
/T(■ somebody)
/Contents(■ text)
/NM(okular-{8ff65cc1-7b89-45c6-8adf-1aa6cec06cd0})
/F 4
/C[1 1 0]
/CA 0.5
/Border[0 0 1]
/P 20 0 R
>>
endobj

18 0 obj
<<
/Type/Annot
/Rect[37.7 597.841 236.675 615.979]
/Subtype/FreeText
/DA(/Invalid_font 10 Tf)
/M(D:20170828091316)
/T(■ somebody)
/Contents(■ text)
/NM(okular-{50420111-1c05-4e07-8db5-08deffb0ec7e})
/F 20
/C[1 1 0]
/CA 0.5
/Border[0 0 1]
/Q 0
/IT/FreeText
/P 20 0 R
>>
endobj

Those objects are linked to pages using a command like /Annots 14 0 R, which is how this script deletes all comments in a given pdf file, it simply deletes all the /Annots lines:

pdftk original.pdf output uncompressed.pdf uncompress
LANG=C sed -n '/^\/Annots/!p' uncompressed.pdf > stripped.pdf
pdftk stripped.pdf output final.pdf compress

If you dive really deep into the structure of your specific pdf documents – just open them with a text editor –, you may be able to understand what's going on and manage to manipulate your documents with e. g. sed, however I seriously doubt there exists a solution that fits every type of pdf document here. For what it's worth, (at least for my test file) the following oneliner gives you the comments of input.pdf in a terminal:

pdftk input.pdf output - uncompress | sed '/^\/Contents (/!d'

Add >> comments to the end of that line to store the output in a file named comments instead.

5
  • 1
    I am awarding you the bounty so it is not lost. But I hope there is a better way!
    – a06e
    Sep 21, 2017 at 7:20
  • @becko As PDF is far from being a well-defined format with a clear and stable syntax unfortunately that's unlikely. Sorry for not having better news.
    – dessert
    Sep 21, 2017 at 7:26
  • Well, Adobe Acrobat does it pretty well, which shows it is possible. Actually I am using Xodo to make annotations, on a tablet. Maybe Xodo stores comments in the same way as Okular?
    – a06e
    Sep 21, 2017 at 8:03
  • Are you sure Adobe Acrobat can do that for comments added in other programs? I wouldn't count on it… I just tested and Xodo stores comments similarly to Okular, so the last command in my answer is able to display them.
    – dessert
    Sep 21, 2017 at 9:24
  • Adobe Acrobat works fine with Xodo, which is the combo I have been using, on a Mac (where I have Adobe Acrobat). If Xodo uses the same format as Okular that is good news! Thanks
    – a06e
    Sep 21, 2017 at 9:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .