# Resulting document size when Including a graphics file multiple times - pgf vs. graphicx

In his answer to the question Tikz: using external images as building blocks. Stefan Kottwitz says:

The pgf way may be preferred if the document size matters and graphics are multiply used or if masking is desired.

When is there a problem regarding large document size caused be multiple inclusions of the same image? With a random photo in jpg-format I get the results below using the following test-files:

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

\newcount\n
\n=0
\loop\ifnum\n<100 \advance\n by1
\includegraphics[width=5cm]{IMG_1823.JPG}
\newpage
\repeat

\end{document}


and

\documentclass{article}
\usepackage{pgf}
\pgfdeclareimage[width=5cm]{test}{IMG_1823.JPG}
\pagestyle{empty}
\begin{document}

\newcount\n
\n=0
\loop\ifnum\n<100 \advance\n by1
\pgfuseimage{test}
\newpage
\repeat

\end{document}


Compiling with pdfTeX-1.40.10 the resulting document sizes are (output from pdfinfo):

pgf-version:
File size:      1673589 bytes

Graphicx-version:
File size:      1667806 bytes


The photo is about 1.6 Mb:

\$ du IMG_1823.JPG
1592    IMG_1823.JPG


Adding \pdfcompresslevel=0 and inspecting the contents of the pdf-file directly both methods seem (as far as I can tell) to embed the image data once only?

-

## 1 Answer

The FAQ says that repeated graphics are only a problem if you are producing PostScript as the final format. Distillation of the PostScript to PDF (by ghostscript or Distiller) will consolidate the figures, as will direct production of PDF via pdftex.

In the case that small PostScript files are the desired outcome, the FAQ offers several techniques (of varying sneakiness) to ensure that multiply-included graphics are only inserted once.

-