Skip to content

Instantly share code, notes, and snippets.

@lucasvreis
Last active March 19, 2024 11:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucasvreis/d031bb66ec5a4b4af15e80024dc64064 to your computer and use it in GitHub Desktop.
Save lucasvreis/d031bb66ec5a4b4af15e80024dc64064 to your computer and use it in GitHub Desktop.
;; this function NEEDS `lexical-binding' set to `t'
(defun boox/attach-last-figure-adb (basename)
(interactive "sName: ")
(unless (eq major-mode 'org-mode)
(user-error "Not in an org buffer"))
(require 'org-attach)
(require 'org-download)
(let ((fp "/adb:8A3DF2BF:storage/self/primary/note/export/export.pdf"))
(when (file-readable-p fp)
(when-let ((tmpdir (make-temp-file "boox-export" t))
(tmpin (concat tmpdir "/in.pdf"))
(tmpout (format "%s/%s.svg" tmpdir basename)))
(copy-file fp tmpin)
(let ((lastpage (shell-command-to-string (format "pdfinfo %s | awk '/^Pages:/ {print $2}'" tmpin)))
(marker (point-marker)))
(async-start-process
"inkscape-convert"
"inkscape"
(lambda (_)
(message "Inkscape finished.")
(with-current-buffer (marker-buffer marker)
(without-restriction
(save-excursion
(goto-char (marker-position marker))
(let ((org-attach-store-link-p 'attached))
(org-attach-attach tmpout nil 'cp))
(delete-directory tmpdir t nil)
(org-insert-link nil (caar org-stored-links) "")))))
"--actions=select-by-selector:svg>g>use;delete;page-fit-to-selection"
"--pdf-poppler"
(concat "--pages=" lastpage)
"-o" tmpout
"--export-dpi=10"
tmpin))))))
@lucasvreis
Copy link
Author

I've updated the gist to only require inkscape and insert the link asyncronously.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment