vedang / pdf-tools

Emacs support library for PDF files.
https://pdftools.wiki
GNU General Public License v3.0
618 stars 89 forks source link

Editing annotations error: "epdfinfo: No such annotation: annot-X-Y" #246

Open mooseyboots opened 9 months ago

mooseyboots commented 9 months ago

Describe the bug Sometimes when i edit an annotation, I receive the error in the title and am unable to update the annotation's contents. Backtrace below.

My annotations are highlight/text type. I edit one by clicking on it.

I cannot yet discern what triggers this, and it does not always happen. I also find that if i keep annotating the pdf, then return later to the annotation, it will let me edit it. Again I'm unable to determine what makes the issue go away.

I understand if my bug report is too vague, I just thought to report in case anyone else encounters it and can narrow down the trigger.

I can't share the pdf at present as it is for a client, but I have encountered this with various pdfs.

Steps to Reproduce the behaviour Steps to reproduce the behaviour:

  1. Open a pdf
  2. Create highlight annotation: mark a region, then C-c C-a h (actually I use my binding, C to call pdf-annot-add-highlight-markup-annotation-and-copy-region defined below), create some text, then C-c C-c (pdf-annot-edit-contents-commit)
  3. Click on the annotation to edit it.
  4. Change the text, then C-c C-c (pdf-annot-edit-contents-commit) when done, error appears.

What is the expected behaviour? I expect the edited annotation to be modified (and the file to be saved)

Desktop Please complete the following information:

Your pdf-tools install Please complete the following information:

(defun pdf-annot-add-highlight-markup-annotation-and-copy-region ()
  "Copy text in region before creating a highlight annotation."
  (interactive)
  (progn
    (pdf-view-kill-ring-save-keep-region)
    (pdf-annot-add-highlight-markup-annotation (pdf-view-active-region))))

;; wrapper for save-buffer ignoring arguments
(defun mb/save-buffer-no-args ()
  "Save buffer ignoring arguments"
  (save-buffer))

;; save after adding comment
(with-eval-after-load "pdf-annot"
  (advice-add 'pdf-annot-edit-contents-commit :after 'mb/save-buffer-no-args))

(with-eval-after-load "pdf-annot"
  (define-key pdf-annot-edit-contents-minor-mode-map (kbd "C-c C-k") 'pdf-annot-edit-contents-abort))

Additional context the backtrace looks like so:

Debugger entered--Lisp error: (error "epdfinfo: No such annotation: annot-N-M")
  error("epdfinfo: %s" "No such annotation: annot-N-M")
  pdf-info-query(editannot "/path/to/my.pdf" annot-N-M contents "my edited annotation contents")
  pdf-info-editannot(annot-N-M ((contents . "my edited annotation contents")))
  pdf-annot-put(((buffer . #<buffer my.pdf>) (page . N) (edges 0.232997 0.463271 0.266634 0.481908) (type . highlight) (id . annot-N-M) (flags . 0) (color . "#fefe00") (contents . "my edited annotation contents") (modified 25984 6291) (label) (subject) (opacity . 1.0) (popup-edges) (popup-is-open) (created) (markup-edges (0.232997 0.463271 0.266634 0.481908))) contents "my edited annotation contents")
  pdf-annot-edit-contents-save-annotation()
  pdf-annot-edit-contents-finalize(t)
  #<subr pdf-annot-edit-contents-commit>()
  apply(#<subr pdf-annot-edit-contents-commit> nil)
  pdf-annot-edit-contents-commit()
  funcall-interactively(pdf-annot-edit-contents-commit)
  command-execute(pdf-annot-edit-contents-commit)
mooseyboots commented 7 months ago

I think clicking and dragging another region, then clicking to remove it, is what makes the issue go away such that I can edit the annotation.