PostScript FAQ/Using Ghostscript

Using Ghostscript

edit

What is Ghostscript and where can I get it?

edit

Ghostscript is a common open source software suite, which is based on an interpreter for Adobe Systems' page description language PostScript and their Portable Document Format (PDF). The suite is developed by Artifex Software and the worldwide community, it is mainly used for the rasterization and rendering of document pages to display or print them, and for the conversion between PostScript and PDF. It includes sets of free PostScript fonts and is used in many third party applications and GUIs.

Details and software downloads see Ghostscript.

How to create compressed CMYK TIFF?

edit

Ghostscript has five TIFF devices for color managementm and five TIFF compression devices, which produce only b/w images.

 gs -sDEVICE=tif32nc -sOutputFile=tiger.tiff -dEPSCrop examples/tiger.eps

What CJK fonts work on Ghostscript?

edit

Unprotected CJK fonts work on Ghostscript just fine. It is not possible to install CSL (Adobe's CID Support Library) but most PostScript programs don't need it. CSL simulates OCF structures for the jobs that assume OCF fonts on the interpreter and manipulate them directly.

Heisei and KozMin CIDFonts are unprotected proprietary fonts developed by Adobe Systems. The installer that comes with the fonts runs on Mac and installs the fonts to a network printer using PAP protocol. To install the fonts on Ghostscript you need to copy CIDFont files to Resource/CIDFont/ directory.

The CIDFont resources are hidden in resource forks of invisible files in Mac file system. get-mac-cidfont extracts all CIDFont resources from the input file (normally /dev/cdrom) to a directory. The program also works on Windows NT.

How to avoid JPEG compression in PDF?

edit

Ghostscript has overly aggressive heuristic identifying the images for JPEG compression. Using setdistillerparams operator one can manually select compression algorithm. Ghostscript accepts most distiller parameters (PDF 0.6M) as command line arguments in addition to setdistillerparams operator.

 ps2pdf -dAutoFilterColorImages#false -dColorImageFilter#/FlateEncode \
   -dAutoFilterGrayImages#false -dGrayImageFilter#/FlateEncode foo.ps foo.pdf

Ghostscript developers recognize this as a problem. The fix is expected real soon now.

Ghostscript fails with /invalidfont in findfont?

edit

Most likely Ghostscript cannot access any fonts at all. To check what directories are searched for fonts, use

 gs -h

or

 gswin32c -h

How to create a semi-transparent object?

edit

Adobe introduced semi-transparent objects in PDF 1.4. Many new RIP's (including Ghostscript) accept PDF 1.4 directly. So there is no need for the transparency features in PostScript.

  • Ghostscript supports PDF 1.4 in v. 8.00 and up
  • Adobe CPSI supports PDF 1.4 in v. 3015 and up

Standard PostScript has opaque color model. Newer objects completely obscure the objects underneath but parts of the new object can be excluded from painting by clipping path. On level 3 PostScript a sampled image can be used for clipping another sampled image. On level 2 a similar effect can be achieved by painting pattern color through the image mask.

Very limited transparency effects can be also achieved by overprinting spot colors and pure process colors.

PDF 1.4 interpreter in Ghostscript is implemented in extended PostScript language. The extensions are visible to the regular PostScript files and can be used to the same effect. The interface is partly documented in doc/language.htm. Read the source code for details.

PostScript output interferes with redirected device output.

edit

PostScript files that write to stdout will interfere with device output to stdout. That is why since v.7.04 Ghostscript can assign the PostScript %stdout output to a file, leaving the actual stdout 'clean' for use as device output such as with -sOutputFile=- or -sOutputFile=%stdout

For instance, to discard PS %stdout output, such as from the '=' operator, when Ghostscript is being used as a filter the correct command line is:

 gs -q -sstdout=/dev/null -sOutputFile=- - | ...

With a little help from bash, named pipes can be used in place of regular files, avoiding all stdout-stderr problems.

 gs -sDEVICE=pswrite -o >(wc) -c showpage

How to fix a file generated by a pswrite device

edit

Adobe PostScript interpreters and Ghostscript v. 8.55 and higher fail with /typecheck in --where-- on files with non-standard page sizes generated by old versions of Ghostscript with Subversion revisions 1225 to 2334. The affected code executes null where, which is not allowed by PostScript language.

The following IdiomSet resource can be installed on the PostScript interpreter to work around the problem. To activate the IdiomSet you need to copy it to /Resource/IdiomSet/ directory on the printer or host-based interpreter. The PostScript root directory on a host-based interpreter likely to be different from the system root. The file name doesn't matter but FixOldPSwrite is suggested. For a one-time replacement you can also prepend the file to your job file.

 %!
 % This IdionSet provides backward compatibility with the old pdfwrite.
 % pswrite device in Ghostscript 7.04 and older generated incorrect
 % PostScript code. It assumed that the null value can be looked up in
 % a dictionary. Adobe interpreters never accepted null as dictionary
 % key and Ghostscript doesn't do this since v. 8.55. (rev. 6956)
 %
 currentuserparams /IdiomRecognition get
 <</IdiomRecognition false>> setuserparams
 currentglobal true setglobal
 /FixOldPSwrite
 << /fix_old_pswrite
     [
       { PageSize aload pop
         3 index eq exch 4 index eq and
           { pop pop pop
           }
           { PageSize dup
             1 5 -1 roll put
             0 4 -1 roll put dup where
               { exch get exec
               }
               { pop /setpagedevice where
                   { pop 1 dict dup /PageSize PageSize put setpagedevice
                   }
                   { /setpage where
                       { pop PageSize aload pop
                         pageparams 3 { exch pop } repeat setpage
                       }
                     if
                   }
                 ifelse
               }
             ifelse
           }
         ifelse
       } bind
       { PageSize aload pop
         3 index eq exch 4 index eq and
           { pop pop pop
           }
           { PageSize dup
             1 5 -1 roll put
             0 4 -1 roll put dup //null eq { false } { dup where } ifelse
               { exch get exec
               }
               { pop /setpagedevice where
                   { pop 1 dict dup /PageSize PageSize put setpagedevice
                   }
                   { /setpage where
                       { pop PageSize aload pop
                         pageparams 3 { exch pop } repeat setpage
                       }
                     if
                   }
                 ifelse
               }
             ifelse
           }
         ifelse
       } bind
     ]
 >> /IdiomSet defineresource pop
 setglobal <</IdiomRecognition 3 -1 roll>> setuserparams

Ghostscript can not run my files

edit

You try to learn postscript but you can not do:

 $ gs
 GS>(test.ps)run

stack dump from gs here ....

Current allocation mode is local
Last OS error: Permission denied
...
GS>

Since version 9.50 additional safety features are active. Now you need:

  $ gs -dNOSAFER