You need to enable shell escapes. With MiKTeX you do -enable-write18
and with TeXlive -shell-escape
.
You can set up different conversion rules with the epstopdf package
\documentclass{article}
\usepackage{graphicx}
\usepackage{epstopdf}
\epstopdfDeclareGraphicsRule
{.gif}{png}{.png}{convert gif:\SourceFile.\SourceExt png:\OutputFile}
\AppendGraphicsExtensions{.gif}
\begin{document}
\includegraphics{test.gif}
\end{document}
Using epstopdf
you can control if the conversion should be done every time you compile or only if the target file is missing.
There is no package makemypdfsmaller.sty
which reduces the PDF
file size without removing information. However, there are a few
things you can do:
Reduce number of images
Do you really need to include eighteen images? Maybe sixteen or
twelve is enough.
Reduce image size
You can use imagemagick (or gimp or …) to reduce the image size. You
have to experiment which values are acceptable.
convert -geometry 75% input.png output.png
Reduce amount of colours
Especially when the image contains text on white background or just
a few colours, like certificates often do, you can significantly
reduce the image size. Try different values, e.g. 4, 8, 16
convert -colors 16 input.png output.png
Run optipng
on the file
The program optipng
can shrink the file about one to four percent
more after you have reduced the amount of colours. Not much, but
it's lossless. The slowest setting with the highest compression is -o7
.
optipng -o7 input.png
Increase PDF compression
Set \pdfcompresslevel9
. This also does not help much, but maybe it
helps to squeeze it just enough to fit into a file size limit.
Reducing the final PDF
When you already created the PDF or you don't have access to the
images any more, you can use ghostscript to reduce the resolution of
the final PDF. Use for instance the setting -dPDFSETTINGS=/ebook
. Here is
an example.
gs \
-sOutputFile=output_file.pdf \
-sDEVICE=pdfwrite \
-dNOPAUSE \
-dBATCH \
-dPDFSETTINGS=/ebook \
input_file.pdf
/ebook
sets the resolution to 150 DPI. Other settings are
/screen
(75 DPI) or /print
(300 DPI).
Best Answer
The order of preference when files with the same name and different extensions is
which is stored in the macro
\Gin@extensions
. So if you have bothimage.png
andimage.pdf
,pdflatex
will load the former.If you are mixing case in extensions, then
will ensure that PNG are always preferred over PDF files. For the final version it will be sufficient to switch the two lines.
A handier way, suggested by Heiko Oberdiek, is to use the package
grfext
:that will have the same effect without the need to check in
pdftex.def
for the list of extensions.If you want also automatic conversion, you can say
When
image.pdf
exists but notimage.png
, the fileimage-pdf-converted-to.png
will be created and loaded in its place. Add the options you prefer betweenconvert
and#1
(for example-density 100
or something like that).You need to call
pdflatex
with the--shell-escape
option for this automatic conversion to work. Of course you'll comment out the\epstopdfDeclareGraphicsRule
command for the final version, when only PDF files should be loaded (and switch the order of precedence in the lines below).