ps2pdf: PostScript-to-PDF converter

# `ps2pdf`: PostScript-to-PDF converter

## Table of contents

> - Overview
> - Usage
> - Setting page orientation
> - Options
> - Color Conversion and Management
> - Creating a PDF/X-3 document
> - Creating a PDF/A document
> - Limitations
> - Ghostscript PDF Printer Description
> - Known problems
> - Comparison of `ps2pdf` and Acrobat Distiller
> - Acknowledgments

For other information, see the Ghostscript overview.

## Overview

`ps2pdf` is a work-alike for nearly all the functionality (but not the user interface) of Adobe's AcrobatTM DistillerTM product: it converts PostScript files to Portable Document Format (PDF) files.

`ps2pdf` is implemented as a very small command script (batch file) that invokes Ghostscript, selecting a special "output device" called `pdfwrite`.

## Usage

The usage for `ps2pdf` is

> `ps2pdf` [options] input.[e]ps output.pdf

or, on Unix systems and some versions of Windows NT and OS/2

> `ps2pdf` input.[e]ps

which is equivalent to

> `ps2pdf` input.[e]ps input.pdf

There are actually several different `ps2pdf`* scripts: the name `ps2pdf` above refers to any of them.

- `ps2pdf12` produces PDF 1.2 output (Acrobat 3-and-later compatible).
- `ps2pdf13` produces PDF 1.3 output (Acrobat 4-and-later compatible).
- `ps2pdf14` produces PDF 1.4 output (Acrobat 5-and-later compatible).
- `ps2pdf` per se currently produces PDF 1.4 output. However, this may change in the future. If you care about compatibility with a specific output level,use the `-dCompatibilityLevel=`1.x switch in the command line, or one of the specific version aliases `ps2pdf12`, `ps2pdf13`, or `ps2pdf14`.

Note that if you specify a value for `PDFSETTINGS`, this chooses PDF 1.3 or 1.4 output depending on the value of `PDFSETTINGS`: this overrides the output format specified by the script name. You can still specify the output format by using `-dCompatibilityLevel=` after `-dPDFSETTINGS=`.

All of these scripts actually call a script named `ps2pdfwr` or `ps2pdfxx`. The Unix `ps2pdfwr` script assumes that the Ghostscript executable is named `gs`; it is unlikely that you will need to change this. The DOS and MS Windows `ps2pdfxx.bat` script uses the value of the `GSC` environment variable, if defined, as the name of the executable; otherwise the script assumes the executable is named `gswin32c`. So in these environments, if the executable has a different name, you must set `GSC` to the name of the executable.

Ordinarily a single PDF file will be written that includes all input files (concatenated), but if the OutputFile is changed then the current pages will be written and a new PDF file will be started.

Note that the OutputFile will always be written, and if there is no (further) input the file will be a single blank page.

Also, if the OutputFile (or -o outputfile specification) contains a format specifier then there will be one extra (blank page) file created as a result.

## Setting page orientation

By default Ghostscript determines viewing page orientation based on the dominant text orientation on the page. Sometimes, when the page has text in several orientations or has no text at all, wrong orientation can be selected.

Acrobat Distiller parameter `AutoRotatePages` controls the automatic orientation selection algorithm. On Ghostscript, besides input stream, Distiller parameters can be given as command line arguments. For instance: `-dAutoRotatePages=/None` or `/All` or `/PageByPage`.

When there is no text on the page or automatic page rotation is set to `/None` an orientation value from setpagedevice is used. Valid values are: `0` (portrait), `3` (landscape), `2` (upside down), and `1` (seascape). The orientation can be set from the command line as `-c "<</Orientation 3>> setpagedevice"` using Ghostscript directly but cannot be set in `ps2pdf`. See Limitations below.

Ghostscript passes the orientation values from DSC comments to `pdfwrite` driver, and these are compared with the auto-rotate heuristic. If they are different then the auto-rotate value will be used. To use the DSC comment instead select AutoRotatePages=/None

## Options

The options in the command line may include any switches that may be used with Ghostscript's PostScript and PDF interpreter (see here for a complete list), although almost none of them are useful with `ps2pdf`. The following may be useful:

`-r`resolution
  Sets the resolution for pattern fills and for fonts that must be converted to bitmaps. The default internal resolution for pdfwrite is 720dpi.
`-dProcessColorModel=`device_color_space
  Sets the color space to be used for device-dependent colors in the output. device_color_space may be `/DeviceGray`, `/DeviceRGB`, or `/DeviceCMYK`; the default value is `/DeviceRGB`. Note that this does not affect images: see Limitations below.
`-dUNROLLFORMS`
  When converting from PostScript, pdfwrite (and ps2write) preserve the use of Form resources as Form XObjects in the output. Some badly written PostScript can cause this to produce incorrect output (the Quality Logic CET tests for example). By setting this flag, forms will be unrolled and stored in the output each time they are used, which avoids the problems. Note that the output file will of course be larger this way. We do not attempt to preserve Form XObjects from PDF files, unless they are associaed with transparency groups.
`-dNoOutputFonts`
  Ordinarily the pdfwrite device goes to considerable lengths to preserve fonts from the input as fonts in the output. However in some highly specific cases it can be useful to have the text emitted as linework/bitmpas instead. Setting this switch will prevent pdfwrite (and ps2write) from emitting any fonts, all text will be stored as vectors (or bitmaps in the case of bitmapped fonts) in the page content stream. Note that this will produce larger output which will process more slowly, render differently and particularly at lower resolution produce less consistent text rendering. Use with caution.

