I have to read through various research papers and during the course I have to highlight and annotate. But if I rename the file later or change machine the highlights and annotations will be missing since they are stored separately. How can I preserve these highlights/annotations created in Okular if I change machines in the future?


Since KDE 4.2, Okular has the "document archiving" feature. This is an Okular-specific format for carrying the document plus various metadata related to it (currently only annotations). You can save a "document archive" from the open document by choosing File → Export As → Document Archive. To open an Okular document archive, just open it with Okular as it would be e.g. a PDF document.

Since Okular 0.15 you can also save annotations directly into PDF files. This feature is only available if Okular has been built with version 0.20 or later of the Poppler rendering library. You can use File → Save As... to save the copy of the PDF file with annotations.

read here: https://docs.kde.org/stable5/en/kdegraphics/okular/annotations.html


Current version of Okular allows one to save the PDF with the annotations by going into File -> Save As.

However, I wanted something automated. So, I created an Autokey script so that whenever I close my PDF, the annotations are automatically saved in the PDF itself. Note that this script will save your PDF overwriting the original PDF.

The Autokey Script

First, you will need to install autokey-gtk and xdotool first:

sudo apt-get install autokey-gtk xdotool

Now, in autokey, go to New -> Script. Add the following code to your new script:

#This is used to save PDF in okular so that the annotations persist in the PDF file itself
#We have to use to `xdotool` to bring the dialogs back into focus, otherwise they are losing focus 
import subprocess

subprocess.call(["xdotool", "windowfocus", "`xdotool getwindowfocus`"])
subprocess.call(["xdotool", "windowfocus", "`xdotool getwindowfocus`"])
subprocess.call(["xdotool", "windowfocus", "`xdotool getwindowfocus`"])
keyboard.send_keys("<ctrl>+q") #Quit Finally

You can now assign a window filter and hotkey to this script. In window filter, add .*okular.*. And in hotkey, I've used <ctrl>+s. You could use anything else that you prefer.

So, now whenever I have to quit okular, I use CtrlS, and okular quits after saving my pdf.

  • @HermanJaramillo: I'm glad this helped :) However, do remember that this is quite a hack. I am still on the lookout for a more robust approach. – shivams Jun 14 '17 at 11:56
  • 1
    This is the best software I've seen so far ! It's like a shell script but for GUI applications ! :) – matthieu Nov 23 '18 at 10:15

I think I have the answer. After running this simple find command in your Home directory:

find -type d -iname "*okular*" -print

You'll find this directory:


underneath it is the directory:


This docdata directory contains xml files for each document you've opened with Okular. Just backup this folder and carry to your new machine and paste it there in the same place. Your annotations are preserved!

  • Works like a charm. – JohnRos Aug 1 '16 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.