Skip to content
Bruce D'Arcus edited this page Dec 26, 2021 · 22 revisions

pdf-tools integration

Search contents of PDFs

If you run this and select candidates, this will pass the list of any associated PDF files to pdf-tools to search across all of them. If you run embark-act-all on a filtered candidate list, it will pass the files associated with all of them.

image

(defun ex/search-pdf-contents (keys-entries &optional str)
  "Search pdfs."
  (interactive (list (citar-select-refs)))
  (let ((files (citar-file--files-for-multiple-entries
                (citar--ensure-entries keys-entries)
                citar-library-paths
                '("pdf")))
        (search-str (or str (read-string "Search string: "))))
    (pdf-occur-search files search-str t)))

;; with this, you can exploit embark's multitarget actions, so that you can run `embark-act-all`
(add-to-list 'embark-multitarget-actions #'ex/search-pdf-contents)

Add metadata to PDF files

This function will use the metadata from the entry and updated the PDF file metadata.

(defun ex/update-pdf-metadata (key-entry)
  "Add/update metadata of PDF for KEY-ENTRY."
  (interactive (list (citar-select-ref)))
  (let* ((entry (cdr key-entry))
         (key (car key-entry))
         (file (car (citar-file--files-for-entry
                     key
                     entry
                     citar-library-paths
                     '("pdf"))))
         (title (citar-clean-string (citar-get-value 'title entry)))
         (author (citar-get-value 'author entry)))
    (call-process-shell-command
     (concat "exiftool -Title='" title "' -Author='" author "' " file))))
Clone this wiki locally