Home / Alt manpages / ps2pdf(1)

  • ps2pdf(1)
  • User command
  • linux

Convert PostScript to PDF with ps2pdf, Without Losing Compatibility

You will convert a PostScript file to PDF, choose an explicit PDF compatibility level when it matters, and verify the result before handing it to another system. The commands use Ghostscript 10.02.1, installed here from Ubuntu's ghostscript package. Allow about ten minutes for a normal file conversion, longer if you also need to investigate a damaged input or a downstream compatibility problem.

These examples are ordinary user commands. You do not normally need sudo: read the input from a directory you can access and write the PDF somewhere you own. Keep the original PostScript file until the PDF has been opened or otherwise checked.

1. Check the installed command

Confirm which wrapper will run and record the local Ghostscript version. This is a read-only checkpoint, so it does not need elevated privileges.

$ command -v ps2pdf
/usr/bin/ps2pdf
$ ghostscript --version
10.02.1

The manpage shipped with this installation is for Ghostscript 10.02.1. The wrapper accepts the same options as gs(1), but its job is to select the PDF device and pass the conversion request through. If a script depends on an exact output version, make that choice explicit rather than relying on the default.

2. Convert a file to the default PDF

Give ps2pdf an input PostScript or Encapsulated PostScript file and an output name:

$ ps2pdf /path/to/report.ps /path/to/report.pdf

A successful run normally produces no progress message. Check both the exit status and the output file:

$ printf 'exit status: %s\n' "$?"
exit status: 0
$ file /path/to/report.pdf
/path/to/report.pdf: PDF document, version 1.4, ...

If you omit the second filename, the command writes a PDF with the input's name and a .pdf extension in the current directory. That default is convenient for a one-off conversion, but it can put the result somewhere unexpected if you are not watching your working directory:

$ cd /path/to/working-directory
$ ps2pdf report.ps
$ ls -l report.ps report.pdf

Shell redirection and an explicit output path are easier to audit in scripts. Also remember that writing an existing output path can replace its contents. Choose a new filename or make a backup before rerunning a conversion whose result matters.

3. Choose the PDF compatibility level

On this installation, plain ps2pdf currently produces PDF 1.4. The manpage warns that this default may change. Use an alias when a consumer has a documented limit:

CommandOutput versionCompatibility described by the manpage
ps2pdf12PDF 1.2Acrobat 3 and later
ps2pdf13PDF 1.3Acrobat 4 and later
ps2pdf14PDF 1.4Acrobat 5 and later

For example, this creates a PDF 1.3 file:

$ ps2pdf13 /path/to/report.ps /path/to/report-pdf13.pdf
$ pdfinfo /path/to/report-pdf13.pdf | grep '^PDF version:'
PDF version:     1.3

You can also select a level with the Ghostscript switch shown in the manual:

$ ps2pdf -dCompatibilityLevel=1.3 /path/to/report.ps /path/to/report-pdf13.pdf

Use one method consistently. The numbered wrappers make the intended contract obvious to a reader reviewing a script, while the switch is useful when you are already passing other Ghostscript options.

4. Use ps2pdf in a pipeline

A hyphen means standard input or standard output. This lets another program generate PostScript and lets a later command consume the PDF without an intermediate file:

$ make_report.pl -t ps | ps2pdf13 - - | lpr

The first hyphen tells ps2pdf13 to read PostScript from standard input. The second tells it to write PDF to standard output. Keep both hyphens: a missing one changes the argument positions and can make the wrapper interpret a filename as the input or output.

For a safer first test, capture the stream into a new file and inspect it before sending it to a printer or another service:

$ make_report.pl -t ps | ps2pdf13 - /tmp/report-test.pdf
$ file /tmp/report-test.pdf
/tmp/report-test.pdf: PDF document, version 1.3, ...

Standard output is binary PDF data. Do not pipe it through a command that expects text, and do not use a terminal as the destination. A terminal can interpret control bytes and make the output difficult to recover or inspect.

5. Make a higher-quality conversion deliberately

The manpage gives -dPDFSETTINGS=/prepress as an example of a more specific conversion. Treat this as a deliberate output choice, not a universal quality upgrade:

$ ps2pdf -dPDFSETTINGS=/prepress /path/to/artwork.ps /path/to/artwork-proof.pdf

Different settings can change file size, image handling and the suitability of the result for a particular workflow. Compare the generated PDF with the source and with the requirements of the printer, archive or document system. If you need PDF/A or PDF/X, consult the installed Ghostscript documentation and the receiving system's conformance requirements; producing a file with a familiar extension is not proof that it meets a preservation or print standard.

6. Diagnose failures without damaging the source

If the command fails, first check the input path and permissions without changing anything:

$ ls -l /path/to/report.ps
$ file /path/to/report.ps

A missing input, an unreadable file, malformed PostScript and a destination that cannot be created are different problems. Read the diagnostic printed by Ghostscript and check the command's status immediately:

$ ps2pdf /path/to/report.ps /path/to/report.pdf
$ status=$?
$ printf 'ps2pdf status: %s\n' "$status"
ps2pdf status: 0

If the status is non-zero, do not treat a partially written PDF as usable. Write the next attempt to a new name, then replace the old result only after verification. A simple recovery pattern is:

$ ps2pdf /path/to/report.ps /path/to/report.pdf.new
$ pdfinfo /path/to/report.pdf.new
$ mv /path/to/report.pdf.new /path/to/report.pdf

The final mv changes the destination name, so run it only after the new PDF passes your checks. If conversion fails, leave the original PDF alone and investigate the error. Remove an unwanted temporary file only when you are certain it contains no useful result.

Done means

  • The input PostScript remains available for another conversion.
  • The PDF exists at the path you intended and has a successful conversion status.
  • file or pdfinfo confirms that the output is a readable PDF.
  • The selected compatibility level matches the oldest consumer that must open it.
  • A pipeline was tested with a temporary destination before its output was sent to a printer or service.