HOME
 
  INFORMATION
   Curriculum vitae (PDF)
   Publication list
 
  RESEARCH & PROJECTS
   Projects
   Publications
   Teaching
 
  RESOURCES
   TeX & LaTeX
   Linux
 
  LINKS
   VisioWave
   ITS
   MultiMedia SPL
   My alumni ITS page
 
  MISC
   Swiss Train Schedules
 
Created by XEmacs
Valid HTML 4.0!

High quality PDF output from LaTeX and TeX

When converting PostScript output from TeX or LaTeX to PDF, the resulting documents are of very low quality, if no special steps are taken to avoid font rendering problems.

There are several ways of producing PDF output from LaTeX/TeX files. The one I use is to produce a PostScript file, using dvips, and then convert that to PDF using Acrobat Distiller or GhostScript's ps2pdf command. This is the approach covered here, although some of it might be applicable to other ones.

The problem is that by default TeX/LaTeX uses bitmap (i.e., Type 3) fonts instead of scalable Type 1 or TrueType fonts. These bitmap fonts are generated at the printer's resolution, which is typically 300 or 600 dpi. Changing the resolution of bitmap fonts is no easy task and therefore the PDF readers produce terrible results when displaying these fonts on the screen. Furthermore, printing quality can be quite deceiving if the printer's resolution does not match the one of the bitmap font.

The solution to the problem is to force TeX/LaTeX to use Type 1 fonts in the PostScript output (PS). Since these fonts are scalable then the PDF file will display and print well at all resolutions.

In order to force Type 1 fonts there are basically two ways that I know of: use the standard PostScript fonts and/or use Type 1 versions of the Computer Modern fonts. These approaches can, in general, be used together.

Computer Modern (CM) fonts are the original TeX fonts designed by Knuth, which are used by default in many TeX/LaTeX distributions. There also exist the EC fonts, which are basically the same but with an extended encoding, providing more characters for non-English alphabets.

Note that you can additionally use the hyperref package to generate hyperlinked PDF files, as explained in my hyperref page.

Short version

Follow these steps to get a good looking PDF file with LaTeX. If you still experience problems, or are curious, keep on reading the long explanation.
  1. Make sure you have one of the following in your latex preamble.
    1. To use the CM and EC fonts (usually recommended):
      \usepackage[T1]{fontenc}
      \usepackage{ae,aecompl}
      Optionally the aeguill package can also be loaded to get French guillemets.
    2. To use standard PostScript fonts:
      \usepackage[T1]{fontenc}
      \usepackage{pslatex}
      Alternatively, you can use the pslatex command in step 2 below instead of latex, which automatically includes the pslatex package.
  2. Compile your latex file as usual. For example:
    latex file.tex
  3. Convert to PostScript with the following command (replace a4 by letter if using US letter paper):
    dvips -t a4 -Ppdf file.dvi
    This will create a file with the same name and the .ps extension. If you have a dvips version earlier than 5.90 and you see problems with ligatures (e.g., ff) being converted to strange characters use the following:
    dvips -t a4 -Ppdf -G0 file.dvi
    (this can however create some problems with some versions of Acrobat Reader). If you have an old dvips that does not have the pdf pseudo printer, use
    dvips -t a4 -Pcmz -Pamz file.dvi -o
  4. Convert the PostScript file to PDF with ps2pdf or using Acrobat Distiller. For example:
    ps2pdf file.ps

The file should now display and print with very good quality. Note that when using the EC fonts, some characters may be poorly rendered since they are not available as Type 1 fonts and a bitmap is used instead. This should only affect some accented characters and eastern European languages.

Long version

The font encoding

LaTeX can use several font encodings. Typical installations use the OT1 encoding by default, which is the original encoding. However, this encoding is suitable to English only. The more recent T1 encoding includes accented characters and can handle hyphenation of words with accented characters. T1 is therefore the recommended encoding. To define the encoding include the following at the start of the LaTeX preamble:

\usepackage[T1]{fontenc}

The type of encoding determines which font is used by default. The OT1 encoding uses the Computer Modern (CM) fonts, while the T1 encoding uses the EC fonts, which are the same as CM but with more glyphs defined.

Using the Type 1 versions of CM or EC fonts

Modern LaTeX distributions include Type 1 versions of the CM fonts, under the collective name of bluesky. Otherwise they can be obtained from CTAN. There are unfortunately no freely available Type 1 version of the EC fonts, so they need to be emulated from the CM ones.

If you are using the OT1 encoding nothing particular needs to be done to generate the DVI file. With the T1 encoding the following needs to be included in your preamble:

\usepackage{ae,aecompl}
This will substitute the EC fonts with equivalents of the CM fonts, so that Type 1 versions of the characters are available when generating the PDF. The few symbols in the EC font that cannot be emulated from the ones in the CM fonts are taken from the bitmap EC fonts.

You can also include the aeguill package to get French guillemets. Note that including the ae package will automatically set your font encoding to T1.

Using standard PostScript fonts

Alternatively to the CM or EC fonts one can use the standard PostScript fonts for the document text. LaTeX includes some packages that replace the CM or EC text fonts with standard PostScript fonts, which are Type 1 and available in any PostScript or PDF printer or reader.

