Sunday, March 16, 2014

Nautilus Browser for PDF Management : Show and Edit PDF Metadata in Nautilus

I had an ever-growing stock of pdf files (academic journals) which I had to read for my research. I worked mostly on my Linux box and used GNOME to explore files.

In such a case, I wanted my Nautilus to have the capability to

  1. Show the PDF metadata
  2. And be able to edit it

Showing PDF Metadata in Nautilus in List View

There is a famous plugin for that: nautilus-columns. It's not in the official repository. It's a plugin by webupd8. So, just do:

sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install nautilus-columns
nautilus -q
After this, just open your nautilus and go to Preferences  > List Columns. Here, you can now check the metadata you would like to see in the "List Columns View".


A probable problem and its solution

Now, some people might the face problem that it is not work in their Nautilus, especially in MATE desktops. So, for this, you just need to rewire your python a bit: 

For 32-bit users:


sudo ln -sf /usr/lib/libpython2.7.so.1 /usr/lib/libpython2.7.so.1.0
sudo ln -sf /usr/lib/i386-linux-gnu/libpython2.7.so.1 /usr/lib/libpython2.7.so.1
For 64-bit users:
sudo ln -s /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 /usr/lib/libpython2.7.so.1.0
sudo ln -s /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 /usr/lib/x86_64-linux-gnu/libpython2.7.so

Adding more fields for PDF Metadata

By default the nautilus-columns has very less fields related to PDF. Only two, actually: "Title" and "Artist"(author). But you definitely need more. In my case, I needed "Subject", "Year of Publication" and "Keywords". So, I modified the script file a bit.

Now, this script is located at "/usr/share/nautilus-python/extensions/". Go here, and open "bsc-v2.py" as root. Now, if you know a bit about python scripting, it'd be straightforward to you to add more relevant fields. For a demonstration, here's a link to the modified script file that I used for my purpose: https://dl.dropboxusercontent.com/u/14472678/bsc-v2.py

Edits I made: 
  • Added "import re" in line 36
  • Added some fields in lines 88-90
  • Modified the pdf handling starting from line 222
Just browse through the code, and if you have any problem, just drop in a comment.


Editing Metadata in Nautilus

Now, coming to this. Install these requirements:
  • nautilus-actions
  • exiftool
 Now, follow the steps:
1) Open Nautilus-Actions. Click on "New Action" (Ctrl+N)
2) On the right side, in "Action" tab, add something to "Context Label" field. Let's say, we add: "Add Title to PDF"

3) In the "Command" tab, in the "Path" field, we have to enter our command. We enter this:

echo "Enter the title and press enter"; read title; exiftool -Title=$title -overwrite_original %F 

4) In the "Execution" tab, check "In a terminal" as the execution mode. 

5) Now, this is the crucial part. Go to Preferences > Runtime Execution. Here, in the command pattern, add this: 
gnome-terminal -x sh -c COMMAND

6) Now, Save this (Ctrl+S). Close the application. And restart nautilus (nautilus -q). Now, open Nautilus, select any pdf file, and right click on it. You'd see a Nautilus-Actions > "Add Title to PDF" menu item. Click on it. A terminal will open up. Enter the desired title. And it'd be instantly changed. 

And we're done!!


What's happening here?

Nothing much. We are basically using exiftool  to edit the metadata. Also, we used the "read" command to take input from the user. Rest is self-explanatory.




No comments:

Post a Comment