More importantly, options may include `-d`parameter=value or `-s`parameter=string switches for setting "distiller parameters", Adobe's documented parameters for controlling the conversion process. The PostScript `setdistillerparams` and `currentdistillerparams` operators are also recognized when running `ps2pdf`, and provide an equivalent way to set these parameters from within the PostScript input file.

`ps2pdf` also recognizes the following options:

`-dCompressFonts=`boolean
  Defines whether `ps2pdf` will compress embedded fonts in the output. The default value is `true`; the `false` setting is intended only for debugging.
`-dMaxInlineImageSize=`integer
  Specifies the maximum size of an inline image, in bytes. For images larger than this size, `ps2pdf` will create an XObject instead of embedding the image into the context stream. The default value is `4000`. Note that redundant inline images must be embedded each time they occur in the document, while multiple references can be made to a single XObject image. Therefore it may be advantageous to set a small or zero value if the source document is expected to contain multiple identical images, reducing the size of the generated PDF.
`-dPDFSETTINGS=`configuration
  Presets the "distiller parameters" to one of four predefined settings:
  - `/screen` selects low-resolution output similar to the Acrobat Distiller "Screen Optimized" setting.
  - `/ebook` selects medium-resolution output similar to the Acrobat Distiller "eBook" setting.
  - `/printer` selects output similar to the Acrobat Distiller "Print Optimized" setting.
  - `/prepress` selects output similar to Acrobat Distiller "Prepress Optimized" setting.
  - `/default` selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file.
`-dDoNumCopies`
  When present, causes pdfwrite to use the #copies or /NumCopies entry in the page device dictionary to duplicate each page in the output PDF file as many times as the 'copies' value. This is intended for use by workflow applications like CUPS and should not be used for generating general purpose PDF files. In particular any pdfmark operations which rely on page numbers, such as Link or Outline annotations will not work correctly with this flag.
`-dPreserveSeparation`
  This takes a Boolean argument, when set to true (the default) any /Separation color spaces in the input PostScript or PDF file will be preserved as /Separation color spaces in the output. When false, the alternate space specified by the original color space will be used instead.
`-dPreserveDeviceN`
  Behaves as per PreserveSeparation above except that it deals with DeviceN color spaces.
`-dDetectDuplicateImages`
  Takes a Boolean argument, when set to true (the default) pdfwrite will compare all new images with all the images encountered to date (NOT small images which are stored in-line) to see if the new image is a duplicate of an earlier one. If it is a duplicate then instead of writing a new image into the PDF file, the PDF will reuse the reference to the earlier image. This can considerably reduce the size of the output PDF file, but increases the time taken to process the file. This time grows exponentially as more images are added, and on large input files with numerous images can be prohibitively slow. Setting this to false will improve performance at the cost of final file size.
`-dFastWebView`
  Takes a Boolean argument, default is false. When set to true pdfwrite will reorder the output PDF file to conform to the Adobe 'linearised' PDF specification. The Acrobat user interface refers to this as 'Optimised for Fast Web Viewing'. Note that this will cause the conversion to PDF to be slightly slower and will usually result in a slightly larger PDF file.

The following option specifies a conversion into PDF/X-3:

`-dPDFX=`boolean
  Specifies the generated document is to follow the PDF/X-3 standard. When true, a `DefaultRGB` `ColorSpace` resource must be defined, and options `NOSUBSTDEVICECOLORS`, `NOCIE` must not be specified. Default value is `false`.

When generating a PDF/X-3 document, Ghostscript performs the following special actions to satisfy the PDF/X-3 standard :

- All fonts are embedded.
- `DeviceRGB` color space is substituted with `the DefaultRGB` color space, which must be defined in the `ColorSpace` category. The easiest way is to provide it in the `DefaultRGB` file in the resource directory.
- `DeviceRGB` color values are passed unchanged. If a user needs an non trivial color adjustment, a non trivial `DefaultRGB` color space must be defined.
- Transfer functions and halftone phases are skipped.
- `/PS pdfmark` interprets the `DataSource` stream or file.
- `TrimBox` and `BleedBox` entries are generated in page descriptions. Their values can be changed using the `PDFXTrimBoxToMediaBoxOffset`, `PDFXSetBleedBoxToMediaBox`, and `PDFXBleedBoxToTrimBoxOffset` distiller parameters (see below).

The following options control a conversion into PDF 1.2:

`-dPatternImagemask=boolean`
  With `CompatibilityLevel < 1.3` it specifies whether the target viewer handles `ImageMask` with a pattern color. Some old viewers, such as Ghostscript 3.30 fail with such constructs. Seting this option to false, one can get more compatibility, but the mask interpolation is lost. With `CompatibilityLevel ≥ 1.3` this option is ignored. Default value is `false`.
`-dMaxClipPathSize=integer`
  Specifies the maximum number of elements in the clipping path that the target viewer can handle. This option is used only with `CompatibilityLevel < 1.3` and `PatternImagemask=false`, and only when converting a mask into a clipping path. If the clipping path exceeds the specified size, the masked image and the clipping path is decomposed into smaller images. The value of the option counts straight path segments (curved segments are not used for representing a mask). Default value is `12000`.
