1

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}  
{\Link[\csname Gin@base\endcsname .pdf]{}{}% link the pdf figure 
\Picture[pict]{\csname Gin@base\endcsname .png width="\expandafter\the\csname Gin@req@width\endcsname" align=center border=0}%  Show the png
\EndLink  
}

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
3

We can use small Javascript trick:

\Preamble{xhtml}
\Configure{graphics*} 
{pdf}  
{\Link[\csname Gin@base\endcsname .pdf]{}{}% link the pdf figure 
\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
\EndLink  
}
\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:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.