[pdftex] redundant objects with includegraphics

Otfried Cheong otfried at cs.uu.nl
Fri May 4 17:15:52 CEST 2001


 > > > * This week I have learned about \pdflastximagepages. But is there
 > > >   a more elegant way than
 > > >     \begingroup
 > > >       \sbox0{\includegraphics{foo.pdf}}%
 > > >       \xdef\foopages{\the\pdflastximagepages}%
 > > >     \endgroup
 > > >     Result: foo.pdf has \foopages\ page(s).
 > > >     ...
 > > >     \includepdf[pages=1-\foopages]{foo.pdf}
 > >
 > >I would just use the \pdximage primitive directly (not that it's a big
 > >improvement):
 > >
 > >\xpdfimage{foo.pdf}\def\foopages{\the\pdflastximagepages}%
 > 
 > With \includegraphics, the referenced number will be reused,
 > if the first page is embeded later. Or only other pages
 > are used, or the pdf file will not embedded at all. So the
 > question is, what is the best strategy for getting the
 > number of pages?

Either form is fine.  The first page will only be embedded if you
really put it in the paper.  

If you use \xpdfimage directly, it will create an internal 'ximage'
slot, which would not be reused (even if you include page 1 later),
but which would never create any PDF output.

If you use \includegraphics, \includegraphics calls both \pdfximage
and \pdfrefximage.  The latter creates a whatsit node that ends up in
box0, which is discarded immediately -- and so nothing ends up in the
PDF output.

Using \includegraphics saves one 'ximage' slot if and only if you
actually include page 1.  On the other hand, it defines three macros
for its internal cache.  Since neither 'ximage' slots nor macros are
scarce resources, I don't think it really matters.

Otfried





More information about the pdftex mailing list