= 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). This page was adapted from the text by Jeffrey Dick, using input from Johannes Menzel, (especially the result list paragraph format), adapting things for the new handler. 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 (fields file) Let's create two fields named "year" and "journal". The prefixes starting with "XY" are extension prefixes that are added to the terms in the Xapian database (Recoll internally does not use prefixes starting with XY). Additionally, the year and journal are stored so they can be displayed in the results list. 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. Add this text to the fields file in your Recoll configuration directory ('~/.recoll/fields'). ---- [prefixes] year = XYEAR journal = XYJOUR [stored] bibtex:year = bibtex:journal = ---- == 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). Example: ---- pdfextrameta = bibtex:year bibtex:journal bibtex:booktitle|title ---- Here, 'bibtex:year' and 'bibtex:journal' are used directly, and 'bibtex:booktitle' is translated to 'title' (the example is not supposed to make sense) == 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 ---- == 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 Here, the result is formatted to show the title, which is a link to open the document, in blue with underlining turned off. The next two lines contain the authors, then the journal title in green italicized text followed by year (in parentheses). The keywords are listed in red after the abstract/text snippet. 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) |
|