Taking a 2284 line source file (language=C) and embedding into a LaTeX document using \usepackage{listings} produces a PDF of around 150KB. The original source file is 78KB.
By itself this is acceptable, but I'm building a complete project document with hundreds of source files. My final document is now around 22MB of source listings!
Previously I've used GNU Enscript to produce postscript output from source. Using the same source file as above, Enscript produced a postscript file of 211KB, and then ps2pdf produced a PDF of 50KB; about a third the size of 'listings' package.
Below are my 'listings' settings. I'm using pdflatex and MiKTeX 2.9. Is there anything I can change to help reduce the file size? Why the disparity between Enscript and 'listings'?
\documentclass{article}
\usepackage{listings}
\usepackage{color}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\lstset{
language=C,
basicstyle=\footnotesize\ttfamily,
keywordstyle=\color{blue},
commentstyle=\color{dkgreen},
stringstyle=\color{mauve},
numbers=left
}
\begin{document}
\lstinputlisting{my_main.c}
\end{document}
Thanks, Chris
====
Edit: To add difference between postscript outputs.
Please see the postscript outputs below. I created a short 'hello world' C file which I ran through both Enscript and LaTeX (via listings) to produce some postscript output for comparison.
The Enscript output appears more concise, whilst the LaTeX (listings) is rather fragmented, and I can only conclude is what is greatly increasing my final PDF sizes. Does this postscript output from 'listings' look correct?
C code:
#include <stdio.h>
int main(int)
{
/* This is a comment, can you see me in LaTeX? */
printf("Hello World!\n");
return 1;
}
Enscript postscript output:
<snip>
/Courier-Oblique 8 8 SUF
0.133333 0.545098 0.133333 setrgbcolor
19.4 732 M
(/* This is a comment, can you see me in LaTeX? */) s
/F-gs-font 8 8 SF
0 setgray
5 723 M
( printf\() s
/Courier-Bold 8 8 SUF
0 setgray
53 723 M
("Hello World!\\n") s
/F-gs-font 8 8 SF
0 setgray
129.8 723 M
(\);) s
5 714 M
( ) s
LaTeX listings postscript output:
TeXcolorrgb Black 0 0.6 0 TeXcolorrgb 216 w Fb(/)5
b(*)p Black 0 0.6 0 TeXcolorrgb Black 0 0.6 0 TeXcolorrgb
53 w(T)h(h)g(i)g(s)p Black 0 0.6 0 TeXcolorrgb Black
0 0.6 0 TeXcolorrgb 53 w(i)f(s)p Black 0 0.6 0 TeXcolorrgb
Black 0 0.6 0 TeXcolorrgb 51 w(a)p Black 0 0.6 0 TeXcolorrgb
Black 0 0.6 0 TeXcolorrgb 50 w(c)g(o)g(m)g(m)g(e)g(n)g(t)p
Black 0 0.6 0 TeXcolorrgb 21 w(,)p Black 0 0.6 0 TeXcolorrgb
Black 0 0.6 0 TeXcolorrgb 50 w(c)g(a)g(n)p Black 0 0.6 0
TeXcolorrgb Black 0 0.6 0 TeXcolorrgb 55 w(y)g(o)g(u)p
Black 0 0.6 0 TeXcolorrgb Black 0 0.6 0 TeXcolorrgb 54
w(s)g(e)g(e)p Black 0 0.6 0 TeXcolorrgb Black 0 0.6 0
TeXcolorrgb 54 w(m)g(e)p Black 0 0.6 0 TeXcolorrgb Black
0 0.6 0 TeXcolorrgb 52 w(i)g(n)p Black 0 0.6 0 TeXcolorrgb
Black 0 0.6 0 TeXcolorrgb 53 w(L)h(a)g(T)g(e)g(X)p Black
0 0.6 0 TeXcolorrgb 11 w(?)p Black 0 0.6 0 TeXcolorrgb
Black 0 0.6 0 TeXcolorrgb 51 w(*)f(/)p Black 396 917
a Fc(6)217 b Fb(p)6 b(r)g(i)g(n)g(t)g(f)11 b(\()p 0.58 0 0.82
TeXcolorrgb 8 w(")p Black 0.58 0 0.82 TeXcolorrgb 10
w(H)6 b(e)g(l)g(l)g(o)p Black 0.58 0 0.82 TeXcolorrgb
10 w( )p Black 0.58 0 0.82 TeXcolorrgb 10 w(W)g(o)g(r)g(l)g(d)p
Black 0.58 0 0.82 TeXcolorrgb 11 w(!)f(\\)p Black 0.58 0 0.82
TeXcolorrgb 9 w(n)p Black 0.58 0 0.82 TeXcolorrgb 7 w(")p
Black 9 w(\))g(;)