I would like to capture the selected text (selected with the mouse) in a PDF document (opened in PDFView Mode) with an org capture template.

When I evaluate the expression (car (pdf-view-active-region-text)) with eval-expression, I can get this highlighted text.

However when I try to use it in a capture template like this:

(setq org-capture-templates
      '(("j" "Notes" entry (file+olp "~/Documents/wiki/Notes.org" "Notes")
         "* %?\n%(car (pdf-view-active-region-text))\n")))

I get:

%![Error: (error The region is not active)]

I use the pdf-tools support library.

  • Have you tried %i or %c instead of %(car (pdf-view-active-region-text))? Aug 7, 2019 at 11:57

1 Answer 1


You are in the *Capture* buffer during the execution of the Elisp code embedded in the template. Execute your code with the active buffer temporarily set to the original buffer. You get the original buffer from the plist variable org-capture-plist as property :original-buffer.

(defun org-capture-pdf-active-region ()
  "Capture the active region of the pdf-view buffer."
  (let* ((pdf-buf-name (plist-get org-capture-plist :original-buffer))
         (pdf-buf (get-buffer pdf-buf-name)))
    (if (buffer-live-p pdf-buf)
        (with-current-buffer pdf-buf
          (car (pdf-view-active-region-text)))
      (user-error "Buffer %S not alive." pdf-buf-name))))

(setq org-capture-templates
        ("j" "Notes" entry (file+olp "/temp/Notes.org" "Notes")
         "* %?\n%(org-capture-pdf-active-region)\n")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.