Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org-noter-create-skeleton fails: "epdfinfo: Expected a relative rectangle" #181

Open
benthamite opened this issue Nov 26, 2023 · 0 comments

Comments

@benthamite
Copy link

benthamite commented Nov 26, 2023

After starting org-noter, invoking org-noter-create-skeleton, and selecting "Annotations", "Highlights" and "DONE", the process fails with the following error:

pdf-info-query: epdfinfo: Expected a relative rectangle: -5592405.330729 -1084587.0328283333 5592405.330729 1084588.0343433334

This happens only with a specific PDF; the highlights export fine in all the other files I tried.

The backtrace and some comments from GPT-4 follow, in case they help someone with better elisp skills diagnose the problem.

Backtrace

Debugger entered--Lisp error: (error "epdfinfo: Expected a relative rectangle: -5592405.330729 -1084587.0328283333 5592405.330729 1084588.0343433334")
error("epdfinfo: %s" "Expected a relative rectangle: -5592405.330729 -1084587.0328283333 5592405.330729 1084588.0343433334")
pdf-info-query(gettext "/Users/pablostafforini/Google Drive/library-pdf/Burns2009GoddessMarketAyn.pdf" 121 "-5592405.330729 -1084587.0328283333 5592405.330729 1084588.0343433334" 0)
pdf-info-gettext(121 (-5592405.330729 -1084587.0328283333 5592405.330729 1084588.0343433334))
(cons (pdf-info-gettext page edges) (and (or (and item-subject (> (length item-subject) 0)) (and item-contents (> (length item-contents) 0))) (concat (or item-subject "") (if (and item-subject item-contents) "\n" "") (or item-contents ""))))
(setq contents (cons (pdf-info-gettext page edges) (and (or (and item-subject (> (length item-subject) 0)) (and item-contents (> (length item-contents) 0))) (concat (or item-subject "") (if (and item-subject item-contents) "\n" "") (or item-contents "")))))
(progn (setq contents (cons (pdf-info-gettext page edges) (and (or (and item-subject (> (length item-subject) 0)) (and item-contents (> (length item-contents) 0))) (concat (or item-subject "") (if (and item-subject item-contents) "\n" "") (or item-contents ""))))))
(if insert-contents (progn (setq contents (cons (pdf-info-gettext page edges) (and (or (and item-subject (> (length item-subject) 0)) (and item-contents (> (length item-contents) 0))) (concat (or item-subject "") (if (and item-subject item-contents) "\n" "") (or item-contents "")))))))
(if (eq type 'link) (let* ((var page)) (if (memql var pages-with-links) (with-no-warnings pages-with-links) (setq pages-with-links (cons var pages-with-links)))) (setq name (cond ((eq type 'highlight) "Highlight") ((eq type 'underline) "Underline") ((eq type 'squiggly) "Squiggly") ((eq type 'text) "Text note") ((eq type 'strike-out) "Strikeout"))) (if insert-contents (progn (setq contents (cons (pdf-info-gettext page edges) (and (or (and item-subject (> (length item-subject) 0)) (and item-contents (> (length item-contents) 0))) (concat (or item-subject "") (if (and item-subject item-contents) "\n" "") (or item-contents ""))))))) (setq output-data (cons (vector (format "%s on page %d" name page) (cons page top) 'inside contents) output-data)))
(progn (if (eq type 'link) (let* ((var page)) (if (memql var pages-with-links) (with-no-warnings pages-with-links) (setq pages-with-links (cons var pages-with-links)))) (setq name (cond ((eq type 'highlight) "Highlight") ((eq type 'underline) "Underline") ((eq type 'squiggly) "Squiggly") ((eq type 'text) "Text note") ((eq type 'strike-out) "Strikeout"))) (if insert-contents (progn (setq contents (cons (pdf-info-gettext page edges) (and (or (and item-subject (> (length item-subject) 0)) (and item-contents (> (length item-contents) 0))) (concat (or item-subject "") (if (and item-subject item-contents) "\n" "") (or item-contents ""))))))) (setq output-data (cons (vector (format "%s on page %d" name page) (cons page top) 'inside contents) output-data))))
(if (and (memq type chosen-annots) (> page 0)) (progn (if (eq type 'link) (let* ((var page)) (if (memql var pages-with-links) (with-no-warnings pages-with-links) (setq pages-with-links (cons var pages-with-links)))) (setq name (cond ((eq type 'highlight) "Highlight") ((eq type 'underline) "Underline") ((eq type 'squiggly) "Squiggly") ((eq type 'text) "Text note") ((eq type 'strike-out) "Strikeout"))) (if insert-contents (progn (setq contents (cons (pdf-info-gettext page edges) (and (or (and item-subject (> (length item-subject) 0)) (and item-contents (> (length item-contents) 0))) (concat (or item-subject "") (if (and item-subject item-contents) "\n" "") (or item-contents ""))))))) (setq output-data (cons (vector (format "%s on page %d" name page) (cons page top) 'inside contents) output-data)))))
(let* ((type (alist-get 'type item)) (page (alist-get 'page item)) (edges (or (org-noter-pdf--edges-to-region (alist-get 'markup-edges item)) (alist-get 'edges item))) (top (nth 1 edges)) (item-subject (alist-get 'subject item)) (item-contents (alist-get 'contents item)) name contents) (if (and (memq type chosen-annots) (> page 0)) (progn (if (eq type 'link) (let* ((var page)) (if (memql var pages-with-links) (with-no-warnings pages-with-links) (setq pages-with-links (cons var pages-with-links)))) (setq name (cond ((eq type 'highlight) "Highlight") ((eq type 'underline) "Underline") ((eq type 'squiggly) "Squiggly") ((eq type 'text) "Text note") ((eq type 'strike-out) "Strikeout"))) (if insert-contents (progn (setq contents (cons (pdf-info-gettext page edges) (and (or (and item-subject (> (length item-subject) 0)) (and item-contents (> (length item-contents) 0))) (concat (or item-subject "") (if (and item-subject item-contents) "\n" "") (or item-contents ""))))))) (setq output-data (cons (vector (format "%s on page %d" name page) (cons page top) 'inside contents) output-data))))))
(let ((item (car tail))) (let* ((type (alist-get 'type item)) (page (alist-get 'page item)) (edges (or (org-noter-pdf--edges-to-region (alist-get 'markup-edges item)) (alist-get 'edges item))) (top (nth 1 edges)) (item-subject (alist-get 'subject item)) (item-contents (alist-get 'contents item)) name contents) (if (and (memq type chosen-annots) (> page 0)) (progn (if (eq type 'link) (let* ((var page)) (if (memql var pages-with-links) (with-no-warnings pages-with-links) (setq pages-with-links (cons var pages-with-links)))) (setq name (cond ((eq type 'highlight) "Highlight") ((eq type 'underline) "Underline") ((eq type 'squiggly) "Squiggly") ((eq type 'text) "Text note") ((eq type 'strike-out) "Strikeout"))) (if insert-contents (progn (setq contents (cons (pdf-info-gettext page edges) (and (or (and item-subject (> (length item-subject) 0)) (and item-contents (> (length item-contents) 0))) (concat (or item-subject "") (if (and item-subject item-contents) "\n" "") (or item-contents ""))))))) (setq output-data (cons (vector (format "%s on page %d" name page) (cons page top) 'inside contents) output-data)))))) (setq tail (cdr tail)))
(while tail (let ((item (car tail))) (let* ((type (alist-get 'type item)) (page (alist-get 'page item)) (edges (or (org-noter-pdf--edges-to-region (alist-get 'markup-edges item)) (alist-get 'edges item))) (top (nth 1 edges)) (item-subject (alist-get 'subject item)) (item-contents (alist-get 'contents item)) name contents) (if (and (memq type chosen-annots) (> page 0)) (progn (if (eq type 'link) (let* ((var page)) (if (memql var pages-with-links) (with-no-warnings pages-with-links) (setq pages-with-links (cons var pages-with-links)))) (setq name (cond ((eq type 'highlight) "Highlight") ((eq type 'underline) "Underline") ((eq type 'squiggly) "Squiggly") ((eq type 'text) "Text note") ((eq type 'strike-out) "Strikeout"))) (if insert-contents (progn (setq contents (cons (pdf-info-gettext page edges) (and (or (and item-subject (> (length item-subject) 0)) (and item-contents (> (length item-contents) 0))) (concat (or item-subject "") (if (and item-subject item-contents) "\n" "") (or item-contents ""))))))) (setq output-data (cons (vector (format "%s on page %d" name page) (cons page top) 'inside contents) output-data)))))) (setq tail (cdr tail))))
(let ((tail (pdf-info-getannots))) (while tail (let ((item (car tail))) (let* ((type (alist-get 'type item)) (page (alist-get 'page item)) (edges (or (org-noter-pdf--edges-to-region (alist-get 'markup-edges item)) (alist-get 'edges item))) (top (nth 1 edges)) (item-subject (alist-get 'subject item)) (item-contents (alist-get 'contents item)) name contents) (if (and (memq type chosen-annots) (> page 0)) (progn (if (eq type 'link) (let* ((var page)) (if (memql var pages-with-links) (with-no-warnings pages-with-links) (setq pages-with-links (cons var pages-with-links)))) (setq name (cond ((eq type 'highlight) "Highlight") ((eq type 'underline) "Underline") ((eq type 'squiggly) "Squiggly") ((eq type 'text) "Text note") ((eq type 'strike-out) "Strikeout"))) (if insert-contents (progn (setq contents (cons (pdf-info-gettext page edges) (and (or (and item-subject (> (length item-subject) 0)) (and item-contents (> (length item-contents) 0))) (concat (or item-subject "") (if (and item-subject item-contents) "\n" "") (or item-contents ""))))))) (setq output-data (cons (vector (format "%s on page %d" name page) (cons page top) 'inside contents) output-data)))))) (setq tail (cdr tail)))))
(let ((possible-annots (list '("Highlights" . highlight) '("Underlines" . underline) '("Squigglies" . squiggly) '("Text notes" . text) '("Strikeouts" . strike-out) '("Links" . link) '("ALL" . all))) chosen-annots insert-contents pages-with-links) (while (> (length possible-annots) 1) (let* ((chosen-string (completing-read "Which types of annotations do you want? " possible-annots nil t)) (chosen-pair (assoc chosen-string possible-annots))) (cond ((eq (cdr chosen-pair) 'all) (let ((tail possible-annots)) (while tail (let ((annot (car tail))) (if (and (cdr annot) (not (eq (cdr annot) 'all))) (progn (setq chosen-annots (cons (cdr annot) chosen-annots)))) (setq tail (cdr tail))))) (setq possible-annots nil)) ((cdr chosen-pair) (setq chosen-annots (cons (cdr chosen-pair) chosen-annots)) (setq possible-annots (delq chosen-pair possible-annots)) (if (= 1 (length chosen-annots)) (progn (setq possible-annots (cons '("DONE") possible-annots))))) (t (setq possible-annots nil))))) (setq insert-contents (y-or-n-p "Should we insert the annotations contents? ")) (let ((tail (pdf-info-getannots))) (while tail (let ((item (car tail))) (let* ((type (alist-get 'type item)) (page (alist-get 'page item)) (edges (or (org-noter-pdf--edges-to-region (alist-get 'markup-edges item)) (alist-get 'edges item))) (top (nth 1 edges)) (item-subject (alist-get 'subject item)) (item-contents (alist-get 'contents item)) name contents) (if (and (memq type chosen-annots) (> page 0)) (progn (if (eq type 'link) (let* ((var page)) (if (memql var pages-with-links) (with-no-warnings pages-with-links) (setq pages-with-links (cons var pages-with-links)))) (setq name (cond ((eq type 'highlight) "Highlight") ((eq type 'underline) "Underline") ((eq type 'squiggly) "Squiggly") ((eq type 'text) "Text note") ((eq type 'strike-out) "Strikeout"))) (if insert-contents (progn (setq contents (cons (pdf-info-gettext page edges) (and (or (and item-subject (> (length item-subject) 0)) (and item-contents (> (length item-contents) 0))) (concat (or item-subject "") (if (and item-subject item-contents) "\n" "") (or item-contents ""))))))) (setq output-data (cons (vector (format "%s on page %d" name page) (cons page top) 'inside contents) output-data)))))) (setq tail (cdr tail))))) (let ((tail pages-with-links)) (while tail (let ((page (car tail))) (let ((links (pdf-info-pagelinks page)) type) (let ((tail links)) (while tail (let ((link (car tail))) (setq type (alist-get 'type link)) (if (eq type 'goto-dest) nil (let* ((edges (alist-get 'edges link)) (title (alist-get 'title link)) (top (nth 1 edges)) (target-page (alist-get 'page link)) target heading-text) (if (and title (> (length title) 0)) nil (setq title (pdf-info-gettext page edges))) (cond ((eq type 'uri) (progn (setq target (alist-get 'uri link)) (setq heading-text (format "Link on page %d: [[%s][%s]]" page target title)))) ((eq type 'goto-remote) (progn (setq target (concat "file:" (alist-get 'filename link))) (setq heading-text (format "Link to document on page %d: [[%s][%s]]" page target title))) (if target-page (progn (setq heading-text (concat heading-text (format " (target page: %d)" target-page)))))) (t (error "Unexpected link type"))) (setq output-data (cons (vector heading-text (cons page top) 'inside nil) output-data)))) (setq tail (cdr tail)))))) (setq tail (cdr tail))))))
(progn (let ((possible-annots (list '("Highlights" . highlight) '("Underlines" . underline) '("Squigglies" . squiggly) '("Text notes" . text) '("Strikeouts" . strike-out) '("Links" . link) '("ALL" . all))) chosen-annots insert-contents pages-with-links) (while (> (length possible-annots) 1) (let* ((chosen-string (completing-read "Which types of annotations do you want? " possible-annots nil t)) (chosen-pair (assoc chosen-string possible-annots))) (cond ((eq (cdr chosen-pair) 'all) (let ((tail possible-annots)) (while tail (let ((annot (car tail))) (if (and (cdr annot) (not (eq (cdr annot) 'all))) (progn (setq chosen-annots (cons (cdr annot) chosen-annots)))) (setq tail (cdr tail))))) (setq possible-annots nil)) ((cdr chosen-pair) (setq chosen-annots (cons (cdr chosen-pair) chosen-annots)) (setq possible-annots (delq chosen-pair possible-annots)) (if (= 1 (length chosen-annots)) (progn (setq possible-annots (cons '("DONE") possible-annots))))) (t (setq possible-annots nil))))) (setq insert-contents (y-or-n-p "Should we insert the annotations contents? ")) (let ((tail (pdf-info-getannots))) (while tail (let ((item (car tail))) (let* ((type (alist-get 'type item)) (page (alist-get 'page item)) (edges (or (org-noter-pdf--edges-to-region (alist-get 'markup-edges item)) (alist-get 'edges item))) (top (nth 1 edges)) (item-subject (alist-get 'subject item)) (item-contents (alist-get 'contents item)) name contents) (if (and (memq type chosen-annots) (> page 0)) (progn (if (eq type 'link) (let* ((var page)) (if (memql var pages-with-links) (with-no-warnings pages-with-links) (setq pages-with-links (cons var pages-with-links)))) (setq name (cond ((eq type 'highlight) "Highlight") ((eq type 'underline) "Underline") ((eq type 'squiggly) "Squiggly") ((eq type 'text) "Text note") ((eq type 'strike-out) "Strikeout"))) (if insert-contents (progn (setq contents (cons (pdf-info-gettext page edges) (and (or (and item-subject (> (length item-subject) 0)) (and item-contents (> (length item-contents) 0))) (concat (or item-subject "") (if (and item-subject item-contents) "\n" "") (or item-contents ""))))))) (setq output-data (cons (vector (format "%s on page %d" name page) (cons page top) 'inside contents) output-data)))))) (setq tail (cdr tail))))) (let ((tail pages-with-links)) (while tail (let ((page (car tail))) (let ((links (pdf-info-pagelinks page)) type) (let ((tail links)) (while tail (let ((link (car tail))) (setq type (alist-get 'type link)) (if (eq type 'goto-dest) nil (let* ((edges (alist-get 'edges link)) (title (alist-get 'title link)) (top (nth 1 edges)) (target-page (alist-get 'page link)) target heading-text) (if (and title (> (length title) 0)) nil (setq title (pdf-info-gettext page edges))) (cond ((eq type 'uri) (progn (setq target (alist-get 'uri link)) (setq heading-text (format "Link on page %d: [[%s][%s]]" page target title)))) ((eq type 'goto-remote) (progn (setq target (concat "file:" (alist-get 'filename link))) (setq heading-text (format "Link to document on page %d: [[%s][%s]]" page target title))) (if target-page (progn (setq heading-text (concat heading-text (format " (target page: %d)" target-page)))))) (t (error "Unexpected link type"))) (setq output-data (cons (vector heading-text (cons page top) 'inside nil) output-data)))) (setq tail (cdr tail)))))) (setq tail (cdr tail)))))))
(if (memq 'annots answer) (progn (let ((possible-annots (list '("Highlights" . highlight) '("Underlines" . underline) '("Squigglies" . squiggly) '("Text notes" . text) '("Strikeouts" . strike-out) '("Links" . link) '("ALL" . all))) chosen-annots insert-contents pages-with-links) (while (> (length possible-annots) 1) (let* ((chosen-string (completing-read "Which types of annotations do you want? " possible-annots nil t)) (chosen-pair (assoc chosen-string possible-annots))) (cond ((eq (cdr chosen-pair) 'all) (let ((tail possible-annots)) (while tail (let ((annot (car tail))) (if (and (cdr annot) (not (eq (cdr annot) 'all))) (progn (setq chosen-annots (cons (cdr annot) chosen-annots)))) (setq tail (cdr tail))))) (setq possible-annots nil)) ((cdr chosen-pair) (setq chosen-annots (cons (cdr chosen-pair) chosen-annots)) (setq possible-annots (delq chosen-pair possible-annots)) (if (= 1 (length chosen-annots)) (progn (setq possible-annots (cons '("DONE") possible-annots))))) (t (setq possible-annots nil))))) (setq insert-contents (y-or-n-p "Should we insert the annotations contents? ")) (let ((tail (pdf-info-getannots))) (while tail (let ((item (car tail))) (let* ((type (alist-get 'type item)) (page (alist-get 'page item)) (edges (or (org-noter-pdf--edges-to-region (alist-get 'markup-edges item)) (alist-get 'edges item))) (top (nth 1 edges)) (item-subject (alist-get 'subject item)) (item-contents (alist-get 'contents item)) name contents) (if (and (memq type chosen-annots) (> page 0)) (progn (if (eq type 'link) (let* ((var page)) (if (memql var pages-with-links) (with-no-warnings pages-with-links) (setq pages-with-links (cons var pages-with-links)))) (setq name (cond ((eq type 'highlight) "Highlight") ((eq type 'underline) "Underline") ((eq type 'squiggly) "Squiggly") ((eq type 'text) "Text note") ((eq type 'strike-out) "Strikeout"))) (if insert-contents (progn (setq contents (cons (pdf-info-gettext page edges) (and (or (and item-subject (> (length item-subject) 0)) (and item-contents (> (length item-contents) 0))) (concat (or item-subject "") (if (and item-subject item-contents) "\n" "") (or item-contents ""))))))) (setq output-data (cons (vector (format "%s on page %d" name page) (cons page top) 'inside contents) output-data)))))) (setq tail (cdr tail))))) (let ((tail pages-with-links)) (while tail (let ((page (car tail))) (let ((links (pdf-info-pagelinks page)) type) (let ((tail links)) (while tail (let ((link (car tail))) (setq type (alist-get 'type link)) (if (eq type 'goto-dest) nil (let* ((edges (alist-get 'edges link)) (title (alist-get 'title link)) (top (nth 1 edges)) (target-page (alist-get 'page link)) target heading-text) (if (and title (> (length title) 0)) nil (setq title (pdf-info-gettext page edges))) (cond ((eq type 'uri) (progn (setq target (alist-get 'uri link)) (setq heading-text (format "Link on page %d: [[%s][%s]]" page target title)))) ((eq type 'goto-remote) (progn (setq target (concat "file:" (alist-get 'filename link))) (setq heading-text (format "Link to document on page %d: [[%s][%s]]" page target title))) (if target-page (progn (setq heading-text (concat heading-text (format " (target page: %d)" target-page)))))) (t (error "Unexpected link type"))) (setq output-data (cons (vector heading-text (cons page top) 'inside nil) output-data)))) (setq tail (cdr tail)))))) (setq tail (cdr tail))))))))
(save-current-buffer (set-buffer (let* ((cl-x session)) (progn (or (let* ((cl-x cl-x)) (progn (and (memq (type-of cl-x) cl-struct-org-noter--session-tags) t))) (signal 'wrong-type-argument (list 'org-noter--session cl-x))) (aref cl-x 3)))) (setq answer (assoc (completing-read "What do you want to import? " options nil t) options)) (if (memq 'outline answer) (progn (let ((tail (pdf-info-outline))) (while tail (let ((item (car tail))) (let ((type (alist-get 'type item)) (page (alist-get 'page item)) (depth (alist-get 'depth item)) (title (alist-get 'title item)) (top (alist-get 'top item))) (if (and (eq type 'goto-dest) (> page 0)) (progn (setq output-data (cons (vector title (cons page top) (1+ depth) nil) output-data))))) (setq tail (cdr tail))))))) (if (memq 'annots answer) (progn (let ((possible-annots (list '("Highlights" . highlight) '("Underlines" . underline) '("Squigglies" . squiggly) '("Text notes" . text) '("Strikeouts" . strike-out) '("Links" . link) '("ALL" . all))) chosen-annots insert-contents pages-with-links) (while (> (length possible-annots) 1) (let* ((chosen-string (completing-read "Which types of annotations do you want? " possible-annots nil t)) (chosen-pair (assoc chosen-string possible-annots))) (cond ((eq (cdr chosen-pair) 'all) (let ((tail possible-annots)) (while tail (let ((annot (car tail))) (if (and (cdr annot) (not (eq (cdr annot) 'all))) (progn (setq chosen-annots (cons (cdr annot) chosen-annots)))) (setq tail (cdr tail))))) (setq possible-annots nil)) ((cdr chosen-pair) (setq chosen-annots (cons (cdr chosen-pair) chosen-annots)) (setq possible-annots (delq chosen-pair possible-annots)) (if (= 1 (length chosen-annots)) (progn (setq possible-annots (cons '("DONE") possible-annots))))) (t (setq possible-annots nil))))) (setq insert-contents (y-or-n-p "Should we insert the annotations contents? ")) (let ((tail (pdf-info-getannots))) (while tail (let ((item (car tail))) (let* ((type (alist-get 'type item)) (page (alist-get 'page item)) (edges (or (org-noter-pdf--edges-to-region (alist-get 'markup-edges item)) (alist-get 'edges item))) (top (nth 1 edges)) (item-subject (alist-get 'subject item)) (item-contents (alist-get 'contents item)) name contents) (if (and (memq type chosen-annots) (> page 0)) (progn (if (eq type 'link) (let* ((var page)) (if (memql var pages-with-links) (with-no-warnings pages-with-links) (setq pages-with-links (cons var pages-with-links)))) (setq name (cond ((eq type 'highlight) "Highlight") ((eq type 'underline) "Underline") ((eq type 'squiggly) "Squiggly") ((eq type 'text) "Text note") ((eq type 'strike-out) "Strikeout"))) (if insert-contents (progn (setq contents (cons (pdf-info-gettext page edges) (and (or (and item-subject (> (length item-subject) 0)) (and item-contents (> (length item-contents) 0))) (concat (or item-subject "") (if (and item-subject item-contents) "\n" "") (or item-contents ""))))))) (setq output-data (cons (vector (format "%s on page %d" name page) (cons page top) 'inside contents) output-data)))))) (setq tail (cdr tail))))) (let ((tail pages-with-links)) (while tail (let ((page (car tail))) (let ((links (pdf-info-pagelinks page)) type) (let ((tail links)) (while tail (let ((link (car tail))) (setq type (alist-get 'type link)) (if (eq type 'goto-dest) nil (let* ((edges (alist-get 'edges link)) (title (alist-get 'title link)) (top (nth 1 edges)) (target-page (alist-get 'page link)) target heading-text) (if (and title (> (length title) 0)) nil (setq title (pdf-info-gettext page edges))) (cond ((eq type 'uri) (progn (setq target (alist-get 'uri link)) (setq heading-text (format "Link on page %d: [[%s][%s]]" page target title)))) ((eq type 'goto-remote) (progn (setq target (concat "file:" (alist-get 'filename link))) (setq heading-text (format "Link to document on page %d: [[%s][%s]]" page target title))) (if target-page (progn (setq heading-text (concat heading-text (format " (target page: %d)" target-page)))))) (t (error "Unexpected link type"))) (setq output-data (cons (vector heading-text (cons page top) 'inside nil) output-data)))) (setq tail (cdr tail)))))) (setq tail (cdr tail)))))))) (if output-data (progn (if (memq 'annots answer) (setq output-data (sort output-data #'(lambda (e1 e2) (or (not (aref e1 1)) (and (aref e2 1) (org-noter--compare-locations '< (aref e1 1) (aref e2 1))))))) (setq output-data (nreverse output-data))) (setq output-data (cons (vector "Skeleton" nil 1 nil) output-data)))))
(let* ((ast (org-noter--parse-root)) (top-level (or (org-element--property :level ast nil nil) 0)) (options '(("Outline" outline) ("Annotations" annots) ("Both" outline annots))) answer output-data) (save-current-buffer (set-buffer (let* ((cl-x session)) (progn (or (let* ((cl-x cl-x)) (progn (and (memq (type-of cl-x) cl-struct-org-noter--session-tags) t))) (signal 'wrong-type-argument (list 'org-noter--session cl-x))) (aref cl-x 3)))) (setq answer (assoc (completing-read "What do you want to import? " options nil t) options)) (if (memq 'outline answer) (progn (let ((tail (pdf-info-outline))) (while tail (let ((item (car tail))) (let ((type (alist-get 'type item)) (page (alist-get 'page item)) (depth (alist-get 'depth item)) (title (alist-get 'title item)) (top (alist-get 'top item))) (if (and (eq type 'goto-dest) (> page 0)) (progn (setq output-data (cons (vector title (cons page top) (1+ depth) nil) output-data))))) (setq tail (cdr tail))))))) (if (memq 'annots answer) (progn (let ((possible-annots (list '("Highlights" . highlight) '("Underlines" . underline) '("Squigglies" . squiggly) '("Text notes" . text) '("Strikeouts" . strike-out) '("Links" . link) '("ALL" . all))) chosen-annots insert-contents pages-with-links) (while (> (length possible-annots) 1) (let* ((chosen-string (completing-read "Which types of annotations do you want? " possible-annots nil t)) (chosen-pair (assoc chosen-string possible-annots))) (cond ((eq (cdr chosen-pair) 'all) (let ((tail possible-annots)) (while tail (let ((annot (car tail))) (if (and (cdr annot) (not (eq (cdr annot) 'all))) (progn (setq chosen-annots (cons (cdr annot) chosen-annots)))) (setq tail (cdr tail))))) (setq possible-annots nil)) ((cdr chosen-pair) (setq chosen-annots (cons (cdr chosen-pair) chosen-annots)) (setq possible-annots (delq chosen-pair possible-annots)) (if (= 1 (length chosen-annots)) (progn (setq possible-annots (cons '("DONE") possible-annots))))) (t (setq possible-annots nil))))) (setq insert-contents (y-or-n-p "Should we insert the annotations contents? ")) (let ((tail (pdf-info-getannots))) (while tail (let ((item (car tail))) (let* ((type (alist-get 'type item)) (page (alist-get 'page item)) (edges (or (org-noter-pdf--edges-to-region (alist-get 'markup-edges item)) (alist-get 'edges item))) (top (nth 1 edges)) (item-subject (alist-get 'subject item)) (item-contents (alist-get 'contents item)) name contents) (if (and (memq type chosen-annots) (> page 0)) (progn (if (eq type 'link) (let* ((var page)) (if (memql var pages-with-links) (with-no-warnings pages-with-links) (setq pages-with-links (cons var pages-with-links)))) (setq name (cond ((eq type 'highlight) "Highlight") ((eq type 'underline) "Underline") ((eq type 'squiggly) "Squiggly") ((eq type 'text) "Text note") ((eq type 'strike-out) "Strikeout"))) (if insert-contents (progn (setq contents (cons (pdf-info-gettext page edges) (and (or (and item-subject (> (length item-subject) 0)) (and item-contents (> (length item-contents) 0))) (concat (or item-subject "") (if (and item-subject item-contents) "\n" "") (or item-contents ""))))))) (setq output-data (cons (vector (format "%s on page %d" name page) (cons page top) 'inside contents) output-data)))))) (setq tail (cdr tail))))) (let ((tail pages-with-links)) (while tail (let ((page (car tail))) (let ((links (pdf-info-pagelinks page)) type) (let ((tail links)) (while tail (let ((link (car tail))) (setq type (alist-get 'type link)) (if (eq type 'goto-dest) nil (let* ((edges (alist-get 'edges link)) (title (alist-get 'title link)) (top (nth 1 edges)) (target-page (alist-get 'page link)) target heading-text) (if (and title (> (length title) 0)) nil (setq title (pdf-info-gettext page edges))) (cond ((eq type 'uri) (progn (setq target (alist-get 'uri link)) (setq heading-text (format "Link on page %d: [[%s][%s]]" page target title)))) ((eq type 'goto-remote) (progn (setq target (concat "file:" (alist-get 'filename link))) (setq heading-text (format "Link to document on page %d: [[%s][%s]]" page target title))) (if target-page (progn (setq heading-text (concat heading-text (format " (target page: %d)" target-page)))))) (t (error "Unexpected link type"))) (setq output-data (cons (vector heading-text (cons page top) 'inside nil) output-data)))) (setq tail (cdr tail)))))) (setq tail (cdr tail)))))))) (if output-data (progn (if (memq 'annots answer) (setq output-data (sort output-data #'(lambda (e1 e2) (or (not (aref e1 1)) (and (aref e2 1) (org-noter--compare-locations '< (aref e1 1) (aref e2 1))))))) (setq output-data (nreverse output-data))) (setq output-data (cons (vector "Skeleton" nil 1 nil) output-data))))) (save-current-buffer (set-buffer (let* ((cl-x session)) (progn (or (let* ((cl-x cl-x)) (progn (and (memq (type-of cl-x) cl-struct-org-noter--session-tags) t))) (signal 'wrong-type-argument (list 'org-noter--session cl-x))) (aref cl-x 4)))) (widen) (save-excursion (goto-char (let* ((parray (and t (let* ((val (org-element-type ast))) (cond ((null val) 'nil) ((eq val 'plain-text) 'nil) (t (let nil (if (eq :standard-properties (car (nth 1 ast))) (car (cdr (nth 1 ast))) (plist-get (nth 1 ast) :standard-properties))))))))) (if parray (let* ((val (aref parray 4))) (if (eq val 'org-element-ast--nil) 'nil (let ((val val)) val))) (let* ((val (org-element-type ast))) (cond ((null val) 'nil) ((eq val 'plain-text) (let nil (or (get-text-property 0 :end ast) (if nil (progn (if (with-no-warnings (plist-member (text-properties-at 0 ast) :end)) nil nil)))))) (t (let nil (or (plist-get (nth 1 ast) :end) (if nil (progn (if (with-no-warnings (plist-member (nth 1 ast) :end)) nil nil))))))))))) (let (last-absolute-level title location relative-level contents level) (let ((tail output-data)) (while tail (let ((data (car tail))) (progn (setq title (aref data 0)) (setq location (aref data 1)) (setq relative-level (aref data 2)) (setq contents (aref data 3))) (if (symbolp relative-level) (setq level (1+ last-absolute-level)) (progn (setq last-absolute-level (+ top-level relative-level)) (setq level last-absolute-level))) (org-noter--insert-heading level title) (if location (progn (org-entry-put nil org-noter-property-note-location (org-noter--pretty-print-location location)))) (if org-noter-doc-property-in-notes (progn (org-entry-put nil org-noter-property-doc-file (let* ((cl-x session)) (progn (or (let* ((cl-x cl-x)) (progn (and (memq (type-of cl-x) cl-struct-org-noter--session-tags) t))) (signal 'wrong-type-argument (list 'org-noter--session cl-x))) (aref cl-x 10)))) (org-entry-put nil org-noter--property-auto-save-last-location "nil"))) (if (car contents) (progn (org-noter--insert-heading (1+ level) "Contents") (insert (car contents)))) (if (cdr contents) (progn (org-noter--insert-heading (1+ level) "Comment") (insert (cdr contents)))) (setq tail (cdr tail)))))) (setq ast (org-noter--parse-root)) (org-noter--narrow-to-root ast) (goto-char (let* ((parray (and t (let* ((val (org-element-type ast))) (cond ((null val) 'nil) ((eq val 'plain-text) 'nil) (t (let nil (if (eq :standard-properties (car (nth 1 ast))) (car (cdr (nth 1 ast))) (plist-get (nth 1 ast) :standard-properties))))))))) (if parray (let* ((val (aref parray 0))) (if (eq val 'org-element-ast--nil) 'nil (let ((val val)) val))) (let* ((val (org-element-type ast))) (cond ((null val) 'nil) ((eq val 'plain-text) (let nil (or (get-text-property 0 :begin ast) (if nil (progn (if (with-no-warnings (plist-member (text-properties-at 0 ast) :begin)) nil nil)))))) (t (let nil (or (plist-get (nth 1 ast) :begin) (if nil (progn (if (with-no-warnings (plist-member (nth 1 ast) :begin)) nil nil))))))))))) (outline-hide-subtree) (org-show-children 2))) output-data)
(progn (let* ((ast (org-noter--parse-root)) (top-level (or (org-element--property :level ast nil nil) 0)) (options '(("Outline" outline) ("Annotations" annots) ("Both" outline annots))) answer output-data) (save-current-buffer (set-buffer (let* ((cl-x session)) (progn (or (let* ((cl-x cl-x)) (progn (and (memq (type-of cl-x) cl-struct-org-noter--session-tags) t))) (signal 'wrong-type-argument (list 'org-noter--session cl-x))) (aref cl-x 3)))) (setq answer (assoc (completing-read "What do you want to import? " options nil t) options)) (if (memq 'outline answer) (progn (let ((tail (pdf-info-outline))) (while tail (let ((item (car tail))) (let ((type (alist-get 'type item)) (page (alist-get 'page item)) (depth (alist-get 'depth item)) (title (alist-get 'title item)) (top (alist-get 'top item))) (if (and (eq type 'goto-dest) (> page 0)) (progn (setq output-data (cons (vector title (cons page top) (1+ depth) nil) output-data))))) (setq tail (cdr tail))))))) (if (memq 'annots answer) (progn (let ((possible-annots (list '("Highlights" . highlight) '("Underlines" . underline) '("Squigglies" . squiggly) '("Text notes" . text) '("Strikeouts" . strike-out) '("Links" . link) '("ALL" . all))) chosen-annots insert-contents pages-with-links) (while (> (length possible-annots) 1) (let* ((chosen-string (completing-read "Which types of annotations do you want? " possible-annots nil t)) (chosen-pair (assoc chosen-string possible-annots))) (cond ((eq (cdr chosen-pair) 'all) (let ((tail possible-annots)) (while tail (let ((annot (car tail))) (if (and (cdr annot) (not (eq (cdr annot) 'all))) (progn (setq chosen-annots (cons (cdr annot) chosen-annots)))) (setq tail (cdr tail))))) (setq possible-annots nil)) ((cdr chosen-pair) (setq chosen-annots (cons (cdr chosen-pair) chosen-annots)) (setq possible-annots (delq chosen-pair possible-annots)) (if (= 1 (length chosen-annots)) (progn (setq possible-annots (cons '("DONE") possible-annots))))) (t (setq possible-annots nil))))) (setq insert-contents (y-or-n-p "Should we insert the annotations contents? ")) (let ((tail (pdf-info-getannots))) (while tail (let ((item (car tail))) (let* ((type (alist-get 'type item)) (page (alist-get 'page item)) (edges (or (org-noter-pdf--edges-to-region (alist-get 'markup-edges item)) (alist-get 'edges item))) (top (nth 1 edges)) (item-subject (alist-get 'subject item)) (item-contents (alist-get 'contents item)) name contents) (if (and (memq type chosen-annots) (> page 0)) (progn (if (eq type 'link) (let* ((var page)) (if (memql var pages-with-links) (with-no-warnings pages-with-links) (setq pages-with-links (cons var pages-with-links)))) (setq name (cond ((eq type 'highlight) "Highlight") ((eq type 'underline) "Underline") ((eq type 'squiggly) "Squiggly") ((eq type 'text) "Text note") ((eq type 'strike-out) "Strikeout"))) (if insert-contents (progn (setq contents (cons (pdf-info-gettext page edges) (and (or (and item-subject (> (length item-subject) 0)) (and item-contents (> (length item-contents) 0))) (concat (or item-subject "") (if (and item-subject item-contents) "\n" "") (or item-contents ""))))))) (setq output-data (cons (vector (format "%s on page %d" name page) (cons page top) 'inside contents) output-data)))))) (setq tail (cdr tail))))) (let ((tail pages-with-links)) (while tail (let ((page (car tail))) (let ((links (pdf-info-pagelinks page)) type) (let ((tail links)) (while tail (let ((link (car tail))) (setq type (alist-get 'type link)) (if (eq type 'goto-dest) nil (let* ((edges (alist-get 'edges link)) (title (alist-get 'title link)) (top (nth 1 edges)) (target-page (alist-get 'page link)) target heading-text) (if (and title (> (length title) 0)) nil (setq title (pdf-info-gettext page edges))) (cond ((eq type 'uri) (progn (setq target (alist-get 'uri link)) (setq heading-text (format "Link on page %d: [[%s][%s]]" page target title)))) ((eq type 'goto-remote) (progn (setq target (concat "file:" (alist-get 'filename link))) (setq heading-text (format "Link to document on page %d: [[%s][%s]]" page target title))) (if target-page (progn (setq heading-text (concat heading-text (format " (target page: %d)" target-page)))))) (t (error "Unexpected link type"))) (setq output-data (cons (vector heading-text (cons page top) 'inside nil) output-data)))) (setq tail (cdr tail)))))) (setq tail (cdr tail)))))))) (if output-data (progn (if (memq 'annots answer) (setq output-data (sort output-data #'(lambda (e1 e2) (or (not (aref e1 1)) (and (aref e2 1) (org-noter--compare-locations '< (aref e1 1) (aref e2 1))))))) (setq output-data (nreverse output-data))) (setq output-data (cons (vector "Skeleton" nil 1 nil) output-data))))) (save-current-buffer (set-buffer (let* ((cl-x session)) (progn (or (let* ((cl-x cl-x)) (progn (and (memq (type-of cl-x) cl-struct-org-noter--session-tags) t))) (signal 'wrong-type-argument (list 'org-noter--session cl-x))) (aref cl-x 4)))) (widen) (save-excursion (goto-char (let* ((parray (and t (let* ((val (org-element-type ast))) (cond ((null val) 'nil) ((eq val 'plain-text) 'nil) (t (let nil (if (eq :standard-properties (car (nth 1 ast))) (car (cdr (nth 1 ast))) (plist-get (nth 1 ast) :standard-properties))))))))) (if parray (let* ((val (aref parray 4))) (if (eq val 'org-element-ast--nil) 'nil (let ((val val)) val))) (let* ((val (org-element-type ast))) (cond ((null val) 'nil) ((eq val 'plain-text) (let nil (or (get-text-property 0 :end ast) (if nil (progn (if (with-no-warnings (plist-member (text-properties-at 0 ast) :end)) nil nil)))))) (t (let nil (or (plist-get (nth 1 ast) :end) (if nil (progn (if (with-no-warnings (plist-member (nth 1 ast) :end)) nil nil))))))))))) (let (last-absolute-level title location relative-level contents level) (let ((tail output-data)) (while tail (let ((data (car tail))) (progn (setq title (aref data 0)) (setq location (aref data 1)) (setq relative-level (aref data 2)) (setq contents (aref data 3))) (if (symbolp relative-level) (setq level (1+ last-absolute-level)) (progn (setq last-absolute-level (+ top-level relative-level)) (setq level last-absolute-level))) (org-noter--insert-heading level title) (if location (progn (org-entry-put nil org-noter-property-note-location (org-noter--pretty-print-location location)))) (if org-noter-doc-property-in-notes (progn (org-entry-put nil org-noter-property-doc-file (let* ((cl-x session)) (progn (or (let* ((cl-x cl-x)) (progn (and (memq (type-of cl-x) cl-struct-org-noter--session-tags) t))) (signal 'wrong-type-argument (list 'org-noter--session cl-x))) (aref cl-x 10)))) (org-entry-put nil org-noter--property-auto-save-last-location "nil"))) (if (car contents) (progn (org-noter--insert-heading (1+ level) "Contents") (insert (car contents)))) (if (cdr contents) (progn (org-noter--insert-heading (1+ level) "Comment") (insert (cdr contents)))) (setq tail (cdr tail)))))) (setq ast (org-noter--parse-root)) (org-noter--narrow-to-root ast) (goto-char (let* ((parray (and t (let* ((val (org-element-type ast))) (cond ((null val) 'nil) ((eq val 'plain-text) 'nil) (t (let nil (if (eq :standard-properties (car (nth 1 ast))) (car (cdr (nth 1 ast))) (plist-get (nth 1 ast) :standard-properties))))))))) (if parray (let* ((val (aref parray 0))) (if (eq val 'org-element-ast--nil) 'nil (let ((val val)) val))) (let* ((val (org-element-type ast))) (cond ((null val) 'nil) ((eq val 'plain-text) (let nil (or (get-text-property 0 :begin ast) (if nil (progn (if (with-no-warnings (plist-member (text-properties-at 0 ast) :begin)) nil nil)))))) (t (let nil (or (plist-get (nth 1 ast) :begin) (if nil (progn (if (with-no-warnings (plist-member (nth 1 ast) :begin)) nil nil))))))))))) (outline-hide-subtree) (org-show-children 2))) output-data))
(progn (progn (let* ((ast (org-noter--parse-root)) (top-level (or (org-element--property :level ast nil nil) 0)) (options '(("Outline" outline) ("Annotations" annots) ("Both" outline annots))) answer output-data) (save-current-buffer (set-buffer (let* ((cl-x session)) (progn (or (let* ((cl-x cl-x)) (progn (and (memq (type-of cl-x) cl-struct-org-noter--session-tags) t))) (signal 'wrong-type-argument (list 'org-noter--session cl-x))) (aref cl-x 3)))) (setq answer (assoc (completing-read "What do you want to import? " options nil t) options)) (if (memq 'outline answer) (progn (let ((tail (pdf-info-outline))) (while tail (let ((item (car tail))) (let ((type (alist-get 'type item)) (page (alist-get 'page item)) (depth (alist-get 'depth item)) (title (alist-get 'title item)) (top (alist-get 'top item))) (if (and (eq type 'goto-dest) (> page 0)) (progn (setq output-data (cons (vector title (cons page top) (1+ depth) nil) output-data))))) (setq tail (cdr tail))))))) (if (memq 'annots answer) (progn (let ((possible-annots (list '("Highlights" . highlight) '("Underlines" . underline) '("Squigglies" . squiggly) '("Text notes" . text) '("Strikeouts" . strike-out) '("Links" . link) '("ALL" . all))) chosen-annots insert-contents pages-with-links) (while (> (length possible-annots) 1) (let* ((chosen-string (completing-read "Which types of annotations do you want? " possible-annots nil t)) (chosen-pair (assoc chosen-string possible-annots))) (cond ((eq (cdr chosen-pair) 'all) (let ((tail possible-annots)) (while tail (let ((annot (car tail))) (if (and (cdr annot) (not (eq (cdr annot) 'all))) (progn (setq chosen-annots (cons (cdr annot) chosen-annots)))) (setq tail (cdr tail))))) (setq possible-annots nil)) ((cdr chosen-pair) (setq chosen-annots (cons (cdr chosen-pair) chosen-annots)) (setq possible-annots (delq chosen-pair possible-annots)) (if (= 1 (length chosen-annots)) (progn (setq possible-annots (cons '("DONE") possible-annots))))) (t (setq possible-annots nil))))) (setq insert-contents (y-or-n-p "Should we insert the annotations contents? ")) (let ((tail (pdf-info-getannots))) (while tail (let ((item (car tail))) (let* ((type (alist-get 'type item)) (page (alist-get 'page item)) (edges (or (org-noter-pdf--edges-to-region (alist-get 'markup-edges item)) (alist-get 'edges item))) (top (nth 1 edges)) (item-subject (alist-get 'subject item)) (item-contents (alist-get 'contents item)) name contents) (if (and (memq type chosen-annots) (> page 0)) (progn (if (eq type 'link) (let* ((var page)) (if (memql var pages-with-links) (with-no-warnings pages-with-links) (setq pages-with-links (cons var pages-with-links)))) (setq name (cond ((eq type 'highlight) "Highlight") ((eq type 'underline) "Underline") ((eq type 'squiggly) "Squiggly") ((eq type 'text) "Text note") ((eq type 'strike-out) "Strikeout"))) (if insert-contents (progn (setq contents (cons (pdf-info-gettext page edges) (and (or (and item-subject (> (length item-subject) 0)) (and item-contents (> (length item-contents) 0))) (concat (or item-subject "") (if (and item-subject item-contents) "\n" "") (or item-contents ""))))))) (setq output-data (cons (vector (format "%s on page %d" name page) (cons page top) 'inside contents) output-data)))))) (setq tail (cdr tail))))) (let ((tail pages-with-links)) (while tail (let ((page (car tail))) (let ((links (pdf-info-pagelinks page)) type) (let ((tail links)) (while tail (let ((link (car tail))) (setq type (alist-get 'type link)) (if (eq type 'goto-dest) nil (let* ((edges (alist-get 'edges link)) (title (alist-get 'title link)) (top (nth 1 edges)) (target-page (alist-get 'page link)) target heading-text) (if (and title (> (length title) 0)) nil (setq title (pdf-info-gettext page edges))) (cond ((eq type 'uri) (progn (setq target (alist-get 'uri link)) (setq heading-text (format "Link on page %d: [[%s][%s]]" page target title)))) ((eq type 'goto-remote) (progn (setq target (concat "file:" (alist-get 'filename link))) (setq heading-text (format "Link to document on page %d: [[%s][%s]]" page target title))) (if target-page (progn (setq heading-text (concat heading-text (format " (target page: %d)" target-page)))))) (t (error "Unexpected link type"))) (setq output-data (cons (vector heading-text (cons page top) 'inside nil) output-data)))) (setq tail (cdr tail)))))) (setq tail (cdr tail)))))))) (if output-data (progn (if (memq 'annots answer) (setq output-data (sort output-data #'(lambda (e1 e2) (or (not (aref e1 1)) (and (aref e2 1) (org-noter--compare-locations '< (aref e1 1) (aref e2 1))))))) (setq output-data (nreverse output-data))) (setq output-data (cons (vector "Skeleton" nil 1 nil) output-data))))) (save-current-buffer (set-buffer (let* ((cl-x session)) (progn (or (let* ((cl-x cl-x)) (progn (and (memq (type-of cl-x) cl-struct-org-noter--session-tags) t))) (signal 'wrong-type-argument (list 'org-noter--session cl-x))) (aref cl-x 4)))) (widen) (save-excursion (goto-char (let* ((parray (and t (let* ((val (org-element-type ast))) (cond ((null val) 'nil) ((eq val 'plain-text) 'nil) (t (let nil (if (eq :standard-properties (car (nth 1 ast))) (car (cdr (nth 1 ast))) (plist-get (nth 1 ast) :standard-properties))))))))) (if parray (let* ((val (aref parray 4))) (if (eq val 'org-element-ast--nil) 'nil (let ((val val)) val))) (let* ((val (org-element-type ast))) (cond ((null val) 'nil) ((eq val 'plain-text) (let nil (or (get-text-property 0 :end ast) (if nil (progn (if (with-no-warnings (plist-member (text-properties-at 0 ast) :end)) nil nil)))))) (t (let nil (or (plist-get (nth 1 ast) :end) (if nil (progn (if (with-no-warnings (plist-member (nth 1 ast) :end)) nil nil))))))))))) (let (last-absolute-level title location relative-level contents level) (let ((tail output-data)) (while tail (let ((data (car tail))) (progn (setq title (aref data 0)) (setq location (aref data 1)) (setq relative-level (aref data 2)) (setq contents (aref data 3))) (if (symbolp relative-level) (setq level (1+ last-absolute-level)) (progn (setq last-absolute-level (+ top-level relative-level)) (setq level last-absolute-level))) (org-noter--insert-heading level title) (if location (progn (org-entry-put nil org-noter-property-note-location (org-noter--pretty-print-location location)))) (if org-noter-doc-property-in-notes (progn (org-entry-put nil org-noter-property-doc-file (let* ((cl-x session)) (progn (or (let* ((cl-x cl-x)) (progn (and (memq (type-of cl-x) cl-struct-org-noter--session-tags) t))) (signal 'wrong-type-argument (list 'org-noter--session cl-x))) (aref cl-x 10)))) (org-entry-put nil org-noter--property-auto-save-last-location "nil"))) (if (car contents) (progn (org-noter--insert-heading (1+ level) "Contents") (insert (car contents)))) (if (cdr contents) (progn (org-noter--insert-heading (1+ level) "Comment") (insert (cdr contents)))) (setq tail (cdr tail)))))) (setq ast (org-noter--parse-root)) (org-noter--narrow-to-root ast) (goto-char (let* ((parray (and t (let* ((val (org-element-type ast))) (cond ((null val) 'nil) ((eq val 'plain-text) 'nil) (t (let nil (if (eq :standard-properties (car (nth 1 ast))) (car (cdr (nth 1 ast))) (plist-get (nth 1 ast) :standard-properties))))))))) (if parray (let* ((val (aref parray 0))) (if (eq val 'org-element-ast--nil) 'nil (let ((val val)) val))) (let* ((val (org-element-type ast))) (cond ((null val) 'nil) ((eq val 'plain-text) (let nil (or (get-text-property 0 :begin ast) (if nil (progn (if (with-no-warnings (plist-member (text-properties-at 0 ast) :begin)) nil nil)))))) (t (let nil (or (plist-get (nth 1 ast) :begin) (if nil (progn (if (with-no-warnings (plist-member (nth 1 ast) :begin)) nil nil))))))))))) (outline-hide-subtree) (org-show-children 2))) output-data)))
(if (org-noter--valid-session session) (progn (progn (let* ((ast (org-noter--parse-root)) (top-level (or (org-element--property :level ast nil nil) 0)) (options '(("Outline" outline) ("Annotations" annots) ("Both" outline annots))) answer output-data) (save-current-buffer (set-buffer (let* ((cl-x session)) (progn (or (let* ((cl-x cl-x)) (progn (and (memq (type-of cl-x) cl-struct-org-noter--session-tags) t))) (signal 'wrong-type-argument (list 'org-noter--session cl-x))) (aref cl-x 3)))) (setq answer (assoc (completing-read "What do you want to import? " options nil t) options)) (if (memq 'outline answer) (progn (let ((tail (pdf-info-outline))) (while tail (let ((item (car tail))) (let ((type (alist-get 'type item)) (page (alist-get 'page item)) (depth (alist-get 'depth item)) (title (alist-get 'title item)) (top (alist-get 'top item))) (if (and (eq type 'goto-dest) (> page 0)) (progn (setq output-data (cons (vector title (cons page top) (1+ depth) nil) output-data))))) (setq tail (cdr tail))))))) (if (memq 'annots answer) (progn (let ((possible-annots (list '("Highlights" . highlight) '("Underlines" . underline) '("Squigglies" . squiggly) '("Text notes" . text) '("Strikeouts" . strike-out) '("Links" . link) '("ALL" . all))) chosen-annots insert-contents pages-with-links) (while (> (length possible-annots) 1) (let* ((chosen-string (completing-read "Which types of annotations do you want? " possible-annots nil t)) (chosen-pair (assoc chosen-string possible-annots))) (cond ((eq (cdr chosen-pair) 'all) (let ((tail possible-annots)) (while tail (let ((annot (car tail))) (if (and (cdr annot) (not (eq (cdr annot) 'all))) (progn (setq chosen-annots (cons (cdr annot) chosen-annots)))) (setq tail (cdr tail))))) (setq possible-annots nil)) ((cdr chosen-pair) (setq chosen-annots (cons (cdr chosen-pair) chosen-annots)) (setq possible-annots (delq chosen-pair possible-annots)) (if (= 1 (length chosen-annots)) (progn (setq possible-annots (cons '("DONE") possible-annots))))) (t (setq possible-annots nil))))) (setq insert-contents (y-or-n-p "Should we insert the annotations contents? ")) (let ((tail (pdf-info-getannots))) (while tail (let ((item (car tail))) (let* ((type (alist-get 'type item)) (page (alist-get 'page item)) (edges (or (org-noter-pdf--edges-to-region (alist-get 'markup-edges item)) (alist-get 'edges item))) (top (nth 1 edges)) (item-subject (alist-get 'subject item)) (item-contents (alist-get 'contents item)) name contents) (if (and (memq type chosen-annots) (> page 0)) (progn (if (eq type 'link) (let* ((var page)) (if (memql var pages-with-links) (with-no-warnings pages-with-links) (setq pages-with-links (cons var pages-with-links)))) (setq name (cond ((eq type 'highlight) "Highlight") ((eq type 'underline) "Underline") ((eq type 'squiggly) "Squiggly") ((eq type 'text) "Text note") ((eq type 'strike-out) "Strikeout"))) (if insert-contents (progn (setq contents (cons (pdf-info-gettext page edges) (and (or (and item-subject (> (length item-subject) 0)) (and item-contents (> (length item-contents) 0))) (concat (or item-subject "") (if (and item-subject item-contents) "\n" "") (or item-contents ""))))))) (setq output-data (cons (vector (format "%s on page %d" name page) (cons page top) 'inside contents) output-data)))))) (setq tail (cdr tail))))) (let ((tail pages-with-links)) (while tail (let ((page (car tail))) (let ((links (pdf-info-pagelinks page)) type) (let ((tail links)) (while tail (let ((link (car tail))) (setq type (alist-get 'type link)) (if (eq type 'goto-dest) nil (let* ((edges (alist-get 'edges link)) (title (alist-get 'title link)) (top (nth 1 edges)) (target-page (alist-get 'page link)) target heading-text) (if (and title (> (length title) 0)) nil (setq title (pdf-info-gettext page edges))) (cond ((eq type 'uri) (progn (setq target (alist-get 'uri link)) (setq heading-text (format "Link on page %d: [[%s][%s]]" page target title)))) ((eq type 'goto-remote) (progn (setq target (concat "file:" (alist-get 'filename link))) (setq heading-text (format "Link to document on page %d: [[%s][%s]]" page target title))) (if target-page (progn (setq heading-text (concat heading-text (format " (target page: %d)" target-page)))))) (t (error "Unexpected link type"))) (setq output-data (cons (vector heading-text (cons page top) 'inside nil) output-data)))) (setq tail (cdr tail)))))) (setq tail (cdr tail)))))))) (if output-data (progn (if (memq 'annots answer) (setq output-data (sort output-data #'(lambda (e1 e2) (or (not (aref e1 1)) (and (aref e2 1) (org-noter--compare-locations '< (aref e1 1) (aref e2 1))))))) (setq output-data (nreverse output-data))) (setq output-data (cons (vector "Skeleton" nil 1 nil) output-data))))) (save-current-buffer (set-buffer (let* ((cl-x session)) (progn (or (let* ((cl-x cl-x)) (progn (and (memq (type-of cl-x) cl-struct-org-noter--session-tags) t))) (signal 'wrong-type-argument (list 'org-noter--session cl-x))) (aref cl-x 4)))) (widen) (save-excursion (goto-char (let* ((parray (and t (let* ((val (org-element-type ast))) (cond ((null val) 'nil) ((eq val 'plain-text) 'nil) (t (let nil (if (eq :standard-properties (car (nth 1 ast))) (car (cdr (nth 1 ast))) (plist-get (nth 1 ast) :standard-properties))))))))) (if parray (let* ((val (aref parray 4))) (if (eq val 'org-element-ast--nil) 'nil (let ((val val)) val))) (let* ((val (org-element-type ast))) (cond ((null val) 'nil) ((eq val 'plain-text) (let nil (or (get-text-property 0 :end ast) (if nil (progn (if (with-no-warnings (plist-member (text-properties-at 0 ast) :end)) nil nil)))))) (t (let nil (or (plist-get (nth 1 ast) :end) (if nil (progn (if (with-no-warnings (plist-member (nth 1 ast) :end)) nil nil))))))))))) (let (last-absolute-level title location relative-level contents level) (let ((tail output-data)) (while tail (let ((data (car tail))) (progn (setq title (aref data 0)) (setq location (aref data 1)) (setq relative-level (aref data 2)) (setq contents (aref data 3))) (if (symbolp relative-level) (setq level (1+ last-absolute-level)) (progn (setq last-absolute-level (+ top-level relative-level)) (setq level last-absolute-level))) (org-noter--insert-heading level title) (if location (progn (org-entry-put nil org-noter-property-note-location (org-noter--pretty-print-location location)))) (if org-noter-doc-property-in-notes (progn (org-entry-put nil org-noter-property-doc-file (let* ((cl-x session)) (progn (or (let* ((cl-x cl-x)) (progn (and (memq (type-of cl-x) cl-struct-org-noter--session-tags) t))) (signal 'wrong-type-argument (list 'org-noter--session cl-x))) (aref cl-x 10)))) (org-entry-put nil org-noter--property-auto-save-last-location "nil"))) (if (car contents) (progn (org-noter--insert-heading (1+ level) "Contents") (insert (car contents)))) (if (cdr contents) (progn (org-noter--insert-heading (1+ level) "Comment") (insert (cdr contents)))) (setq tail (cdr tail)))))) (setq ast (org-noter--parse-root)) (org-noter--narrow-to-root ast) (goto-char (let* ((parray (and t (let* ((val (org-element-type ast))) (cond ((null val) 'nil) ((eq val 'plain-text) 'nil) (t (let nil (if (eq :standard-properties (car (nth 1 ast))) (car (cdr (nth 1 ast))) (plist-get (nth 1 ast) :standard-properties))))))))) (if parray (let* ((val (aref parray 0))) (if (eq val 'org-element-ast--nil) 'nil (let ((val val)) val))) (let* ((val (org-element-type ast))) (cond ((null val) 'nil) ((eq val 'plain-text) (let nil (or (get-text-property 0 :begin ast) (if nil (progn (if (with-no-warnings (plist-member (text-properties-at 0 ast) :begin)) nil nil)))))) (t (let nil (or (plist-get (nth 1 ast) :begin) (if nil (progn (if (with-no-warnings (plist-member (nth 1 ast) :begin)) nil nil))))))))))) (outline-hide-subtree) (org-show-children 2))) output-data))))
(let ((session org-noter--session)) (if (org-noter--valid-session session) (progn (progn (let* ((ast (org-noter--parse-root)) (top-level (or (org-element--property :level ast nil nil) 0)) (options '(("Outline" outline) ("Annotations" annots) ("Both" outline annots))) answer output-data) (save-current-buffer (set-buffer (let* ((cl-x session)) (progn (or (let* ((cl-x cl-x)) (progn (and (memq (type-of cl-x) cl-struct-org-noter--session-tags) t))) (signal 'wrong-type-argument (list 'org-noter--session cl-x))) (aref cl-x 3)))) (setq answer (assoc (completing-read "What do you want to import? " options nil t) options)) (if (memq 'outline answer) (progn (let ((tail (pdf-info-outline))) (while tail (let ((item (car tail))) (let ((type (alist-get 'type item)) (page (alist-get 'page item)) (depth (alist-get 'depth item)) (title (alist-get 'title item)) (top (alist-get 'top item))) (if (and (eq type 'goto-dest) (> page 0)) (progn (setq output-data (cons (vector title (cons page top) (1+ depth) nil) output-data))))) (setq tail (cdr tail))))))) (if (memq 'annots answer) (progn (let ((possible-annots (list '("Highlights" . highlight) '("Underlines" . underline) '("Squigglies" . squiggly) '("Text notes" . text) '("Strikeouts" . strike-out) '("Links" . link) '("ALL" . all))) chosen-annots insert-contents pages-with-links) (while (> (length possible-annots) 1) (let* ((chosen-string (completing-read "Which types of annotations do you want? " possible-annots nil t)) (chosen-pair (assoc chosen-string possible-annots))) (cond ((eq (cdr chosen-pair) 'all) (let ((tail possible-annots)) (while tail (let ((annot (car tail))) (if (and (cdr annot) (not (eq (cdr annot) 'all))) (progn (setq chosen-annots (cons (cdr annot) chosen-annots)))) (setq tail (cdr tail))))) (setq possible-annots nil)) ((cdr chosen-pair) (setq chosen-annots (cons (cdr chosen-pair) chosen-annots)) (setq possible-annots (delq chosen-pair possible-annots)) (if (= 1 (length chosen-annots)) (progn (setq possible-annots (cons '("DONE") possible-annots))))) (t (setq possible-annots nil))))) (setq insert-contents (y-or-n-p "Should we insert the annotations contents? ")) (let ((tail (pdf-info-getannots))) (while tail (let ((item (car tail))) (let* ((type (alist-get 'type item)) (page (alist-get 'page item)) (edges (or (org-noter-pdf--edges-to-region (alist-get 'markup-edges item)) (alist-get 'edges item))) (top (nth 1 edges)) (item-subject (alist-get 'subject item)) (item-contents (alist-get 'contents item)) name contents) (if (and (memq type chosen-annots) (> page 0)) (progn (if (eq type 'link) (let* ((var page)) (if (memql var pages-with-links) (with-no-warnings pages-with-links) (setq pages-with-links (cons var pages-with-links)))) (setq name (cond ((eq type 'highlight) "Highlight") ((eq type 'underline) "Underline") ((eq type 'squiggly) "Squiggly") ((eq type 'text) "Text note") ((eq type 'strike-out) "Strikeout"))) (if insert-contents (progn (setq contents (cons (pdf-info-gettext page edges) (and (or (and item-subject (> (length item-subject) 0)) (and item-contents (> (length item-contents) 0))) (concat (or item-subject "") (if (and item-subject item-contents) "\n" "") (or item-contents ""))))))) (setq output-data (cons (vector (format "%s on page %d" name page) (cons page top) 'inside contents) output-data)))))) (setq tail (cdr tail))))) (let ((tail pages-with-links)) (while tail (let ((page (car tail))) (let ((links (pdf-info-pagelinks page)) type) (let ((tail links)) (while tail (let ((link (car tail))) (setq type (alist-get 'type link)) (if (eq type 'goto-dest) nil (let* ((edges (alist-get 'edges link)) (title (alist-get 'title link)) (top (nth 1 edges)) (target-page (alist-get 'page link)) target heading-text) (if (and title (> (length title) 0)) nil (setq title (pdf-info-gettext page edges))) (cond ((eq type 'uri) (progn (setq target (alist-get 'uri link)) (setq heading-text (format "Link on page %d: [[%s][%s]]" page target title)))) ((eq type 'goto-remote) (progn (setq target (concat "file:" (alist-get 'filename link))) (setq heading-text (format "Link to document on page %d: [[%s][%s]]" page target title))) (if target-page (progn (setq heading-text (concat heading-text (format " (target page: %d)" target-page)))))) (t (error "Unexpected link type"))) (setq output-data (cons (vector heading-text (cons page top) 'inside nil) output-data)))) (setq tail (cdr tail)))))) (setq tail (cdr tail)))))))) (if output-data (progn (if (memq 'annots answer) (setq output-data (sort output-data #'(lambda (e1 e2) (or (not (aref e1 1)) (and (aref e2 1) (org-noter--compare-locations '< (aref e1 1) (aref e2 1))))))) (setq output-data (nreverse output-data))) (setq output-data (cons (vector "Skeleton" nil 1 nil) output-data))))) (save-current-buffer (set-buffer (let* ((cl-x session)) (progn (or (let* ((cl-x cl-x)) (progn (and (memq (type-of cl-x) cl-struct-org-noter--session-tags) t))) (signal 'wrong-type-argument (list 'org-noter--session cl-x))) (aref cl-x 4)))) (widen) (save-excursion (goto-char (let* ((parray (and t (let* ((val (org-element-type ast))) (cond ((null val) 'nil) ((eq val 'plain-text) 'nil) (t (let nil (if (eq :standard-properties (car (nth 1 ast))) (car (cdr (nth 1 ast))) (plist-get (nth 1 ast) :standard-properties))))))))) (if parray (let* ((val (aref parray 4))) (if (eq val 'org-element-ast--nil) 'nil (let ((val val)) val))) (let* ((val (org-element-type ast))) (cond ((null val) 'nil) ((eq val 'plain-text) (let nil (or (get-text-property 0 :end ast) (if nil (progn (if (with-no-warnings (plist-member (text-properties-at 0 ast) :end)) nil nil)))))) (t (let nil (or (plist-get (nth 1 ast) :end) (if nil (progn (if (with-no-warnings (plist-member (nth 1 ast) :end)) nil nil))))))))))) (let (last-absolute-level title location relative-level contents level) (let ((tail output-data)) (while tail (let ((data (car tail))) (progn (setq title (aref data 0)) (setq location (aref data 1)) (setq relative-level (aref data 2)) (setq contents (aref data 3))) (if (symbolp relative-level) (setq level (1+ last-absolute-level)) (progn (setq last-absolute-level (+ top-level relative-level)) (setq level last-absolute-level))) (org-noter--insert-heading level title) (if location (progn (org-entry-put nil org-noter-property-note-location (org-noter--pretty-print-location location)))) (if org-noter-doc-property-in-notes (progn (org-entry-put nil org-noter-property-doc-file (let* ((cl-x session)) (progn (or (let* ((cl-x cl-x)) (progn (and (memq (type-of cl-x) cl-struct-org-noter--session-tags) t))) (signal 'wrong-type-argument (list 'org-noter--session cl-x))) (aref cl-x 10)))) (org-entry-put nil org-noter--property-auto-save-last-location "nil"))) (if (car contents) (progn (org-noter--insert-heading (1+ level) "Contents") (insert (car contents)))) (if (cdr contents) (progn (org-noter--insert-heading (1+ level) "Comment") (insert (cdr contents)))) (setq tail (cdr tail)))))) (setq ast (org-noter--parse-root)) (org-noter--narrow-to-root ast) (goto-char (let* ((parray (and t (let* ((val (org-element-type ast))) (cond ((null val) 'nil) ((eq val 'plain-text) 'nil) (t (let nil (if (eq :standard-properties (car (nth 1 ast))) (car (cdr (nth 1 ast))) (plist-get (nth 1 ast) :standard-properties))))))))) (if parray (let* ((val (aref parray 0))) (if (eq val 'org-element-ast--nil) 'nil (let ((val val)) val))) (let* ((val (org-element-type ast))) (cond ((null val) 'nil) ((eq val 'plain-text) (let nil (or (get-text-property 0 :begin ast) (if nil (progn (if (with-no-warnings (plist-member (text-properties-at 0 ast) :begin)) nil nil)))))) (t (let nil (or (plist-get (nth 1 ast) :begin) (if nil (progn (if (with-no-warnings (plist-member (nth 1 ast) :begin)) nil nil))))))))))) (outline-hide-subtree) (org-show-children 2))) output-data)))))
[a few sexps removed here to avoid exceeding the character limit]
org-noter-pdf--create-skeleton(pdf-view-mode)
org-noter-create-skeleton()
funcall-interactively(org-noter-create-skeleton)
command-execute(org-noter-create-skeleton)

GPT-4 comments

This error is likely occurring due to problems with the rectangle specified in the function call pdf-info-gettext. The rectangle dimensions given are unusually large and might be causing the error.

You can double check if the coordinates are correct. If the coordinates are auto generated, it could be an issue with how these coordinates are being calculated. For these kind of errors with coordinates, it's often because of some kind of data corruption or error in calculation.

Please update the rectangle coordinates to a reasonable values. Check the documentation or examples of usage of pdf-info-gettext to get an idea of typically used values.

If you are not sure what the values should be, it might be useful to understand that they typically specify the area in which you're interested in the PDF document. It's defined using a list of four numbers [left top right bottom], usually ranging from 0 to 1, which denote the relative position/size of the rectangle. For instance, a value of [0 0 1 1] would signify the full view.

If that doesn't solve it or the problem is more complex, consider reaching out to the maintainers of the package or seek help on a forum where Emacs and Lisp are being discussed. They will be in a better position to help with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant