PDF image files and `htlatex`

Try this configuration file:

\Preamble{xhtml}
  \Configure{graphics*}  
         {pdf}  
         {\Needs{"convert '\csname Gin@base\endcsname.pdf'  
                               '\csname Gin@base\endcsname.png'"}%  
          \Picture[pict]{\csname Gin@base\endcsname.png}%  
          \special{t4ht+@File: \csname Gin@base\endcsname.png}
         }  
\begin{document}
\EndPreamble

save it as myxhtml.cfg. This configuration tells htlatex for every image file with pdf suffix, run imagemagick's convert command and then insert the image. You must provide correct file extension for every included image in your source file. Compile the file with command

htlatex filename myxhtml

Edit:
Added \special{t4ht+@File: \csname Gin@base\endcsname.png}, purpose of this line is to store information about used images to the filename.lg file. This information is important when generated files are copied to another directory (make4ht or tex4ebook are using this information, for example).


Based on michal.h21's answer I have derived a solution that accepts (almost) all image types also accepted by default pdflatex. This considerably simplifies conversion of documents that are originally created in a pdflatex-based environment, as no conversion to EPS is required anymore.

PDFs are converted to PNG files with a density of 300 dpi. (I couldn't get SVG to work properly with LibreOffice, perhaps Enhanced Metafile or Windows Metafile could work, too, if Microsoft Word is your final target platform.) PNGs and JPEGs are used as they are, for the latter the extension is always .jpg. I have also added support for images in other than the default location by implementing a similar naming scheme to the one used by tex4ht for autogenerated images.

The process requires the following configuration file, let's call it my.cfg:

\Preamble{xhtml}
  \newcommand{\ConfigureGraphicsDirect}[3]{%
    \Configure{graphics*}
         {#1}
         {\Needs{"#3 \csname Gin@base\endcsname.#1
                               \jobname\arabic{texforhtimagecounter}y.#2"}%
          \Picture[pict]{\jobname\arabic{texforhtimagecounter}y.#2}%
          \stepcounter{texforhtimagecounter}%
         }%
  }
  \ConfigureGraphicsDirect{pdf}{png}{convert -density 300}%
  \ConfigureGraphicsDirect{png}{png}{cp}%
  \ConfigureGraphicsDirect{jpg}{jpg}{cp}%
  \ConfigureGraphicsDirect{jpeg}{jpg}{cp}%
\begin{document}
  \DeclareGraphicsExtensions{.pdf,.png,.jpg,.jpeg}
  \newcounter{texforhtimagecounter}
  \renewcommand{\AsPicture}[1]{%
    \Picture+[]{}#1\EndPicture}
\EndPreamble

For some reason two runs of mk4ht are required to produce a complete .odt file. After the first run, the images are missing. To compile, type:

mk4ht oolatex mainfile "my,ooffice"
mk4ht oolatex mainfile "my,ooffice"

For consistent dimensioning of other \Pictures, it is worthwhile to use a custom tex4ht.env file. I have found that dvips+convert does a better job here than dvipng. For this, copy the tex4ht.env file on your system to your main TeX file's directory and substitute this line

Gdvipng -T tight -x 1400 -D 72 -bg Transparent -pp %%2:%%2 %%1 -o %%3

(starting with Gdvipng line just after G.png) by:

Gdvips -E -D 300 -pp %%2:%%2 %%1 -o %%3.ps
Gconvert -density 300 %%3.ps %%3

If LibreOffice/OpenOffice is your target you need to manually resize each figure to 32% (for 300 dpi pictures). I haven't found an automatic way to do this, a modification of xtpipes might be required here.

Of course, for this to work on Windows you need to substitute cp by copy in the corresponding \ConfigureGraphicsDirect invocations.

The complete code is at GitHub, however you still might have to use your own copy of tex4ht.env unless you run Ubuntu 12.10 (or later) with a default installation or TeXlive.

I have found a very similar .cfg file at http://people.bath.ac.uk/cspehj/maths-access/xht/, but no description whatsoever.

GIF support is left as exercise for the reader.

Tags:

Html

Pdf

Eps

Tex4Ht