# tex4ht: include *.pdf image - need condition in configuration file

I use tex4ht to compile my document.

In case if user includes .pdf image, I handle this situation in the following way (.cfg file):

\Configure{graphics*}
{pdf}
\Picture[pict]{\csname Gin@base\endcsname .png width="\expandafter\the\csname Gin@req@width\endcsname" align=center border=0}%  Show the png
}


I want to realize the following idea:

If imagename.png doesn't exist, then paste default.png (the same in all cases) image, otherwise reflect imagename.png.

Could someone help me to write such condition in configuration file, if it is possible.

• so if I understand it correctly, you don't want to convert your pdf images to png? – michal.h21 Dec 30 '15 at 12:20
• There are a lot of documents which where created previously and *.png file is absent. And I want in such case reflect informative image instead of "PIC" word. – Yulia Spryn Dec 30 '15 at 12:29

We can use small Javascript trick:

\Preamble{xhtml}
\Configure{graphics*}
{pdf}
\Picture[pict]{\csname Gin@base\endcsname .png width="\expandafter\the\csname Gin@req@width\endcsname" align=center border=0 onerror="this.src='missing.png'"}%  Show the png
}
\begin{document}
\EndPreamble


the important part is onerror="this.src='missing.png'".

Some sample:

\documentclass{article}
\usepackage{graphicx}
\begin{document}

\includegraphics[width=180pt]{hello.pdf}
\includegraphics[width=180pt]{world.pdf}
\end{document}


and the result: