Convert PostScript to PDF with ps2pdfwr
You will finish with a PDF made from a PostScript or EPS input, a quick check that the file is usable, and a safe pattern for converting data from standard input. The examples use ps2pdfwr from Ghostscript 10.02.1, installed here as package version 10.02.1~dfsg1-0ubuntu7.9.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about ten minutes. You need a readable .ps or .eps file, a writable destination directory, and the Ghostscript package. These conversions normally run as your ordinary user. Do not use sudo unless the input or destination permissions genuinely require it.
1. Check the installed wrapper
Confirm which executable is in use and read its local usage line. This is read-only and does not need elevated privileges:
$ command -v ps2pdfwr
/usr/bin/ps2pdfwr
$ ps2pdfwr 2>&1 | head -n 1
Usage: ps2pdfwr [options...] (input.[e]ps|-) [output.pdf|-]
$ gs --version
10.02.1
The wrapper accepts options, then an input path or -, followed by an optional output path or -. The installed manpage describes it as a wrapper around gs with the PDF-writing device, batch mode, quiet mode and safe processing enabled.
Checkpoint: if command -v finds nothing, install Ghostscript through your normal package-management process. Do not copy a script from another host merely because its version looks similar.
2. Convert a PostScript file
Choose an output name that does not contain a useful PDF you still need. The command below reads the input and writes a new PDF:
$ ps2pdfwr /path/to/input.ps /path/to/output.pdf
A successful conversion is quiet and returns status zero. Check both the exit status and the resulting file:
$ printf 'exit status: %s\n' "$?"
exit status: 0
$ file /path/to/output.pdf
/path/to/output.pdf: PDF document, version 1.7, 1 page(s)
$ pdfinfo /path/to/output.pdf | grep -E 'PDF version|Pages|Page size'
Pages: 1
Page size: 612 x 792 pts (letter)
PDF version: 1.7
The wording from file and the page size will vary with the input. The useful checks are that the destination exists, identifies as PDF, and has the expected page count. If pdfinfo is not installed, use file and open the result with a trusted PDF reader.
3. Protect an existing output
Do not assume the wrapper will protect an existing destination. Ghostscript is being asked to produce the path you supplied, so make the overwrite decision explicit before running it:
$ test ! -e /path/to/output.pdf && ps2pdfwr /path/to/input.ps /path/to/output.pdf
output=/path/to/output.pdf
if test -e "$output"; then
printf 'Refusing to overwrite %s\n' "$output" >&2
exit 1
fi
ps2pdfwr /path/to/input.ps "$output"
Use one of these patterns, not both. The first is a compact guard for a one-off command. The second is easier to extend in a script. A failed conversion may leave an incomplete destination, so write to a temporary name in the same directory and rename it only after validation when the output matters:
$ tmp=/path/to/output.pdf.new
$ ps2pdfwr /path/to/input.ps "$tmp" && pdfinfo "$tmp" > /dev/null && mv -- "$tmp" /path/to/output.pdf
The mv replaces the old file only after conversion and a basic PDF read have succeeded. If the command fails, inspect or remove output.pdf.new manually; the original output remains in place. The replacement is a state-changing operation, so do not run it in a production directory without checking the destination first.
4. Convert standard input
Use - as the input when another command produces PostScript on standard output. Keep the output path as the final argument:
$ generate-postscript | ps2pdfwr - /path/to/generated.pdf
$ file /path/to/generated.pdf
/path/to/generated.pdf: PDF document, version 1.7, 1 page(s)
This is useful for a pipeline, but it also hides the original input if the producer is wrong. During troubleshooting, save the PostScript first so you can inspect and replay it:
$ generate-postscript > /tmp/generated.ps
$ ps2pdfwr /tmp/generated.ps /path/to/generated.pdf
You can send the PDF to standard output by using - as the output argument:
$ ps2pdfwr /path/to/input.ps - > /tmp/output.pdf
$ file /tmp/output.pdf
/tmp/output.pdf: PDF document, version 1.7, 1 page(s)
Keep diagnostic output separate from the PDF stream. The wrapper's normal conversion is quiet, but a producer or surrounding command that writes status text to standard output can corrupt a redirected PDF.
5. Choose compatibility deliberately
ps2pdfwr does not select a PDF compatibility level itself. Its purpose is to invoke Ghostscript's pdfwrite device without adding the version-specific setting used by scripts such as ps2pdf. If a downstream system requires a particular PDF level, pass the Ghostscript option explicitly and verify the result:
$ ps2pdfwr -dCompatibilityLevel=1.4 /path/to/input.ps /path/to/output-1.4.pdf
$ pdfinfo /path/to/output-1.4.pdf | grep 'PDF version'
PDF version: 1.4
Do not add a compatibility level just to make a command look complete. Older levels can restrict features or change how content is represented. Establish the receiving system's requirement first, then test representative input, especially if the document contains transparency, colour profiles, fonts or embedded images.
6. Diagnose failures without weakening safety
A missing input is usually a path or permission problem. Check it without changing anything:
$ ls -l /path/to/input.ps
$ test -r /path/to/input.ps && echo readable
$ test -w /path/to && echo destination-writable
If Ghostscript reports a PostScript error, inspect the input and the producer. Do not respond by adding arbitrary device or file-access options. The wrapper prepends -dSAFER; the manpage says this is now redundant because safe processing is the default, but it is retained and does no harm. That safety setting is a boundary, not a promise that malformed or untrusted PostScript is harmless in every surrounding workflow.
Keep untrusted input in a controlled working directory, avoid running the conversion as root, and do not expose a writable output directory to a service that will later serve files without checking names and permissions. If a conversion has changed a file that should not have changed, stop, preserve the input and logs, and restore the previous output from your normal backup rather than rerunning blindly.
Done means
ps2pdfwris the expected Ghostscript 10.02.1 wrapper on your path.- The input is a readable PostScript or EPS file, or a deliberate standard-input pipeline.
- The output is a non-empty PDF whose page count and content are plausible.
- An existing PDF was not overwritten accidentally.
- Any compatibility level was chosen because a receiving system requires it and was verified with
pdfinfo. - The conversion ran without unnecessary elevated privileges and without weakening Ghostscript's safety options.