`-dMaxShadingBitmapSize=integer`
  Specifies the maximum number of bytes allowed for representing a shading as a bitmap. If a shading exceeds this value, the resolution of the output bitmap is reduced to fit into the specified number of bytes. Note that the number of bytes depends on the number of color components in `ProcessColorModel` or `ColorConverionStrategy`, assumes 8 bits per sample, and doesn't consider image compression or downsampling. The image is rendered at the current resolution as specified by `-r` or the default of 720 dpi. Default value is `256000`. In general larger values will result in higher quality, but the output file size may increase dramatically, particularly with shadings which cover large areas. Shadings hsould generally only be rendered to images if `CompatibilityLevel` is 1.2 or less or if `ColorCoversionStrategy` specifies a color space differnt to that of the shading.
`-dHaveTrueTypes=boolean`
  With `CompatibilityLevel < 1.3` it specifies whether the target viewer can handle TrueType fonts. If not, TrueType fonts are converted into raster fonts with resolution specified in `HWResolution`. Note that large text at higher resolutions results in very large bitmaps which are likely to defeat caching in many printers. As a result the text is emitted as simple images rather than as a (type 3) bitmap font. The PostScript user parameter MaxFontItem can be used to increase the maximum size of a cache entry which will increase the size/resolution of the text which can be stored in a font. With `CompatibilityLevel ≥ 1.3` this option is ignored. Default value is `true`.

The following option controls a conversion into PDF 1.3:

`-dHaveTransparency=boolean`
  With `CompatibilityLevel ≥ 1.4` it specifies whether the target viewer can handle PDF 1.4 transparency objects. If not, transparency objects are converted into plain images. Default value is `true`.

The following switches are used for creating encrypted documents :

`-sOwnerPassword=`string
  Defines that the document be encrypted with the specified owner password.

`-sUserPassword=`string
  Defines the user password for opening the document. If empty, the document can be opened with no password, but the owner password is required to edit it.

`-dPermissions=`number
  Defines the PDF permissions flag field. Negative values are allowed to represent unsigned integers with the highest bit set. See the PDF Reference manual for the meaning of the flag bits.

`-dEncryptionR=`number
  Defines the encryption method revision number - either 2 or 3.

`-dKeyLength=`number
  Defines the length (in bits) of the encryption key. Must be a multiple of 8 in the interval [40, 128]. If the length isn't 40, `-dEncryptionR` must be 3.

The following switches are used for generating metadata according to Adobe XMP specification :

`-sDocumentUUID=`string
  Defines a DocumentID to be included into the document Metadata. If not specified, Ghostscript generates an UUID automatically. Otherwise the specified string is copied into the document without checking its syntax or consistence.

  Note that Adobe XMP specification requires DocumentID must be same for all versions of a document. Since Ghostscript does not provide a maintenance of document versions, users are responsible to provide a correct UUID through this parameter.

  Note that Ghostscript has no assess to the host node ID due to a minimization of platform dependent modules. Therefore it uses an MD5 hash of the document contents for generating UUIDs.

`-sInstanceUUID=`string
  Defines a instance ID to be included into the document Metadata. If not specified, Ghostscript generates an UUID automatically. Otherwise the specified string is copied into the document without checking its syntax or consistence.

  Note that Adobe XMP specification requires instance ID must be inique for all versions of document. This parameter may be used to disable an unique ID generation for a debug purpose.

  When none of `DocumentUUID` and `InstanceUUID` are specified, the generated DocumentID appears same as instance ID.

`-sDocumentTimeSeq=`integer
  Defines an integer to be used as a deconflictor for generating UUIDs, when several invokations of Ghostscript create several PDF documents within same clock quantum (tick). Mainly reserved for very fast computers and/or multhithreading applications, which may appear in future. If both `DocumentUUID` and `InstanceUUID` are specified, `DocumentTimeSeq` is ignored.

`-sDSCEncoding=`string
  Defines a name of Postscript encoding in which DSC comments are encoded in the source document. If specified, the comments are converted from that encoding into Unicode UTF-8 when writing `Metadata`. If not specified, the comments are copied to `Metadata` with no conversion. Note that Adobe Distiller for Windows uses the default locale's code page for this translation, so it's result may differ from Ghostscript. Adobe Acrobat appears to use `PDFDocEncoding` when displaying document's properties, so we recommend this value.

`ps2pdf` recognizes all of the Acrobat Distiller 5 parameters defined in the DistillerParameters document included in the Acrobat SDK. Cells in the table containing '=' mean that the value of the parameter is the same as in the "default" column.

