From mboxrd@z Thu Jan 1 00:00:00 1970 From: Instructor account Subject: Re: pdf images in html export Date: Thu, 13 Nov 2014 07:21:58 -0500 Message-ID: References: <84tx24x1r6.fsf@tm6592.fritz.box> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XotzG-0007Ud-PK for emacs-orgmode@gnu.org; Thu, 13 Nov 2014 07:59:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XotzB-00016z-Vd for emacs-orgmode@gnu.org; Thu, 13 Nov 2014 07:58:58 -0500 Received: from smtp.andrew.cmu.edu ([128.2.105.202]:50845) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XotzB-00016o-RF for emacs-orgmode@gnu.org; Thu, 13 Nov 2014 07:58:53 -0500 In-Reply-To: (Rainer M. Krug's message of "Wed, 12 Nov 2014 15:13:46 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Rainer M Krug Cc: Andreas Leha , emacs-orgmode@gnu.org I think the best thing to do here is create a derived backend. Filters could work to, but you will have to parse the img link, get the pdf file, convert it and replace the path in the link. with a derived backend you can get that a little more directly like this. This code block works on a minimal example for me. I guess you could make a little function to do the last line, and put this all in your init files and it would work. This is a very unsophisticated format function that does not check for attributes like width or height or link descriptions... but, I get a png image in the html export of an org file with a pdf image ;) #+BEGIN_SRC emacs-lisp (defun my-link-format (link contents info) (let ((type (org-element-property :type link)) (path (org-element-property :path link))) (cond ((and (string= type "file") (string-match "\.pdf" path)) (shell-command (format "convert %s %s" path (replace-regexp-in-string "\.pdf" ".png" path))) (format "" (replace-regexp-in-string "\.pdf" ".png" path))) ;; anything else, we just do the regular thing (t (org-html-link link contents info))))) (org-export-define-derived-backend 'my-html 'html :translate-alist '((link . my-link-format))) (browse-url (org-export-to-file 'my-html "custom-link.html")) #+END_SRC Rainer M Krug writes: > Andreas Leha writes: > >> Hi Rainer, >> >> Rainer M Krug writes: >>> Andreas Leha writes: >>> >>>> Hi Marco, >>>> >>>> Marco Wahl writes: >>>>> Andreas Leha writes: >>>>> >>>>>> how would I export an org file containing >>>>>> >>>>>> [[file:./myimage.pdf]] >>>>>> >>>>>> to html so that a say png version myimage.pdf is inlined in the html >>>>>> which links to the pdf? >>>>>> >>>>>> I guess it should be possible to run imagemagick on all pdf links during >>>>>> export somehow. >>>>> >>>>> You could introduce a relation of the pdf-filenames to the respective >>>>> thumb-filenames e.g. by using the suffix '_thumb'. Before the export >>>>> the conversion tool would create the thumbs. >>>>> >>>>> The org-file could reference the data as >>>>> >>>>> [[file:./myimage.pdf][file:myimage_thumb.png]] >>>>> >>>>> See the info page (info "(org)Images in HTML export")? >>>>> >>>>> Untested. I just accidentially browsed that info page yesterday. >>>>> >>>>> >>>> >>>> Thanks for your thoughts. I would like to automate all of that. So, I >>>> guess the first question is where to put code that would trigger the >>>> conversion and how to best detect links to pdfs. >>> >>> Well - this is coming again and again - but no solution out of the >>> box. There are effectively two approaches: >>> >>> 1) Macro to change properties according to backend used. >>> >>> One usage is changing the file name extension according to the >>> backend. This is implemented as a simplified macro below. This could >>> be done by using ~(by-backend (html "graph.png") (latex "graph.pdf") (t "graph.pdf"))~ >>> >>> See [[http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html#sec-4-3][work section ob-doc-LaTeX]] for details. >>> >>> #+begin_src emacs-lisp >>> (setq org-babel-latex-htlatex "htlatex") >>> (defmacro rmk-by-backend (&rest body) >>> `(case (if (boundp 'backend) (org-export-backend-name backend) nil) ,@body)) >>> #+end_src >>> >>> 2) To use svg image format, which is supported by both (although has >>> it's drawbacks: slow rendering of the html, need to run external programs upon compilation) >>> >>> So the first might be the modst feasible option. >>> >> >> Thanks for this. I am aware of how to *produce* graphics in different >> formats for different export backends. I use your first approach, >> which I think is the better solution. > > I agree with you. > >> >> Here, I am after a solution, that works on images that are not produced >> but merely included via [[file:./some.pdf]]. > > OK - understood. > >> >> I think there should be the possibility to include these into html (and >> odt) export without any user interaction. So, I >> - do not want to write a source block just to produce the by-backend image >> - do not want to change the link manually >> - do not want to run the converter manually > > I agree with you - this *should* be possible, and I assume not to > difficult to implement. In my opinion, this should also work out of the > box when enabling it e.g. via a property. > >> >> I am pretty sure this should be achievable with standard orgmode tools >> (like filters, export hooks, or anything). > > Yes - it should be. > >> >> Since 'this is coming again and again' it seems a non-esoteric task. >> And as there is 'no solution out of the box', I assume(d) that somebody has >> written these filters already. > > Unfortunately not... > > Cheers, > > Rainer > >> >> Regards, >> Andreas >> >> >> -- ----------------------------------- John Kitchin Professor Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 http://kitchingroup.cheme.cmu.edu