[texhax] [pdftex] image XObjects in pdfTeX or XeTeX PDF output?

Paul Isambert zappathustra at free.fr
Fri Nov 19 21:46:10 CET 2010


Here's a simple way to use images in pdfTeX:

%%%

\def\loadimage#1#2#{%
  \getimage{#1}{#2}%
  }

\def\getimage#1#2#3{%
  \pdfximage #2 {#3}%
  \expandafter\edef\csname
#1 at image\endcsname{\pdfrefximage\the\pdflastximage\relax}%
  }

\def\useimage#1{%
  \ifcsname #1 at image\endcsname
    \csname #1 at image\endcsname
  \else
    \errmessage{Image `#1' hasn't been loaded}%
  \fi
  }

%%%

Then you can use \loadimage{<name>}<specs>{<file>} and \useimage{<name>}.

The <specs> are optional, and are of the form:

width <length> height <length> depth <length>

in any order. If none is present, the image is loaded at its natural size. If
one is present, the others are scaled accordingly. Naturally an image has a
depth of 0, but you can use it anyway. For instance:

% Natural size
\loadimage{myimg}{img.jpg}

% Height scaled to match width
\loadimage{myimg} width 3cm {img.jpg}

% Image deformed, probably
\loadimage{myimg} width 3cm height 1cm {img.jpg}


I don't think multiple posting is necessary. Please stick to one list or
another, and then turn to another list if you get no answer. Which is quite rare
if you post on texhax.


Best,
Paul


Selon Peter Davis <pfd at pfdstudio.com>:

> Is there a way in LaTeX, with either pdfTeX or XeTeX, to specify image and
> form XObjects for the final PDF document?  I want to generate a document
> which uses the same images multiple times, so I'd prefer the image just be
> included once, and then referenced each time it's needed on a page.
>
> Is this possible?
>
> Thank you!
>
> -pd
>




More information about the texhax mailing list