1

I am using

$ pdflatex --version
pdfTeX 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian)
kpathsea version 6.2.3

to compile a 30-page pdf output. Twelve of the pages look like this (the rest are only text):

enter image description here

All items are generated by this code:

\newcommand{\weapon}[8]
{
\begin{multicols}{2}
  \noindent \textbf{#2} \\
  Необходима сила: #3  \\
  Обсег: #4  \\
  Щети: #5  \\
  Свойства: #6  \\
  Маса: #7  \\
  Стойност: #8  \\
  \includegraphics[height=0.13\textheight]{../images/#1}~
\end{multicols}
\vspace{0.01cm}
}

This bring the file size to:

remote: warning: File build/elementaris-fantasy.pdf is 63.06 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB

The images I am using are not scaled and some of them are quire large.

How can I reduce the size of the PDF file? The purpose of the PDF is to be printed on sheets of paper as reference for a game.

  • 1
    You will have to produce smaller versions of the images. – Ulrike Fischer Mar 17 '18 at 11:42
  • @UlrikeFischer I could, of course, scale them with GIMP. But that would make later rescaling more difficult. Is this the recommended solution? – Vorac Mar 17 '18 at 11:45
  • 1
    pdflatex can't change the size of images. If they are large you will get a large pdf, if you don't want this you will have to change they file size -- how at best depends on the images. – Ulrike Fischer Mar 17 '18 at 11:55
  • 2
    What is the sum of the image sizes? Have you changed \pdfcompresslevel? (It should be set to 9 for maximum compression). What are the image formats (PNG, JPEG, PDF, ...)? In case of PNG, what tells the .log about the inclusion? – Heiko Oberdiek Mar 17 '18 at 12:19
  • 2
    If the purpose is to be printed (to paper): Color images print best at 300 pixels per inch (118.11 per centimeter), more or less. Except for art-quality print, there is no benefit to higher resolution, because the printed images will be screened. It is best to provide the images at exact size, without scaling or cropping. Although it depends on the image, JPG format at quality 90% is usually best. – user139954 Mar 17 '18 at 15:30
3

You can use \DeclareGraphicsRule to call a resize command (externally) on files with the specified extension. The pdf will be smaller because it uses the resized image file.

In the MWE below the size is hardcoded to a height of 100px. The rule can be declared and subsequently replaced by a dummy rule at any point in the document, to avoid resizing jpg files in other parts of the document. Note however that the conversion is cached per file, so you cannot include a resized image and later include the full-size image from the same file.

The example image is taken from Wikipedia (https://commons.wikimedia.org/wiki/File:Bodiam-castle-10My8-1197.jpg).

Code (compile with --shell-escape):

\documentclass{article}
\usepackage{graphicx}
\begin{document}
% remove these two lines to reduce the pdf filesize
Before \texttt{\textbackslash DeclareGraphicsRule}:\\
\includegraphics[scale=0.2]{Bodiam-castle-10My8-1197.jpg}

% resize rule
\DeclareGraphicsRule{.jpg}{jpg}{.jpg}{`convert -geometry x100 #1 `basename #1 .jpg`-jpg-converted-to.jpg}

After \texttt{\textbackslash DeclareGraphicsRule}:\\
\includegraphics[scale=1.0]{Bodiam-castle-10My8-1197.jpg}
% dummy rule
\DeclareGraphicsRule{.jpg}{jpg}{.jpg}{`convert #1 `basename #1 .jpg`-jpg-converted-to.jpg}
\end{document}

Result:

enter image description here

0

You can compress the pdf using ghostscript. The relevant command line option is -dPDFSETTINGS= (see this question for details).

I use the following script for the compression (to medium resolution):

#!/bin/bash
INPUT="$1"
if [[ ! -f "$INPUT" ]]; then
   echo "File not exist \"$INPUT\""
   exit 1
fi
OUTPUT="$2"
if [[ -f "$2" ]]; then
    echo "File exists \"$2\""
    exit 1
fi
OUTPUT=${OUTPUT:-${INPUT%.*}.pdf}
[[ $# > 2 ]] && (echo "Extra arguments found: \"$*\""; exit 1)
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile="$OUTPUT" "$INPUT"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.