[ ESO ]

PostScript to PDF conversion

How to convert PostScript into Portable Document Format

1. Using ps2pdf

The simplest way to convert PostScript files into PDF on our Linux machines is to use the ps2pdf command, e.g. ps2pdf file.ps file.pdf. This works fine when only one PostScript file has to be converted. Further details can be found on the ps2pdf manual page .

2. Using ghostscript

Ps2pdf is a simple wrapper around ghostscript (gs). The limitations of ps2pdf can be avoided by using gs directly. The device pdfwrite has to be specified in this case. A safe call of gs is:
gs -q -dSAFER -dNOPAUSE -dBATCH -sOutputFile=file.pdf -sDEVICE=pdfwrite -c .setpdfwrite "-c <</Orientation 3>> setpagedevice" -f *ps
This command would convert all PS files in the current directory into one PDF file. If all original files contain only one page then the resulting PDF document would have have one page for each file. The option "-c <</Orientation 3>> setpagedevice" is necessary if you want to rotate the PS files for viewing on the screen, what is the case for my files. The option -c .setpdfwrite seems to be necessary in order to enable the rotation feature.

The output PDF file can be viewed with Acrobat Reader and prints out fine. I have not observed losses in printing quality compared to the original PS files. The size of the PDF file is only about half of the total size of the PS files. This advantage, however, vanishes if the PS files are compressed (compression on PDF does not reduce the file size much).

3. Inserting bookmarks by using pdfmark operators

Bookmarks are a useful feature to enhance the readability of a PDF document. When converting PostScript into PDF, bookmarks (and other PDF features such as links or annotations) can be inserted by using the pdfmark PostScript extension. This allows to add information to PS files that is not normally present but is necessary for PDF specific features. The original PS files have to be edited.

1. Step: Add a line in the prolog section of the PS document so that PostScript interpreters that are not using pdfmark are not confused:
%% BeginProlog
/pdfmark where
{pop} {userdict /pdfmark /cleartomark load put} ifelse
%% EndProlog
2. Step: Add a pdfmark operator in the set-up section so that the list of bookmarks in the resulting PDF document is visible on the left hand side when the file is opened:
%% BeginSetup
[/PageMode /UseOutlines
/Page 1 /View [/XYZ null null null]
/DOCVIEW pdfmark
%% EndSetup
The /XYZ parameter specifies the place and the magnification of the page. /XYZ null null 2.0 would, for example, mean a zoom factor of 200%.

 3. Step: Add pdfmark bookmark operators. The place of the operators within the PS file does not seem to be important. I have added them at the beginning of the first page. Examples for bookmarks would be:

[/Page 1 /View [/XYZ null null null] /Title (Main QC plot) /OUT pdfmark
[/Page 2 /View [/XYZ null null null] /Title (Position check) /OUT pdfmark
[/Page 3 /View [/XYZ null null null] /Title (FWHM check) /OUT pdfmark

These operators would create three bookmarks, one for every page. If you convert several PS files into on PDF document then it is sufficient to edit only the first file.

I have created an example PDF document that contains three plots and a bookmark for every plot.

I have also written a small shell script in order to demonstrate automatic editing of PostScript files. The script adds a prolog section, a set-up section, and the pdfmark bookmark operators to an existing PS file. It makes some assumption on the file, i.e. that the prolog and set-up sections are not already present. The script is called by

add_pdfmark.sh in_ps_file out_ps_file bookmark_file

where bookmark_file is an ASCII file containing the pdfmark operators. It could, for example, contain the three lines written under step 3.

The script is available here .

4. Some links

Ps2pdf documentation
How to use ghostscript
pdfmark Reference Manual by Adobe

example PDF document
example of an edited PostScript document with pdfmark operators

QC home (external)
QC home (internal)