Closed QikeLi closed 7 years ago
I just added a minimum working example in https://github.com/kaushalmodi/.emacs.d/tree/master/elisp/org-include-img-from-pdf
Check it out.
Use the same mwe org file ( https://raw.githubusercontent.com/kaushalmodi/.emacs.d/master/elisp/org-include-img-from-pdf/org-include-img-from-pdf-mwe.org ) and the associated PDF file and see if it works for you.
Thank you very much for the mwe. It worked perfectly for me. However, I realized that if a figure is not placed at the beginning of the file like what you did, it cannot get converted. Does that happen to you as well? If so, do you plan to fix it?
Here is my example you may want to use to reproduce the error.
#+TITLE: PDF Image
#+NAME: fig:unicorn
#+HEADER: :convertfrompdf t
1. make a plot
#+BEGIN_SRC R :exports both :results graphics :file ./fig-1.pdf
plot(1:100)
#+END_SRC
[[./fig-1.png]]
However, I realized that if a figure is not placed at the beginning of the file like what you did, it cannot get converted.
That should have worked as long as the pdf file was available.
I do not have R installed so I tried the below and that worked:
#+TITLE: PDF Image
#+NAME: fig:unicorn
#+HEADER: :convertfrompdf t
1. make a plot
[[./org-mode-unicorn-logo.png]]
Though, I am not sure why you would want to keep the #+NAME
and #+HEADER
related to that image away from the image reference.
Few things I could think of that could be causing the problem:
org-export-before-processing-hook
? Because that is when the pdf file should be available if you are using that hook. To test out this theory, use a pre-generated pdf like the one I have in my mwe, and use that instead of relying on R to generate the pdf.#+HEADER
is actually an org inbuilt feature for source blocks. I am reusing it for this pdf to png conversion feature.
- Looks like your R code should be generating the pdf. Are you sure that the pdf is being generated before the org-export-before-processing-hook? Because that is when the pdf file should be available if you are using that hook. To test out this theory, use a pre-generated pdf like the one I have in my mwe, and use that instead of relying on R to generate the pdf.
I thought about that too. But no, this is no what's causing the problem.
- I do not think this second point could be causing the problem, but still I'll list it. The #+HEADER is actually an org inbuilt feature for source blocks. I am reusing it for this pdf to png conversion feature.
I am glad you raised this point. Once I place =#+HEADER: :convertfrompdf t= right before the figure[[*.png]], everything works fine.
Thank you for your quick response and this awesome function!
Once I place =#+HEADER: :convertfrompdf t= right before the figure[[*.png]], everything works fine.
Glad to know that you have this working. Yeah, that #+HEADER
is supposed to be specific to each figure. So it's not a bad idea to have #+HEADER
directly before the figure (along with #+NAME
and #+CAPTION
if any).
Feel free to close this issue if that is workable for you.
Started a discussion on org mode list to learn about the best way to improve this: http://lists.gnu.org/archive/html/emacs-orgmode/2017-01/msg00260.html
Your modi/org-include-img-from-pdf function seems awesome. However, I cannot get it work for me. My 'convert' is available in exec-path, and something like this works for me:
Also I can invoke modi/org-include-img-from-pdf by M-x, just nothing happens after running the function. Would you advise how to solve this? Thank you very much!