There are several such packages, providing different font substitutions. The main ones are: times, palatino, newcent and bookman. The times package will use Times-Roman for the roman font, Courier for typewriter and Helvetica for sans serif. To use it add

\usepackage{times}
to your preamble. For more information on these and other similar packages consult the psnfss2e documentation that comes with your LaTeX system.

Note that since the fonts are different from the CM or EC ones, the output will be modified. Note also that equations still use the CM fonts and thus equations that mix text and mathematical symbols can appear distorted, due to the font mismatch.

The pslatex package solves the font mismatch problem by scaling the fonts and using a mix of Times-Roman italic, CM and other fonts for the math mode. It is otherwise similar to the times package. To use it add

\usepackage{pslatex}
to your preamble, instead of times or any other such package. Alternatively, if you use the pslatex command to compile your file, instead of latex, the package is automatically included and no modification is necessary. Again, since the fonts are not the same as the default CM or EC fonts the output will look different.

No that, as far as I know, any package selecting PostScript fonts as default cannot be used in conjunction with the ae and aecompl packages since they both redefine the default font.

Generating a proper PS file

In LaTeX distributions the dvips command will by default use the bitmap CM fonts instead of the Type 1 versions. It is therefore necessary to explicitly tell it to use the former. In recent LaTeX distributions this is done with the command

dvips -Ppdf file.dvi
The pdf pseudo printer will use the Type 1 version of the fonts, whenever available, and will set some other options to better match PDF requirements (e.g., set a very high nominal resolution to avoid some "optimizations"). It will create a file with the same name and a .ps extension.

Some versions of Acrobat Reader have problems with fonts that have characters in positions where the standard Adobe fonts do not, as is the case with most LaTeX fonts. To solve this problem the -G1 switch of dvips will relocate such characters to harmless positions. This is enabled by default with the pdf pseudo printer. On dvips versions earlier than 5.90 this will however create problems with ligatures in some fonts, where they are converted to strange characters. If you have such problems use the -G0 option to disable character remapping, such as:

dvips -Ppdf -G0 file.dvi

Old versions of dvips do not have a pdf pseudo printer. The use of Type 1 fonts can, however, be forced with the following command line:

dvips -Pcmz -Pamz file.dvi -o
Note however that this will not set other options that benefit PDF creation.

If you have used the standard PostScript fonts instead of LaTeX CM or EC fonts, the Type 1 versions are used by default (as they are only available as Type 1). Nevertheless, some characters from the CM fonts are still used and the special options for dvips are required to get optimal results.

There is also another issue that arises from TeX's poor handling of the paper size. Although the DVI file will be typeset correctly for the paper size specified in the document class options, dvips will not explicitely set the paper size in the PS file, in an attempt to produce portable PS. However, PS to PDF converters will assume a default size (typically US letter) that may not match the actual paper size (typically A4 outside North America). Furthermore, depending on the distribution dvips will assume A4 or letter as the default paper size for converting from DVI to PS coordinates. It is therefore safer, and often necessary, to explicitely tell dvips to set the PS paper size with the -t option. For example:

dvips -t a4 -Ppdf -G0 file.dvi
If you are using US letter paper replace a4 by letter.

Converting to PDF

The PS file generated above can be converted to PDF using Acrobat Distiller or GhostScript's ps2pdf command. Using Distiller is rather user-friendly and not covered here.

GhostScript's ps2pdf utility does a very good job converting to PDF. Note however that versions up to than 5.50 will convert any Type 1 font other than the standard PostScript fonts to Type 3 (i.e., bitmap) fonts, so make sure you use version 6.50 at least.

To convert to PDF use the command:

ps2pdf file.ps
This will create a file with the same name and the .pdf extension. The PDF version used will be GhostScript's default, which is currently 1.2. To generate specific PDF versions you can use the ps2pdf12, ps2pdf13 or ps2pdf14 commands, which will generate PDF files compatible with Acrobat Reader versions 3 and later, 4 and later and 5 and later, respectively.

Several profiles are provided that select different sets of options and are similar to Distiller's settings. They are:

  • /screen selects low-resolution output similar to Distiller's "Screen Optimized" setting.
  • /printer selects output similar to Distiller's "Print Optimized" setting.
  • /prepress selects output similar to Distiller's "Prepress Optimized" setting.
  • /default selects good quality output for general purpose use, even if the file size might be larger than in the /screen profile.
The profile can be selected with the -dPDFSETTINGS option. For example:
ps2pdf13 -dPDFSETTINGS=/screen file.ps

If the paper size was not explicitely set when creating the PS file, it can be specified in the ps2pdf command line. For example:

ps2pdf13 -sPAPERSIZE=a4 -dPDFSETTINGS=/screen file.ps
Note that Acrobat Reader on Linux/Unix, up to at least version 5.06, has a bug handling the paper size when printing. Although the page setup dialog says A4 as the paper size, you have to select it again each time Acrobat Reader is started, as the setting is only partially saved. If this is not done, the printed file will have A4 set as the paper size but all the computations done for letter, leading to bogus margins.

More specific settings can also be set, refer to the Ps2pdf.htm file in your GhostScript's documentation (you can find it here for version 7.05).

Last Modified: Wednesday, 06-Apr-2005 20:42:44 W. Europe Daylight Time


Diego Santa Cruz