Home / Alt manpages / ps2pdf(1)

  • ps2pdf(1)
  • User command
  • linux

Convert PostScript to PDF with ps2pdf

ps2pdf turns a PostScript file into PDF and lets you pin down an exact compatibility level when a downstream system is picky about it. 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 are ordinary user commands: read the input from a directory you can access and write the PDF somewhere you own, no sudo needed. 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:

$ cd /path/to/working-directory
$ ps2pdf report.ps
$ ls -l report.ps report.pdf
  • Convenient, but easy to lose track of. The default can put the result somewhere unexpected if you are not watching your working directory.
  • Prefer an explicit output path in scripts. Shell redirection and a named path are easier to audit.

Warning

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

Tip

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.

Tip

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, ...

Warning

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

Recovery

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:

$ 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

  • Source kept: the input PostScript remains available for another conversion.
  • PDF exists: at the path you intended and has a successful conversion status.
  • Output verified: file or pdfinfo confirms the output is a readable PDF.
  • Compatibility matched: the selected level matches the oldest consumer that must open it.
  • Pipeline tested: a temporary destination was checked before its output was sent to a printer or service.