> Parameter name |  | Notes |  | default |  | screen |  | ebook |  | printer |  | prepress
> `AlwaysEmbed` |  | (13) |  | [ ] |  | = |  | = |  | = |  | =
> `AntiAliasColorImages` |  | (0) |  | false |  | = |  | = |  | = |  | =
> `AntiAliasGrayImages` |  | (0) |  | false |  | = |  | = |  | = |  | =
> `AntiAliasMonoImages` |  | (0) |  | false |  | = |  | = |  | = |  | =
> `ASCII85EncodePages` |  |  |  | false |  | = |  | = |  | = |  | =
> `AutoFilterColorImages` |  | (1) |  | true |  | = |  | = |  | = |  | =
> `AutoFilterGrayImages` |  | (1) |  | true |  | = |  | = |  | = |  | =
> `AutoPositionEPSFiles` |  | (0) |  | true |  | = |  | = |  | = |  | =
> `AutoRotatePages` |  |  |  | /PageByPage |  | /PageByPage |  | /All |  | /None |  | /None
> `Binding` |  | (0) |  | /Left |  | = |  | = |  | = |  | =
> `CalCMYKProfile` |  | (0) |  | () |  | = |  | = |  | = |  | =
> `CalGrayProfile` |  | (0) |  | () |  | = |  | = |  | = |  | =
> `CalRGBProfile` |  | (0) |  | () |  | = |  | = |  | = |  | =
> `CannotEmbedFontPolicy` |  | (0) |  | /Warning |  | /Warning |  | /Warning |  | /Warning |  | /Error
> `ColorACSImageDict` |  | (13) |  | (note 7) |  | (note 10) |  | (note 10) |  | (note 8) |  | (note 9)
> `ColorConversionStrategy` |  | (0,6) |  | /LeaveColorUnchanged |  | /sRGB |  | /sRGB |  | /UseDeviceIndependentColor |  | /LeaveColorUnchanged
> `ColorImageDepth` |  |  |  | -1 |  | = |  | = |  | = |  | =
> `ColorImageDict` |  | (13) |  | (note 7) |  | = |  | = |  | = |  | =
> `ColorImageFilter` |  |  |  | /DCTEncode |  | = |  | = |  | = |  | =
> `ColorImageDownsampleThreshold` |  |  |  | 1.5 |  | = |  | = |  | = |  | =
> `ColorImageDownsampleType` |  | (3) |  | /Subsample |  | /Average |  | /Average |  | /Average |  | /Bicubic
> `ColorImageResolution` |  |  |  | 72 |  | 72 |  | 150 |  | 300 |  | 300
> `CompatibilityLevel` |  |  |  | 1.4 |  | 1.3 |  | 1.4 |  | 1.4 |  | 1.4
> `CompressPages` |  |  |  | true |  | = |  | = |  | = |  | =
> `ConvertCMYKImagesToRGB` |  |  |  | false |  | = |  | = |  | = |  | =
> `ConvertImagesToIndexed` |  | (0) |  | false |  | = |  | = |  | = |  | =
> `CoreDistVersion` |  |  |  | 4000 |  | = |  | = |  | = |  | =
> `CreateJobTicket` |  | (0) |  | false |  | false |  | false |  | true |  | true
> `DefaultRenderingIntent` |  |  |  | /Default |  | = |  | = |  | = |  | =
> `DetectBlends` |  | (0) |  | true |  | = |  | = |  | = |  | =
> `DoThumbnails` |  | (0) |  | false |  | false |  | false |  | false |  | true
> `DownsampleColorImages` |  |  |  | false |  | true |  | true |  | false |  | false
> `DownsampleGrayImages` |  |  |  | false |  | true |  | true |  | false |  | false
> `DownsampleMonoImages` |  |  |  | false |  | true |  | true |  | false |  | false
> `EmbedAllFonts` |  |  |  | true |  | false |  | true |  | true |  | true
> `EmitDSCWarnings` |  | (0) |  | false |  | = |  | = |  | = |  | =
> `EncodeColorImages` |  |  |  | true |  | = |  | = |  | = |  | =
> `EncodeGrayImages` |  |  |  | true |  | = |  | = |  | = |  | =
> `EncodeMonoImages` |  |  |  | true |  | = |  | = |  | = |  | =
> `EndPage` |  | (0) |  | -1 |  | = |  | = |  | = |  | =
> `GrayACSImageDict` |  | (13) |  | (note 7) |  | (note 7) |  | (note 10) |  | (note 8) |  | (note 9)
> `GrayImageDepth` |  |  |  | -1 |  | = |  | = |  | = |  | =
> `GrayImageDict` |  | (13) |  | (note 7) |  | = |  | = |  | = |  | =
> `GrayImageDownsampleThreshold` |  |  |  | 1.5 |  | = |  | = |  | = |  | =
> `GrayImageDownsampleType` |  | (3) |  | /Subsample |  | /Average |  | /Bicubic |  | /Bicubic |  | /Bicubic
> `GrayImageFilter` |  |  |  | /DCTEncode |  | = |  | = |  | = |  | =
> `GrayImageResolution` |  |  |  | 72 |  | 72 |  | 150 |  | 300 |  | 300
> `ImageMemory` |  | (0) |  | 524288 |  | = |  | = |  | = |  | =
> `LockDistillerParams` |  |  |  | false |  | = |  | = |  | = |  | =
> `LZWEncodePages` |  | (2) |  | false |  | = |  | = |  | = |  | =
> `MaxSubsetPct` |  |  |  | 100 |  | = |  | = |  | = |  | =
> `MonoImageDepth` |  |  |  | -1 |  | = |  | = |  | = |  | =
> `MonoImageDict` |  | (13) |  | <<K -1>> |  | = |  | = |  | = |  | =
> `MonoImageDownsampleThreshold` |  |  |  | 1.5 |  | = |  | = |  | = |  | =
> `MonoImageDownsampleType` |  |  |  | /Subsample |  | /Subsample |  | /Subsample |  | /Subsample |  | /Bicubic
> `MonoImageFilter` |  |  |  | /CCITTFaxEncode |  | = |  | = |  | = |  | =
> `MonoImageResolution` |  |  |  | 300 |  | 300 |  | 300 |  | 1200 |  | 1200
> `NeverEmbed` |  | (13) |  | (note 11)(note 12) |  | (note 11)(note 12) |  | (note 11)(note 12) |  | [ ](note 12) |  | [ ](note 12)
> `OffOptimizations` |  |  |  | 0 |  | = |  | = |  | = |  | =
> `OPM` |  |  |  | 1 |  | = |  | = |  | = |  | =
> `Optimize` |  | (0,5) |  | false |  | true |  | true |  | true |  | true
> `ParseDSCComments` |  |  |  | true |  | = |  | = |  | = |  | =
> `ParseDSCCommentsForDocInfo` |  |  |  | true |  | = |  | = |  | = |  | =
> `PreserveCopyPage` |  | (0) |  | true |  | = |  | = |  | = |  | =
> `PreserveEPSInfo` |  | (0) |  | true |  | = |  | = |  | = |  | =
> `PreserveHalftoneInfo` |  |  |  | false |  | = |  | = |  | = |  | =
> `PreserveOPIComments` |  | (0) |  | false |  | false |  | false |  | true |  | true
> `PreserveOverprintSettings` |  |  |  | false |  | false |  | false |  | true |  | true
> `sRGBProfile` |  | (0) |  | () |  | = |  | = |  | = |  | =
> `StartPage` |  | (0) |  | 1 |  | = |  | = |  | = |  | =
> `SubsetFonts` |  |  |  | true |  | = |  | = |  | = |  | =
> `TransferFunctionInfo` |  | (4) |  | /Preserve |  | = |  | = |  | = |  | =
> `UCRandBGInfo` |  |  |  | /Remove |  | /Remove |  | /Remove |  | /Preserve |  | /Preserve
> `UseFlateCompression` |  | (2) |  | true |  | = |  | = |  | = |  | =
> `UsePrologue` |  | (0) |  | false |  | = |  | = |  | = |  | =

