11

My instructor demands a maximum size of submitted assignment of 50kb in PDF-format. Whenever I try to build from PDFLatex the files exceed this limit.

I expected the problem to be related to bitmap encoding of fonts and tried to update my cm-super package, but this did not work. I then cross checked with different font encodings using \usepackage[T1]{fontenc} and \usepackage[OT1]{fontenc} but nothing seems to make the PDF smaller.

My minimal working example is

\documentclass[10pt,a4paper,oneside]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{lipsum}

\title{Test}
\author{John doe}
\begin{document}

\maketitle

\section{This is a test}

\lipsum

\end{document}

This produces a PDF of 48.5 kB, which would be okay if my submissions for the assignments were this small. I expect the generated PDF to be a lot smaller since the .tex file is 295b. I use Tex Live 2013 on Ubuntu 14.04 and the cm-super package is in the newest version. Please help me.

10
  • 2
    Why on earth only 50kb? BTW that is the size if you use the lmodern package?
    – daleif
    Commented Sep 11, 2014 at 14:14
  • 11
    What kind of insane limit is that? It's not like we are still in the year 1980. Even an empty PDF file saved with MS Word is already over 78 kB.
    – Fritz
    Commented Sep 11, 2014 at 14:15
  • Please ask the instructor on how to do this in any system? In my book, PDF files that only refer to fonts are not applicable since they are not portable.
    – daleif
    Commented Sep 11, 2014 at 14:17
  • 4
    This is a ridiculous requirement and I would respectfully direct your supervisor to this page. In the meantime, however, you can try any of tex.stackexchange.com/q/2198/17423 or tex.stackexchange.com/q/75535/17423. I'm tempted to think the limit as posted is an error of magnitude; 500kb is a much more reasonable limit. Commented Sep 11, 2014 at 14:18
  • 4
    You can use one of the Standard Type 1 Fonts (Standard 14 Fonts) (en.wikipedia.org/wiki/…) (Times. Courier, Helvetica) and forbid embedding them. PDF readers must have 'local' copies of these fonts. Embeded fonts are quite big if you only have 50kb. But this is just as braindead as your instructor.
    – Josef
    Commented Sep 11, 2014 at 14:57

3 Answers 3

11

It's not sure it will be longer for an assignment: most of the size comes from font embedding in pdf, which does not really depend on what you put in your file.

That said, I've made a little test with your MWE, changing the compiler or the font encoding: with OT1 encoding:

  • latex+dvips+ps2pdf: 22 KB
  • latex+dvipdfmx: 13.34 KB
  • pdflatex: 49.84 KB
  • lualatex: 49.37 KB
  • xelatex: 13.2 KB

With T1 encoding and loading the Latin Modern fonts

  • latex+dvips+ps2pdf: 22.57 KB
  • latex+dvipdfmx: 13.66 KB
  • pdflatex: 99.95 KB
  • lualatex: 49.37 KB
  • xelatex: 13.65 KB

I can't explain these differences between a direct way to .pdf (pdflatex, lualatex) and the way through dvi or xdvi. Perhaps in one case all glyphs are embedded, and in the other, only the necessary glyphs are embedded? That would explain the very different sizes for the pdflatex way between T1 and OT1 font encoding: Latin Modern has much more glyphs than Computer Modern.

4
  • 1
    “Ko” is used only in France and perhaps other French speaking countries. The international symbol is “KiB” or “KB” (the latter being, properly, 1000B and not 1024B).
    – egreg
    Commented Sep 11, 2014 at 15:09
  • Oops! I was distracted. However, there does exist the Kio symbol, or am I dreaming?
    – Bernard
    Commented Sep 11, 2014 at 16:20
  • I don't know about “Kio”. I just wanted to remark the meaning of the symbol for non French speaking people.
    – egreg
    Commented Sep 11, 2014 at 16:24
  • Of course — it's just that I had already met in an (international) english context, and wondered if you knew something about it.
    – Bernard
    Commented Sep 11, 2014 at 16:34
12

Use ghostscript to compress your PDF.

gswin64c -dCompatibilityLevel=1.5 -dAutoRotatePages=/None -dQUIET -sDEVICE=pdfwrite -o "out.pdf" "in.pdf"

I got 19.38KB.

3
  • 2
    Oh my ghost! This answer uses ghost script! :-) Commented Sep 11, 2014 at 17:03
  • Warning: Do use ghostscript to compress PDF from pdflatex ONLY. Commented Sep 11, 2014 at 18:17
  • Could you elaborate on what this is actually doing? Why is my PDF suddenly 56.5MB smaller? (57MB to 260KB) From other answers I understand that it has something to do with embedded fonts, is ghostscript stripping those? Commented May 24, 2020 at 15:05
6

You can limit the size by avoiding font inclusion as much as possible and rely on the PDF viewer to supply the fonts, although this practice is discouraged even for the “standard 35” Adobe fonts, nowadays.

Write the file nodownload.map next to your main document

phvb8r Helvetica-Bold 0 "TeXBase1Encoding ReEncodeFont" <8r.enc
phvb8y Helvetica-Bold 0 "TeXnANSIEncoding ReEncodeFont" <texnansi.enc
phvbo8r Helvetica-BoldOblique 64 "TeXBase1Encoding ReEncodeFont" <8r.enc
phvbo8y Helvetica-BoldOblique 64 "TeXnANSIEncoding ReEncodeFont" <texnansi.enc
phvr8r Helvetica 0 "TeXBase1Encoding ReEncodeFont" <8r.enc
phvr8y Helvetica 0 "TeXnANSIEncoding ReEncodeFont" <texnansi.enc
phvro8r Helvetica-Oblique 64 "TeXBase1Encoding ReEncodeFont" <8r.enc
phvro8y Helvetica-Oblique 64 "TeXnANSIEncoding ReEncodeFont" <texnansi.enc
psyr Symbol 3
ptmb8r Times-Bold 2 "TeXBase1Encoding ReEncodeFont" <8r.enc
ptmb8y Times-Bold 2 "TeXnANSIEncoding ReEncodeFont" <texnansi.enc
ptmbi8r Times-BoldItalic 66 "TeXBase1Encoding ReEncodeFont" <8r.enc
ptmbi8y Times-BoldItalic 66 "TeXnANSIEncoding ReEncodeFont" <texnansi.enc
ptmr8r Times-Roman 2 "TeXBase1Encoding ReEncodeFont" <8r.enc
ptmr8y Times-Roman 2 "TeXnANSIEncoding ReEncodeFont" <texnansi.enc
ptmri8r Times-Italic 66 "TeXBase1Encoding ReEncodeFont" <8r.enc
ptmri8y Times-Italic 66 "TeXnANSIEncoding ReEncodeFont" <texnansi.enc

Now compiling the following example

\pdfmapfile{=nodownload.map}
\documentclass[10pt,a4paper,oneside]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathptmx}
\usepackage[scaled]{helvet}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{lipsum}

\title{Test}
\author{John doe}
\begin{document}

\maketitle

\section{This is a test}

\textsf{Abc\itshape def} and an integral
\[
\int_{-\infty}^{\infty}e^{-x^{2}}\,dx=\sqrt{\pi}
\]
\lipsum

\end{document}

produces, for me, a 29 KiB PDF file. To be sure the compression is as high as possible, add the line

\pdfcompresslevel=9

at the beginning, although this shouldn't be necessary.

But 50 KiB for a PDF file is too strict a requirement in any case. I tried pasting the “lipsum” text in a word processor I happen to own (not that one) and print it to a PDF file. Fonts are included even if Times is used.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .