Export Zotero PDFs with BibTeX key filenames

This is just in from the department of silly Zotero hacks:

I’ve recently started using the brilliant papercite wordpress plugin to publish a list of my academic publications. This is awesome, because I can just export my Zotero bibliography as BibTex, and hand the bib file over to papercite!

However, when one exports a bibliography from Zotero, the associated PDF files are exported with their full filenames (whatever these may be), whilst papercite expects all PDFs to be in a single directory, each named bibtex_cite_key.pdf, for example malan_voxel_2013.pdf.

Hmmm, how will we solve this?!

papercite_pdfs
My precioussss bibtex citation key PDFs!

I know, let’s hack the Zotero translators/BibTex.js again!!

Around about line 2520 of BibTeX.js (this is with Zotero 4.0.17.1), in the function doExport(), you’ll find the following:

for(var i in item.attachments) {
    var attachment = item.attachments[i];
    if(Zotero.getOption("exportFileData") && attachment.saveFile) {
        attachment.saveFile(attachment.defaultPath, true);

Change it into the following:

for(var i in item.attachments) {
    var attachment = item.attachments[i];
    if(Zotero.getOption("exportFileData") && attachment.saveFile) {
        if (attachment.mimeType == 'application/pdf') {
            attachment.saveFile('/tmp/' + citekey + '.pdf', true);
        } else {
            attachment.saveFile(attachment.defaultPath, true);
        }

After exporting any set of publications as BibTeX, with “Export Files” checked, you’ll find a tmp subdirectory in your export directory. This contains all of the associated PDF files, named according to the BibTeX citation key, which is exactly what papercite wants.

Let me know in the comments how this went!

One thought on “Export Zotero PDFs with BibTeX key filenames”

  1. Thank you – it worked perfectly for me.

    I copied the BibTeX.js file and adjusted the meta information – so I have a new entry in the exporter-list.

Leave a Reply

Your email address will not be published. Required fields are marked *