(note 0) This parameter can be set and queried, but currently has no effect.

(note 1) `-dAutoFilterxxxImages=false` works since Ghostscript version 7.30. Older versions of Ghostscript don't examine the image to decide between JPEG and LZW or Flate compression: they always uses Flate compression.

(note 2) Because of Unisys's threats regarding the Welch patent, `ps2pdf` does not actually use LZW compression: instead, it treats all requests for LZW compression as calling for Flate compression. Concomitantly, `UseFlateCompression` is treated as always on, and the value of this parameter is ignored as with note 0. Now that the patent has expired, we could change this should it become worthwhile.

(note 3) The `xxxDownsampleType` parameters can also have the value /Bicubic (a Distiller 4 feature), ths will use a Mitchell filter. (older versions of pdfwrite simpy used Average instead). Note; if a non-integer downsample factor is used the code will clamp to the nearest integer (if the difference is less than 0.1) or will silently switch to the old bicubic filter, NOT the Mitchell filter.

(note 4) Currently, the transfer function is always applied. If the corresponding parameter is set to `/Preserve`, the function setting is also copied into the PDF file.

(note 6) Ghostscript specifics : The value `UseDeviceIndependentColor` requires the device parameter `UseCIEColor` to be set to `true`. The value `UseDeviceIndependentColorForImages` works same as `UseDeviceIndependentColor`. The value `CMYK` works with any `CompatibilityLevel` and requires the device parameter `ProcessColorModel` to be set to `DeviceCMYK`. The value `sRGB` requires the device parameter `ProcessColorModel` to be set to `DeviceRGB`, and actually converts to RGB with the default Ghostscript conversion. The new Ghostscript-specific value `Gray` requires the device parameter `ProcessColorModel` to be set to `DeviceGray`, and converts all colors to DeviceGray. The old Ghostscript-specific value `UseDeviceDependentColor` is now depricated. It is automaticly replaced with `sRGB`, `CMYK`, or `Gray`. With the new color conversion code active it is no longer neccesary to set `ProcessColorModel` when selecting `Gray`, `RGB` or `CMYK`. It is also no longer neccesary to set `UseCIEColor` for `UseDeviceIndependentColor` to work properly, and the use of `UseCIEColor` is now strongly discouraged. `sRGB` is not supported, use `RGB` instead.

(note 7) The default image parameter dictionary is

> `<< /QFactor 0.9 /Blend 1 /HSamples [2 1 1 2] /VSamples [2 1 1 2] >>`

(note 8) The printer ACS image parameter dictionary is

> `<< /QFactor 0.4 /Blend 1 /ColorTransform 1 /HSamples [1 1 1 1] /VSamples [1 1 1 1] >>`

(note 9) The prepress ACS image parameter dictionary is

> `<< /QFactor 0.15 /Blend 1 /ColorTransform 1 /HSamples [1 1 1 1] /VSamples [1 1 1 1] >>`

(note 10) The screen and ebook ACS image parameter dictionary is

> `<< /QFactor 0.76 /Blend 1 /ColorTransform 1 /HSamples [2 1 1 2] /VSamples [2 1 1 2] >>`

(note 11) The default, screen, and ebook settings never embed the 14 standard fonts (Courier, Helvetica, and Times families, Symbol, and ZapfDingbats). This behavior is intentional but can be overrided by:

> `<< /NeverEmbed [ ] >> setdistillerparams`

(note 12) `NeverEmbed` can include CID font names. If a CID font is substituted in `lib/cidfmap`, the substitute font name is used when the CID font is embedded, and the original CID font name is used when it is not embedded. `NeverEmbed` should always specify the original CID font name.

(note 13) The arrays `AlwaysEmbed` and `NeverEmbed` and image parameter dictionaries `ColorACSImageDict`, `ColorACSImageDict`, `ColorImageDict`, `GrayACSImageDict`, `GrayImageDict`, `MonoImageDict` cannot be specified on the ps2pdf command line. To specify these, you must use PostScript, either by including it in the PostScript source or by passing the `-c` command-line parameter to ghostscript as described in Limitations below. For example, including the PostScript string in your file `in.ps`:

> `<</AlwaysEmbed [/Helvetica /Times-Roman]>> setdistillerparams`

is equivalent to invoking:

> `gs -dBATCH -dSAFER -DNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=out.pdf -c '.setpdfwrite <</AlwaysEmbed [/Helvetica /Times-Roman]>> setdistillerparams' -f in.ps`

or using `ps2pdf` with the extra parameters in a file:

> `ps2pdf @params.in out.pdf`

where the file params.in contains:

> `-c '<</AlwaysEmbed [/Helvetica /Times-Roman]>> setdistillerparams' -f in.ps`

## Color Conversion and Management

As of the 9.11 pre-release, the color management in pdfwrite has been substantially altered so that it now uses the same Color Management System as rendering (the default is LCMS2). This considerably improves the color handling in both pdfwrite and ps2write, particularly in the areas of Spearation and DeviceN color spaces, and Indexed color spaces with images. Despite lengthy careful testing it is possible that there will be bugs in this initial implementation and so the following switch is available.

`-dPDFUseOldCMS=`boolean
  Defaults to false, when true this uses the old system for color conversions.

If you do encoutner any problems with the new color conversion code, please do open a bug report. This switch is temporary and will be removed in future releases, do not rely on its availability.

The `ColorConversionStrategy` switch can now be set to `LeaveColorUnchanged`, `Gray`, `RGB`, `CMYK` or `UseDeviceIndependentColor`. Note that, particularly for ps2write, `LeaveColorUnchanged` may still need to convert colors into a different space (ICCbased colors cannot be represented in PostScript for example). In this case the color space chosen will be whatever the current ProcessColorModel is set to, so it is worth setting this as well, if it is important that the color space be controlled.

ps2write cannot currently convert into device-independent color spaces, and so `UseDeviceIndependentColor`should not be used with ps2write.

All other color spaces are converted approproately. Separation and DeviceN spaces will be preserved if possible (ps2write cannot preserve DeviceN) and if the alternate space is not appropriate a new alternate space will be created. Eg a [/Separation (MyColor) /DeviceRGB {...}] when the `ColorConversionStrategy` is set to `CMYK` would be converted to [/Separation (MyColor) /DeviceCMYK {...}] The new tint transform would be created by sampling the original tint transform, converting the RGB values into CMYK, and then creating a function to linearly interpolate between those values.

## Ghostscript PDF Printer Description

To assist with creating a PostScript file suitable for conversion to PDF, ghostscript includes ghostpdf.ppd, a PostScript Printer Description (PPD) file. This allows some distiller parameters to be set when a PostScript file is generated.

### Windows XP or 2000

To install a "Ghostscript PDF" printer on Windows XP, select the Windows Control Panel, Printers and Faxes, Add a Printer, Local Printer, Use port FILE: (Print to File), Have Disk..., select the directory containg ghostpdf.ppd and ghostpdf.inf, select "Ghostscript PDF", Replace existing driver (if asked), and answer the remaining questions appropriately. After installing, open the "Ghostscript PDF" properties, select the Device Settings tab, set "Mimimum Font Size to Download as Outline" to 0 pixels.

To set distiller parameters, select the "Ghostscript PDF" Printing Preferences, then the Advanced button. The PDF settings are under "Printer Features".

## Creating a PDF/X-3 document

To create a PDF/X-3 document from a Postscript or a PDF file, you should :

- Specify the `pdfwrite` device or use the `ps2pdf` script.
- Specify the `-dPDFX` option. It provides the document conformity and forces `-dCompatibilityLevel=1.3`.
- Specify `-sColorConversionStrategy=/Gray`, `-sColorConversionStrategy=/CMYK` or `-sColorConversionStrategy=/UseDeviceIndependentColor`(`RGB` is not allowed). If you plan to create a device-independent color PDF file then you should set the ProcessColorModel using `-sProcessColorModel=DeviceGray` or `-sProcessColorModel=DeviceCMYK`.
- Specify a PDF/X definition file before running the input document. It provides additional information to be included into the output document. A sample PDF/X definition file may be found in `gs/lib/PDFX_def.ps`.
- If a registered printing condition is applicable, specify its identifier in the PDF/X definition file. Otherwise provide an ICC profile and specify it in the PDF/X definition file as explained below.
- Provide a `DefaultRGB` resource file in the ColorSpace resource category. Either define it in the PDF/X definition file, or provide a definition of `gs/Resource/ColorSpace/DefaultRGB` . `gs/Resource/ColorSpace/DefaultRGB` is usually distributed with Ghostscript, its content may not necessarily satisfy your needs, see below.
- Specify, using `-sOutputICCProfile`, an ICC profile which represents the color space (either CMYK or Gray) of the final file. This is the same ICC profile used in the PDF/X definition file as the ICCProfile. Even if you are using a standard OutputCondition and do not need to specify an ICCProfile, you must still set OutputICCProfile with an appropriate ICC profile in order for proper color conversion.

