Update PDF metadata using Emacs? reddit / emacs ---------------------------------------------------------------------- graduale · 2022-01-31 22:36 I'm trying to find a way of using a `.bib` file to populate the metadata of PDFs associated with any entry in my `.bib` file. In my current setup, I have an easy way of getting the path to any PDF associated with my an entry in my main `.bib` file. If I could modify the metadata of a PDF, I might be able to then use the information in the BibTeX entry to update the metadata of the associated PDF. Is there some way of modifying the metadata of a PDF from within Emacs? I keep searching online but most results I find are about attempts to extract information from the metadata in a PDF. ---------------------------------------------------------------------- gjolleyrogers · 2022-02-01 01:33 Cb2bib is an app that does this outside of emacs. There’s source code. And it works well enough for me. ---------------------------------------------------------------------- graduale · 2022-02-01 02:29 From what I can tell, `c2bib` outputs bibtex entries from metadata. What I want is the reverse: output metadata for a given file with a bibtex entry as input. Am I missing something? ---------------------------------------------------------------------- m4xxed_v1 · 2022-02-01 03:33 I use jabref for reference management and it can write metadata from the bibtex entries in my bib file to the pdfs. I don't know whether it can do that in bulk, though. Maybe a starting point? ---------------------------------------------------------------------- art_else · 2022-02-01 10:45 Am looking for a way to edit metadata in pdfs as well, expected pdf- tools to have this aboard, but unfortunately it doesn't. You could try the wrapper around `exiftool` on Melpa. ---------------------------------------------------------------------- graduale · 2022-02-01 18:15 Ah I didn’t know there was such a thing. Thanks! ---------------------------------------------------------------------- graduale · 2022-02-01 18:35 Actually I can’t find the wrapper you mentioned. Any chance you can give me the name? ---------------------------------------------------------------------- art_else · 2022-02-01 20:47 [https://melpa.org/#/exiftool](https://melpa.org/#/exiftool) ;) I haven't worked with it yet myself, but `exiftool` itself is an amazing project. ---------------------------------------------------------------------- graduale · 2022-02-01 21:14 Hah. That's what you get from relying on search engines for this. (DuckDuckGo search for "emacs exiftool", at least, doesn't lead me to that page!) Thanks again! ---------------------------------------------------------------------- graduale · 2022-02-01 21:18 Hm, looks like it only works with JPEG files, sadly... I'll see if I can adapt something from it for my purposes, though. ---------------------------------------------------------------------- oantolin · 2022-02-01 23:39 In addition to exiftool, pdftk can also edit PDF metadata. ---------------------------------------------------------------------- art_else · 2022-02-02 21:29 Please report back when you got something. ---------------------------------------------------------------------- graduale · 2022-02-04 23:48 Nothing too fancy, but it's kind of working so far. There are a few issues still, especially with passing some markup to `exiftool`, but I'll put this here in case anyone can do something better with it. At the moment this relies on `citar`, since it's what I use. I'm looking to tag this on to a function for moving PDF files to the sole member of `citar-library-paths`, so that in moving the pdf and renaming it using the citation key, the metadata gets updated automatically... ```elisp (defun my/citar--update-pdf-metadata (key) "If KEY has a .pdf file associated with it, update its metadata information to include author and title values from the entry associated with KEY." (let* ((default-directory (file-truename (car citar-library-paths))) (entry (citar--get-entry key)) (author-metadata (cond ((citar-has-a-value '(author) entry) (concat "-Author=\"" (citar-get-value "author" entry) "\"")) ((citar-has-a-value '(editor) entry) (concat "-Author=\"" (citar-get-value "editor" entry) " (ed.)" "\"")))) (title-metadata (concat "-Title=\"" (cdr (assoc-string "title" (citar--get-entry key))) "\""))) (if (file-exists-p (concat key ".pdf")) (progn (copy-file (concat key ".pdf") "citar-library-backup/" 1) (shell-command (concat "exiftool " "-overwrite_original_in_place " author-metadata " " title-metadata " " key ".pdf"))) (print (concat "Could not find a file associated with key " key " in " default-directory)) ))) ``` ---------------------------------------------------------------------- art_else · 2022-02-19 23:45 Thanks, will give it a try, but likely will adapt to my needs. ---------------------------------------------------------------------- graduale · 2022-02-20 00:48 Let me know what you come up with!