pdf-tools icon indicating copy to clipboard operation
pdf-tools copied to clipboard

Support for other markup types with pdf-annot

Open sati-bodhi opened this issue 2 years ago • 5 comments

In pdf-annot-markup-annotation-types, we see a long list of "defined markup annotation types".

(text link free-text line square circle polygon poly-line highlight underline squiggly strike-out stamp caret ink file sound)

But only a few are "listed" and supported in pdf-annot-list-listed-types:

(text file squiggly highlight underline strike-out)

Just wondering if it is possible to extend the supported type at least to lines, squares and circles so that markup can be done more freely, especially when ocr (which most of the support types rely on) is not done or done poorly.

(add-to-list 'pdf-annot-list-listed-types 'square)

doesn't change anything, functionally speaking.

sati-bodhi avatar Jan 07 '23 06:01 sati-bodhi

I've check upstream and found this:

in epdfinfo.c:

  if (! strcmp (type, "highlight"))
    a = poppler_annot_text_markup_new_highlight (doc->pdf, r, garray);
  else if (! strcmp (type, "squiggly"))
    a = poppler_annot_text_markup_new_squiggly (doc->pdf, r, garray);
  else if (! strcmp (type, "strike-out"))
    a = poppler_annot_text_markup_new_strikeout (doc->pdf, r, garray);
  else if (! strcmp (type, "underline"))
    a = poppler_annot_text_markup_new_underline (doc->pdf, r, garray);
  else
    cerror_if_not (0, error_msg, "Unknown annotation type: %s", type);

It seems to me that this limitation is preset at the server level. But I wasn't able to reinstall the server to try it out.

sati-bodhi avatar Jan 08 '23 03:01 sati-bodhi

Other tweaks I've made:

In pdf-annot.el:

(defun pdf-annot-add-square-markup-annotation (list-of-edges
                                                  &optional color property-alist)
  "Add a new square annotation in the selected window.

LIST-OF-EDGES defines the annotation boundary. COLOR defines the
annotation color and PROPERTY-ALIST defines additional annotation
properties. See also `pdf-annot-add-markup-annotation'."
  (interactive (list (pdf-view-active-region t)))
  (pdf-annot-add-markup-annotation list-of-edges 'square color property-alist))

In pdf-info.el:

(defun pdf-info-creatable-annotation-types ()
  (let ((features (pdf-info-features)))
    (cond
     ((not (memq 'writable-annotations features)) nil)
     ((memq 'markup-annotations features)
      (list 'text 'squiggly 'underline 'strike-out 'highlight 'square))
     (t (list 'text)))))

sati-bodhi avatar Jan 08 '23 03:01 sati-bodhi

Would be great to have a rectangular box and simple lines. Both of these are defined by two points. All other extras don't seem that much useful.

vspinu avatar Jan 19 '23 12:01 vspinu

I think caret is also very useful to indicate omissions and missing words.

Knusper avatar Mar 05 '23 12:03 Knusper

it would be great also if there is freehand type of annotation, as sometimes you just want to mark a portion of a picture or when the pdf has watermark on it. it seems very distorted when adding highlight annotation

x0xntor33alx0x avatar Jun 08 '23 09:06 x0xntor33alx0x