= Indexing PDF XMP-metadata with Recoll The original document describing XMP metadata usage with Recoll was written by Jeffrey Dick and is link:original-text.html[still available here]. However it described using the old shell-based PDF Recoll input handler, which differs a lot from doing something equivalent with the current Python-based one (for which XMP capability is available from recoll 1.23.2, but the new handler can be used with previous Recoll versions). I based this page on the text by Jeffrey Dick, using input from Johannes Menzel for all examples about the new features. The discussion which led to the updated handler is a link:https://bitbucket.org/medoc/recoll/issues/300/extracting-xmp-metadata-and-tmsu-tags[Bitbucket Recoll issue]. == Introduction Organizing and searching a large collection of PDFs as part of a research project can be a demanding task. link:http://en.wikipedia.org/wiki/Extensible_Metadata_Platform[XMP metadata] stored in a PDF, such as journal title, publication year, and user-added keywords, are often useful when searching for a publication. Here, we describe customizing Recoll to retrieve this metadata, store it, and defining a result paragraph format to display it. See also a related wiki entry, link:https://bitbucket.org/medoc/recoll/wiki/HandleCustomField.wiki[Generating a custom field and using it to sort results], for sorting results on PDF page count. == Saving metadata to PDFs Bibliographic metadata can be saved in the PDF file itself. In the link:http://jabref.sourceforge.net[JabRef] bibliography manager, this is done with the "Write XMP-metadata to PDFs" menu item. Note the presence of the keywords in the screenshot below; this field is a good place to tag the PDF with any words of your choosing to describe genre, topic, etc. image::jabref_metadata.png[Editing metadata with jabref] == Custom indexing short example (fields file) The following example (extract from a complete configuration shown later) creates two fields named "refjournal" and "refpages", which are both stored (so they can be displayed in result list entries), and indexed (you can specifically search them). Some other types of metadata, such as title, author and keywords, are already indexed by Recoll (the default rclpdf finds them using the *pdftotext* command) so there is no need to add those to the [prefixes] section. This is taken from the `fields` file inside the configuration (e.g. '~/.recoll/fields'). ---- [prefixes] refjournal=RFJOURNAL refpages=RFPAGES [stored] refjournal = refpages = [aliases] refjournal = bibtex:journal bibtex:journaltitle refpages = bibtex:pages ---- == Telling the handler what fields to extract As of Recoll 1.23.2, the PDF handler has the capability to use *pdfinfo* for extracting XMP metadata. The switch for executing *pdfinfo* is the 'pdfextrameta' configuration parameter, and the value of the parameter is a list of XMP tags to extract, with optional conversion to Recoll field names (the XMP qualified tag name is kept by default, the translation is separated by a '|' character). Example (without translations): ---- pdfextrameta = bibtex:year bibtex:journal bibtex:journaltitle ---- Note that it is quite equivalent to translate a field name inside 'pdfextrameta' or to uses aliases inside the 'fields' file. == Editing the field values Shortly after the 1.23.2 release, the new rclpdf.py was modified to enable calling external Python code for editing the values of the XMP metadata fields. The name of the external script is defined by the 'pdfextrametafix' configuration variable, and it should define a 'MetaFixer' class, with a 'metafix()' method. In practise, add the following to recoll.conf: ---- pdfextrametafix = /path/to/my/script.py ---- The Python script could look like the following: ---- import sys import re # This can be used for local XMP field editing. # # A new instance is created for each PDF document (so the object could # keep state to avoid, e.g. duplicate values) # # The metafix method receives an (original) field name, and the text # value, and should return the possibly modified text. class MetaFixer(object): def __init__(self): pass def metafix(self, nm, txt): if nm == 'bibtex:pages': txt = re.sub(r'--', '-', txt) elif nm == 'someothername': # do something else pass elif nm == 'stillanother': # etc. pass return txt ---- The metadata-editing script can be modified to fill in the "journal" field for BibTex entries that aren't journal articles (e.g. bibtex:booktitle for "InCollection" entries), by defining a 'wrapup()' method which will be called with the whole metadata array (an array of '(nm,value)' pairs) for global editing/removing/addition. == Indexing Then index away! Note that you can also run the rclpdf.py script manually, e.g. `rclpdf.py -d /path/to/some.pdf`, to inspect the output. If things are working correctly, the
consists of the HTML meta elements, and the contains the text of the PDF. == Result paragraph format The result paragraph format defines what fields are displayed inside Recoll result list, and how they are formatted. Edit this using the Recoll GUI: Preferences > GUI configuration > Result List > Edit result paragraph format string. ----| %u | %S | Relevanz: %R | ||
|
%(author)
%(reftype) |
%(refauthor)%(refchapter) %(reftitle)%(refeditor)%(refbooktitle)%(refjournal)%(refvolume)%(refnumber)%(refaddress)%(reflocation)%(refpublisher)%(refyear)%(refpages).
»%A«
%(refkeywords)
%(refkey) %(refisbn) %(refissn) %(refdoi) |
|