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.
#+TITLE: PDF Image
# 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
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.
(defun modi/org-include-img-from-pdf (&rest _)
"Convert the pdf files to image files.
Only looks at #+HEADER: lines that have \":convertfrompdf t\"."
(when (derived-mode-p 'org-mode)
(let* (filenoext imgext imgfile pdffile cmd)
;; Keep on going on to the next line till it finds a line with
(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
(message "%s" cmd)