* Right way to add special processing to images?
@ 2017-01-12 16:53 Kaushal Modi
2017-01-12 19:59 ` Nicolas Goaziou
0 siblings, 1 reply; 3+ messages in thread
From: Kaushal Modi @ 2017-01-12 16:53 UTC (permalink / raw)
To: emacs-org list
[-- Attachment #1: Type: text/plain, Size: 2611 bytes --]
Hello,
I have this elisp function that I run in org-export-before-processing-hook
that coverts a pdf to png where that png file is already linked in the org
file. Just that the png file did not exist to begin with; it is converted
from pdf at the time of exporting. [Code is at the end of this email.]
But for that you work, need to add my special keyword "convertfrompdf t"
and I chose "#+HEADER" just before the image link to do that.
Here is my MWE:
=====
#+TITLE: PDF Image
#+NAME: fig:unicorn
# Below HEADER is required where the pdf version of the referenced png file
exists.
#+HEADER: :convertfrompdf t
# The below caption line is optional
#+CAPTION: Org-mode Unicorn Logo
[[./org-mode-unicorn-logo.png]]
=====
So the question is: Is using #+HEADER for this a good idea? Would the org
devs just a better way to do the same? I basically need to be able to
control per image link if that linked image foo.png needs to be converted
from a foo.pdf.
Thanks.
=====
(defun modi/org-include-img-from-pdf (&rest _)
"Convert the pdf files to image files.
Only looks at #+HEADER: lines that have \":convertfrompdf t\"."
(interactive)
(when (derived-mode-p 'org-mode)
(save-excursion
(goto-char (point-min))
(while (search-forward-regexp
"^\\s-*#\\+HEADER:.*\\s-:convertfrompdf\\s-+t"
nil 'noerror)
(let* (filenoext imgext imgfile pdffile cmd)
;; Keep on going on to the next line till it finds a line with
;; `[[FILE]]'
(while (progn
(forward-line 1)
(not (looking-at "\\[\\[\\(.*\\)\\.\\(.*\\)\\]\\]"))))
(when (looking-at "\\[\\[\\(.*\\)\\.\\(.*\\)\\]\\]")
(setq filenoext (match-string-no-properties 1))
(setq imgext (match-string-no-properties 2))
(setq imgfile (expand-file-name (concat filenoext "." imgext)))
(setq pdffile (expand-file-name (concat filenoext "." "pdf")))
(setq cmd (concat "convert -density 96 -quality 85 "
pdffile " " imgfile))
(when (file-newer-than-file-p pdffile imgfile)
;; This block is executed only if pdffile is newer than
imgfile
;; or if imgfile does not exist
;;
https://www.gnu.org/software/emacs/manual/html_node/elisp/Testing-Accessibility.html
(message "%s" cmd)
(shell-command cmd))))))))
=====
If interested, here is the code and MWE on my github repo:
https://github.com/kaushalmodi/.emacs.d/tree/master/elisp/org-include-img-from-pdf
--
Kaushal Modi
[-- Attachment #2: Type: text/html, Size: 3838 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Right way to add special processing to images?
2017-01-12 16:53 Right way to add special processing to images? Kaushal Modi
@ 2017-01-12 19:59 ` Nicolas Goaziou
2017-01-12 20:08 ` Kaushal Modi
0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Goaziou @ 2017-01-12 19:59 UTC (permalink / raw)
To: Kaushal Modi; +Cc: emacs-org list
Hello,
Kaushal Modi <kaushal.modi@gmail.com> writes:
> I have this elisp function that I run in org-export-before-processing-hook
> that coverts a pdf to png where that png file is already linked in the org
> file. Just that the png file did not exist to begin with; it is converted
> from pdf at the time of exporting. [Code is at the end of this email.]
>
> But for that you work, need to add my special keyword "convertfrompdf t"
> and I chose "#+HEADER" just before the image link to do that.
>
[...]
> So the question is: Is using #+HEADER for this a good idea? Would the org
> devs just a better way to do the same? I basically need to be able to
> control per image link if that linked image foo.png needs to be converted
> from a foo.pdf.
I would simply use a comment with some specific pattern instead of
messing with Org syntax.
For example, I use the following comments
# © Author "title" licence
just before image links so as to mark them, collect them and build some
special page at the end of a slide with the information.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Right way to add special processing to images?
2017-01-12 19:59 ` Nicolas Goaziou
@ 2017-01-12 20:08 ` Kaushal Modi
0 siblings, 0 replies; 3+ messages in thread
From: Kaushal Modi @ 2017-01-12 20:08 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-org list
[-- Attachment #1: Type: text/plain, Size: 498 bytes --]
On Thu, Jan 12, 2017 at 2:59 PM Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:
> I would simply use a comment with some specific pattern instead of
> messing with Org syntax.
>
> For example, I use the following comments
>
> # © Author "title" licence
>
> just before image links so as to mark them, collect them and build some
> special page at the end of a slide with the information.
>
Thank you. That looks like a simple and safe idea. I will do that.
--
Kaushal Modi
[-- Attachment #2: Type: text/html, Size: 1040 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-01-12 20:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-12 16:53 Right way to add special processing to images? Kaushal Modi
2017-01-12 19:59 ` Nicolas Goaziou
2017-01-12 20:08 ` Kaushal Modi
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).