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.

  • 2
    Why on earth only 50kb? BTW that is the size if you use the lmodern package? – daleif Sep 11 '14 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 Sep 11 '14 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 Sep 11 '14 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 http://tex.stackexchange.com/q/2198/17423 or http://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. – Sean Allred Sep 11 '14 at 14:18
  • I guess one solution would be to hand-code the PDF file, if your assignment contains only text: http://brendanzagaeski.appspot.com/0005.html – Fritz Sep 11 '14 at 14:19
  • 4
    You can use one of the Standard Type 1 Fonts (Standard 14 Fonts) (https://en.wikipedia.org/wiki/Portable_Document_Format#Standard_Type_1_Fonts_.28Standard_14_Fonts.29) (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 Sep 11 '14 at 14:57
  • AR on Linux will substitute them thus rather end result will look wrong when printed – daleif Sep 11 '14 at 17:34
  • @daleif That shouldn't be the case: "These fonts, or suitable substitute fonts with the same metrics, must always be available in all PDF readers and so need not be embedded in a PDF. PDF viewers must know about the metrics of these fonts." OTOH, we've just had a thread in the german pdf newsgroup, that a bank sent account informations without embedded Arial-BoldMT causing immense trouble under Linux. – Josef Sep 11 '14 at 19:37
  • That is not what we observe – daleif Sep 11 '14 at 19:43
  • Thank you all for the feedback! I switched to XeLaTeX and switched the necessary packages specified by http://tex.stackexchange.com/q/2984/30671. I also disabled all of activities from the hyperref package in order to maintain the size further down. My instructor wont budge to our wishes to use PDFLaTeX, but now I can at least upload the assignments... – Anders Larsen Sep 12 '14 at 06:27

3 Answers3

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.

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.

Bernard
  • 271,350
  • 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 Sep 11 '14 at 15:09
  • Oops! I was distracted. However, there does exist the Kio symbol, or am I dreaming? – Bernard Sep 11 '14 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 Sep 11 '14 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 Sep 11 '14 at 16:34
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.

egreg
  • 1,121,712