As mentioned above, the PDF/X definition file provides special information, which the PDF/X-3 standard requires. You can find a sample file in `gs/lib/PDFX_def.ps`, and edit it according to your needs. The file follows Postscript syntax and uses the operator `pdfmark` to pass the special information. For your comfort we marked the lines likely to need editing in the sample file with the comment `% Customize`. They are explained below.

`OutputCondition` string
  Defines an `OutputCondition` value for the output intent dictionary.

`OutputConditionIdentifier` string
  Defines an `OutputConditionIdentifier` value for the output intent dictionary.

`ICCProfile` string
  May be omited if `OutputConditionIdentifier` specifies a registed identifier of characterized printing condition (see http://www.color.org/IPA_2003-11_PDFX.pdf). Defines a file name of an ICC profile file to be included into the output document. You may specify either an absolute file name, or a relative path from the working directory.

`Title` string
  Defines the document title. Only useful if the source Postscript file doesnt define a title with DSC comments. Otherwise remove entire line from definition file.

`Info` string
  Defines an `Info` value for the output intent dictionary.

Ghostscript distribution does not contain an ICC profile to be used for creating a PDF/X-3 document. Users should either create an appropriate one themselves, or use one from a public domain, or create one with the PDF/X-3 inspector freeware.

The PDF/X-3 standard requires a `TrimBox` entry to be written for all page descriptions. This is an array of four offsets that specify how the page is to be trimmed after it has been printed. It is set to the same as `MediaBox` by default unless the `PDFXTrimBoxToMediaBoxOffset` distiller parameter is present. It accepts offsets to the `MediaBox` as an array [left right top bottom], e.g., the PostScript input code `<< /PDFXTrimBoxToMediaBoxOffset [10 20 30 40] >> setdistillerparams` specifies that 10 points will be trimmed at the left, 20 points at the right, 30 points at the top, and 40 points at the bottom.

Another page entry is the `BleedBox`. It gives the area of the page to which actual output items may extend; cut marks, color bars etc. must be positioned in the area between the `BleedBox` and the `MediaBox`. The `TrimBox` is always contained within the `BleedBox`. By default, the `PDFXSetBleedBoxToMediaBox` distiller parameter is `true`, and the `BleedBox` is set to the same values as the `MediaBox`. If it is set to `false`, the `PDFXBleedBoxToTrimBoxOffset` parameter gives offset to the `TrimBox`. It accepts a four-value array in the same format as the `PDFXTrimBoxToMediaBoxOffset` parameter.

Here is a sample command line to invoke Ghostscript for generating a PDF/X-3 document :

> `gs -dPDFX -dBATCH -dNOPAUSE -sColorConverionStrategy=/CMYK -sDEVICE=pdfwrite -sOutputFile=out-x3.pdf PDFX_def.ps input.ps`

Please also see the `PDFACompatibilityPolicy` control described under "Creating a PDF/A document" below. The same control is now used to specify the desired behaviour when an input file cannot be converted 'as is' into a PDF/X file.

## Creating a PDF/A document

To create a PDF/A document, please follow the instructions for creating a PDF/X-3 document, with the following exceptions :

- Specify the `pdfwrite` device or use the `ps2pdf` script.
- Specify the `-dPDFA` option to specify PDF/A-1, or `-dPDFA=2` for PDF/A-2.
- Specify `-sColorConversionStrategy=/RGB`, `-sColorConversionStrategy=/CMYK` or `-sColorConversionStrategy=/UseDeviceIndependentColor`. If you plan to create a device-independent color PDF file then you should set the ProcessColorModel using `-sProcessColorModel=DeviceRGB` or `-sProcessColorModel=DeviceCMYK`.
- Specify, using `-sOutputICCProfile`, an ICC profile which represents the color space (either CMYK or RGB) of the final file. This is the same ICC profile used in the PDF/X definition file as the ICCProfile.
- Specify a PDF/A definition file before running the input document. It provides additional information to be included in the output document. A sample PDF/A definition file may be found in `gs/lib/PDFA_def.ps`. You will need to modify the content of this file; in particular you must alter the /ICCProfile so that it points to a valid ICC profile for your OutputIntent. The string '(...)' defining the ICCProfile must be a fully qualified device and path specification appropriate for your Operating System.

There is one additional control for PDF/A output:

`PDFACompatibilityPolicy` integer
  When an operation (eg pdfmark) is encountered which cannot be emitted in a PDF/A compliant file, this policy is consulted, there are currently three possible values:

  > 0 - (default) Include the feature or operation in the output file, the file will not be PDF/A compliant. Because the document Catalog is emitted before this is encountered, the file will still contain PDF/A metadata but will not be compliant. A warning will be emitted in this case.

  > 1 - The feature or operation is ignored, the resulting PDF file will be PDF/A compliant. A warning wil be emitted for every elided feature.

  > 2 - Processing of the file is aborted with an error, the exact error may vary depending on the nature of the PDF/A incompatibility.

Here is a sample command line to invoke Ghostscript for generating a PDF/A document :

> `gs -dPDFA=1 -dBATCH -dNOPAUSE -sColorConversionStrategy=/RGB -sDEVICE=pdfwrite -sOutputFile=out-a.pdf PDFA_def.ps input.ps`

## Limitations

`ps2pdf` will sometimes convert PostScript constructs to lower-level ones, even if a higher-level construct is available. For example, if the PostScript file uses `charpath` to set a clipping path consisting of text, `ps2pdf` will write the clipping path as a path in the PDF file, rather than as text, even though PDF is able to express clipping with text. This is only a performance issue, and will be improved incrementally over time.

Some applications, such as HIGZ, produce PostScript files that use ridiculously large coordinates. On such files, `ps2pdf` may cause a `limitcheck` error. If this occurs, try reducing the default internal resolution of 720 dpi by using the `-r` switch, e.g., `ps2pdf -r300 somefile.ps`.

`ps2pdf` ignores the PDF 1.3 (Acrobat 4.x) pdfmarks related to document content structure: `StRoleMap`, `StClassMap`, `StPNE`, `StBookmarkRoot`, `StPush`, `StPop`, `StPopAll`, `StBMC`, `StBDC`, `EMC`, `StOBJ`, `StAttr`, `StStore`, `StRetrieve`, `NamespacePush`, `NamespacePop`, and `NI`. While this causes some structural information to be omitted from the output file, the displayed and printed output are normally not affected.

`ps2pdf` currently has only very limited support for PDF 1.4. It writes out the blend mode, constant alpha, and text knockout graphics state parameters, and it handles images with soft masks, but it does not handle transparency groups, or soft masks in the graphics state. (Note that there is no standard way to specify any of these things in PostScript, so these statements only apply when the input file is already a PDF 1.4 file.)

`ps2pdf` provides a simplified interface to the Ghostscript command line. It is not possible to use `-c` option directly or pass multiple source files. For the unrestricted access to the command line parameters, use Ghostscript directly as in:

> `gs -q -dSAFER -dNOPAUSE -dBATCH -sOutputFile=file.pdf` [more options]`\
> -sDEVICE=pdfwrite -c .setpdfwrite -f` source1.ps [more files]

or create a parameter file with the `-c` option and/or the multiple input files:

> `ps2pdf @params.in out.pdf`

where the file params.in contains:

> `-c` Postscript commands `-f` source1.ps [more files]

See Language.htm for details of the `.setpdfwrite` operator.

## Known problems

Distiller parameters should only be saved by `save` and restored by `restore`, but they are also saved by `gsave` and restored by `grestore`.

Changing the value of the `CompressPages` parameter after any marks have been made on the page may cause a crash.

Ghostscript has been writing incorrect `ToUnicode CMap` without `CMapName` into the PDF since version 8.10 (rev. 3611) . This bug is fixed in version 8.54 (rev. 6201). We recommend to re-generate PDF files created by the affected Ghostscript versions. Since version 8.54 (rev. 6590) Ghostscript can read the incorrect PDF files.

## Comparison of `ps2pdf` and Acrobat Distiller

According to users, the greatest benefit of `ps2pdf` is that it is more robust than Acrobat Distiller: it will process complex and difficult PostScript files that Acrobat Distiller is not able to handle.

For certain documents, `ps2pdf` is much faster than Adobe Distiller, and may be suitable for run-time conversions. George White, a heavy user of `ps2pdf`, remarks:

> I haven't seen a head to head comparison, but Distiller seems slower when running on what should be a faster system (for instance, Distiller on a PPC Mac vs a 25 MHz 68040 NeXT running `ps2pdf`), so I think this is fair -- also, one of Mark Doyle's postings indicated that Distiller was not fast enough for use as a run-time server. In contrast, I find that I can use `ps2pdf` as a post-processor during routine document creation.

On the other hand, there are some documents for which `ps2pdf` may be much slower than Acrobat Distiller. Caveat user.

`ps2pdf` usually produces output that is comparable in size to the output of Acrobat Distiller; however, it sometimes produces much larger output, especially if the input file involves pattern fills.

Many users report that the combination of `ps2pdf` with Acrobat Reader is superior to using a generic PostScript viewer (`psview` or `ghostview`), particularly for documents with many pages where the navigational support in PDF files reduces the overhead involved in navigating conventional PostScript documents.

## Acknowledgments

Thanks to George N. White III <aa056@chebucto.ns.ca> of the Ocean Sciences Division of the Bedford Institute of Oceanography in Dartmouth, Nova Scotia for extensive testing of early versions of `ps2pdf`, and for contributing most of this writeup.

Thanks to Martin Hosken of SIL International <http://www.sil.org> for help with testing `ps2pdf` with a wide variety of international fonts.

Copyright © 2000-2006 Artifex Software, Inc. All rights reserved.

This software is provided AS-IS with no warranty, either express or implied. This software is distributed under license and may not be copied, modified or distributed except as expressly authorized under the terms of that license. Refer to licensing information at http://www.artifex.com/ or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134, San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.

Ghostscript version 9.18, 5 October 2015