Last active
March 19, 2024 11:07
-
-
Save lucasvreis/d031bb66ec5a4b4af15e80024dc64064 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've updated the gist to only require inkscape and insert the link asyncronously.