I am attempting to generate an HTML output via

htlatex <filename>

but when the pgfpages package is included I am getting some random images before and after the content. The resulting HTML viewed in Safari looks like:

enter image description here

I looked at pdfpages.sty and see that there is an \AtBeginDocument but don't see how that inserts these random images before the content. Furthermore, did not find a \AtEndDocument so can't understand how anything is happening after the content is processed.



   % \includepdf{foo.pdf}% Cover page
    Some content following cover page.
  • do you use pdfpages just to include some one page pdf file, or do you want to use some more advanced options?
    – michal.h21
    Oct 6, 2014 at 6:45
  • @michal.h21: I am using pdfpages to include the cover page of the book. But, as the above MWE demonstrates just including the package (without using it) results in the random images. Oct 6, 2014 at 6:53

1 Answer 1


pdfpages is obviously one of packages which causes tex4ht to fail just with loading. some other example of such package is fontspec. only solution is to prevent usage of such packages when tex4ht is loaded and to provide alternative definitions for macros used in the document.

To simplify this process, I created simple package, called alternative4ht.sty:


    }{\typeout{alternative4ht: no patch file for #2}}

one command is defined, \altusepackage, which loads package with normal LaTeX, but with tex4ht it loads alternative definitions or it does nothing if such alternative doesn't exist.

You can modify your source:


   %\includepdf{foo.pdf}% Cover page

    Some content following cover page.

you can provide definition for \includepdf in file pdfpages-alt4ht.sty:




and you will need to add support for pdf image inclusion with custom config file, peter.cfg:

         {\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}

now you can compile the document with:

htlatex <filename> peter

and the resulting html is:

<?xml version="1.0" encoding="iso-8859-1" ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="http://www.w3.org/1999/xhtml"  
<head> <title></title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" /> 
<meta name="originator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" /> 
<!-- html,xhtml --> 
<meta name="src" content="sample.tex" /> 
<meta name="date" content="2014-10-06 09:55:00" /> 
<link rel="stylesheet" type="text/css" href="sample.css" /> 
<!--l. 6--><p class="noindent" ><img 
src="foo.png" alt="pict"  
</p><!--l. 8--><p class="indent" >   Some content following cover page. </p> 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .