For other information, see the Ghostscript overview.
The Ghostscript interpreter, except as noted below, is intended to execute
properly any source program written in the (LanguageLevel 3)
PostScript language as defined in the PostScript
Language Reference, Third Edition (ISBN 0-201-37922-8) published by
Addison-Wesley in mid-1999. However, the interpreter is configurable in
ways that can restrict it to various subsets of this language.
Specifically, the base interpreter accepts the Level 1 subset of the
PostScript language, as defined in the first edition of the PostScript
Language Reference Manual (ISBN 0-201-10174-2) Addison-Wesley 1985,
plus the file system, version 25.0 language, and miscellaneous additions
listed in sections A.1.6, A.1.7, and A.1.8 of the Second Edition
respectively, including allowing a string operand for the
"status" operator. The base interpreter may be configured
(see the documentation on building Ghostscript for
how to configure it) by adding any combination of the following:
colorimage). These facilities are available
only if the color, dps, or
level2 feature was selected when Ghostscript was built.
dps feature or the
level2 feature was selected when Ghostscript was built.
compfont feature or the
level2 feature was selected when Ghostscript was built.
ttfont feature was selected when Ghostscript was built.
DCTEncode and DCTDecode filters. These
facilities are available only if the filter,
dps, or level2 feature was selected when
Ghostscript was built.
DCTEncode and
DCTDecode filters. These facilities are available only if
the dct or level2 feature was selected when
Ghostscript was built.
level2 feature was selected when Ghostscript was built.
psl3 feature was selected when Ghostscript was built.
epsf feature was selected when
Ghostscript was built.
Ghostscript currently does not implement the following PostScript LanguageLevel 3 facilities:
ProcessColorModel for page devices, except for
a very few special devices.
IODevices other than %stdin,
%stdout, %stderr, %lineedit,
%statementedit, %os%, and (if configured)
%pipe% and %disk0% through %disk0%.
Ghostscript can also interpret files in the Portable Document Format (PDF)
1.7 format defined in the
PDF
Reference Version 1.7,
distributed by Adobe Systems
Incorporated, except as noted below. This facility can be
disabled by deselecting the pdf feature
when Ghostscript is built.
Ghostscript currently implements the majority of non-interactive features defined in the PDF reference.
Ghostscript also includes a number of additional operators defined below that are not in the PostScript language defined by Adobe.
The implementation limits show here correspond to those in Tables B.1 and B.2 of the Second and Third Editions, which describe the quantities fully. Where Ghostscript's limits are different from those of Adobe's implementations (as shown in the Third Edition), Adobe's limits are also shown.
Architectural limits (corresponds to Adobe table B.1)
Quantity Limit Type Adobe
integer 32-bit twos complement integer real single-precision IEEE float array 16777216 elements 65535 dictionary 16777215 elements 65535 string 16777216 characters 65535 name 16383 characters 127 filename 128* characters savelevelnone (capacity of memory) 15 gsavelevelnone (capacity of memory) 13
* The limit on the length of a file name is 128 characters if the name starts with a %...% IODevice designation, or 124 characters if it does not.
Memory limits (corresponds to Adobe table B.2)
Quantity Limit Type Adobe
userdict200 FontDirectory100 operand stack 800 500 dictionary stack 20 execution stack 250 interpreter level none (capacity of memory) 10 path none (capacity of memory) 1500 dash 11 VM none (capacity of memory) 240000 file none (determined by operating system) 6 image 65535 values (samples × components)
for 1-, 2-, 4-, or 8-bit samples3300 32767 values for 12-bit samples 3300
In 32-bit builds packed array elements occupy either 2 bytes or 12 bytes. The average element size is probably about 7 bytes. Names occupy 16 bytes plus the space for the string.
In 64-bit builds packed array elements occupy either 2 bytes or 16 bytes. The average element size is probably about 9 bytes. Names occupy 24 bytes plus the space for the string.
The garbage collector doesn't reclaim portions of arrays obtained with getinterval, rather it collects entire arrays.
Ghostscript provides a set of operators for implementing the transparency
and compositing facilities of PDF 1.4. These are defined only if the
transpar option was selected when Ghostscript was built. We
do not attempt to explain the underlying graphics model here: for details,
see Adobe
Technical Note #5407, "Transparency
in PDF". Note, however, that
Ghostscript's model generalizes that of PDF 1.4 in that Ghostscript
maintains separate alpha and mask values for opacity and shape, rather than
a single value with a Boolean that says whether it represents opacity or
shape.
<modename> .setblendmode -
rangecheck error. The initial value of
the blending mode is /Compatible.
- .currentblendmode <modename>
<0..1> .setopacityalpha -
- .currentopacityalpha <0..1>
<0..1> .setshapealpha -
- .currentshapealpha <0..1>
<bool> .settextknockout -
true.
- .currenttextknockout <bool>
The interpreter state is extended to include a (per-context) rendering stack for handling transparency groups and masks (generically, "layers"). Groups accumulate a full value for each pixel (paint plus transparency); masks accumulate only a coverage value. Layers must be properly nested, i.e., the 'end' or 'discard' operator must match the corresponding 'begin' operator.
Beginning and ending layers must nest properly with respect to
save and restore: save and
restore do not save and restore the layer stack. Currently,
layers are not required to nest with respect to gsave and
grestore, except that the device that is current in the
graphics state when ending a layer must be the same as the device that was
current when beginning the layer. THIS AREA IS SUBJECT TO CHANGE.
<paramdict> <llx> <lly> <urx> <ury>
.begintransparencygroup -
ll/ur coordinates
are the bounding box of the group in the current user coordinate system.
paramdict has the following keys:
/Isolated
false.
/Knockout
false.
- .discardtransparencygroup -
- .endtransparencygroup -
<paramdict> <llx> <lly> <urx> <ury>
.begintransparencymaskgroup -
ll/ur coordinates
are the bounding box of the mask in the current user coordinate system.
paramdict has the following keys:
/Subtype
/Alpha or
/Luminosity.
/Background
/TransferFunction
.buildfunction to a Function dictionary).
- .begintransparencymaskimage -
- .discardtransparencymask -
<masknum> .endtransparencymask -
masknum = 0) or shape (masknum = 1) mask in
the graphics state.
<masknum> .inittransparencymask -
masknum = 0) or shape
(masknum = 1) mask to an infinite mask with alpha = 1
everywhere.
The transparency extension defines a new ImageType 103, similar to ImageType 3 with the following differences:
MaskDict is replaced by two optional
dictionaries, OpacityMaskDict and
ShapeMaskDict. If present, these dictionaries must have a
BitsPerComponent entry, whose value may be greater than 1.
Note that in contrast to ImageType 3, where any non-zero chunky mask value
is equivalent to 1, ImageType 103 simply takes the low-order bits of chunky
mask values.
Matte entry may be present in one or both mask
dictionaries, indicating premultiplication of the data values. If both
MaskDicts have a Matte entry and the values
of the two Matte entries are different, a
rangecheck error occurs.
InterleaveType appears in the MaskDicts,
not the DataDict, because each mask has its own
InterleaveType. InterleaveType 2
(interlaced scan lines) is not supported.
<bool> .setaccuratecurves -
initgraphics sets this flag to false, to
match other PostScript implementations.
- .currentaccuratecurves <bool>
<int> .setcurvejoin -
setlinejoin.
If the parameter value is -1, the join used for flattened curve line
segments is given by the current line join parameter in the graphics state
(except that if the line join value is "none", a bevel join is used), which
matches the Adobe Red Book, but not some old Adobe implementations; if the curve
join parameter value is a line join value, that type of join is used for
flattened curve line segments, regardless of the value of the graphics state
line join parameter. The initial (and default) value of the curve join
parameter is -1, causing the compatibility to Red Book and to modern Adobe
implementations. initgraphics sets the parameter to its
default value.
- .currentcurvejoin <int>
<bool> .setdashadapt -
initgraphics sets this flag to false.
- .currentdashadapt <bool>
<matrix> .setdefaultmatrix -
defaultmatrix and installed by initmatrix.
Ordinary programs should not use this operator.
<num> <bool> .setdotlength -
bool is false, or in default user coordinates of
points (units of 1/72in; see the notes
on measurements in the documentation on devices) if
bool is true. Dots occurring as part of dash patterns will
be oriented correctly; isolated dots will be oriented as though they were
part of a vertical line. initgraphics sets the dot length
to zero.
- .currentdotlength <num> <bool>
<dx> <dy> .setfilladjust2 -
dx and dy are numbers between 0 and 0.5,
measured in device space. The only two values that are likely to be useful
are 0, which gives a pure center-of-pixel rule, and 0.5, which gives
Adobe's any-part-of-pixel rule. (0.5 is treated slightly specially in
order to create half-open pixels per Adobe's specification.)
- .currentfilladjust2 <dx> <dy>
<bool> .setlimitclamp -
limitcheck error (false). initgraphics sets
this flag to false, to match other PostScript implementations.
- .currentlimitclamp <bool>
<int> .setoverprintmode -
DeviceCMYK, color components whose
value is 0 do not write into the target, rather than writing a 0 value.
THIS BEHAVIOR IS NOT IMPLEMENTED YET. The initial value of the overprint
mode is 0.
- .currentoverprintmode <int>
- .dashpath -
flattenpath and then chops up the path as
determined by the dash pattern.
<x> <y> <width> <height> .rectappend -
<numarray> .rectappend -
<numstring> .rectappend -
rectfill, rectclip, etc. Defined
only if the dps or level2 option was
selected when Ghostscript was built.
- .getpath <array>
upath, except
ucache or setbbox entries are generated.
moveto.
The saved path can be restored by newpath { exec } forall.
- .sethpglpathmode
a b moveto c d moveto e f lineto closepath will draw
back to (a,b), not (c,d). HPGL paths treat these non-subpath starting
movetos as lineto segments when filling, and as
unstroked gaps when stroking.
.currenthpglpathmode -
Ghostscript supports an experimental extension of the PostScript imaging
model to include RasterOp and some related facilities.
This extension is available only if the rasterop option was
selected when building Ghostscript.
With the RasterOp extension, imaging operations compute a
function D = f(D,S,T) in RGB space, where f is an
arbitrary 3-input Boolean function, D is the destination (frame
buffer or print buffer), S is the source (described below), and
T is the texture (the current PostScript color, which may be a
pattern). The source and texture depend on the PostScript imaging
operation:
fill and stroke, the source is
solid black, covering the region to be painted; the texture is the current
PostScript color.
show and imagemask, the source is
solid black, covering the pixels to be painted; the texture is the current
PostScript color.
image and colorimage, the source is
the image data; the texture depends on an optional Boolean parameter,
CombineWithColor, in the image dictionary. If
CombineWithColor is false (the default), the texture is
solid black. If CombineWithColor is true, the texture is
the current color. For the non-dictionary form of the image operator,
CombineWithColor is considered to be false.
The rasterop option adds the following operators:
<int8> .setrasterop -
RasterOp function in the graphics state. The
default function is 252, Source | Texture.
- .currentrasterop <int8>
RasterOp function.
<bool> .setsourcetransparent -
RasterOp function
returns. The default source transparency is false.
- .currentsourcetransparent <bool> -
<bool> .settexturetransparent -
RasterOp function
returns. The default texture transparency is false.
- .currenttexturetransparent <bool> -
For more information on RasterOp and transparency, please consult chapter 5 of the "PCL 5 Color Technical Reference Manual", Hewlett-Packard Manual Part No. 5961-0635.
<string> <bool> .charboxpath -
.charboxpath appends the following to
the current path:
<bool> is true, the equivalent of:
p1x p1ymoveto
p2x p2ylineto
p3x p3ylineto
p4x p4ylineto
closepath
This creates a path whose pathbbox is the
bbox of the string.
<bool> is false, the equivalent of:
p1x p1ymoveto
p3x p3ylineto
If the CTM is well-behaved (consists only of reflection, scaling, and
rotation by multiples of 90 degrees), this too creates a (simpler) path
whose pathbbox is the bbox of the string.
<font> <charname|charcode> <charname> <charstring> .type1execchar -
setcharwidth and setcachedevice, is valid
only in the context of a show operator -- that is, it must only be called
from within a BuildChar or BuildGlyph
procedure.
<font> <charcode> %Type1BuildChar -
show, stringwidth, or
charpath), it looks up the name BuildChar
in the font dictionary to find a procedure to run. If it does not find
this name, and if the FontType is 1, the interpreter
instead uses the value (looked up on the dictionary stack in the usual way)
of the name %Type1BuildChar.
The standard definition of %Type1BuildChar is in the
initialization file gs_type1.ps. Users should not need to
redefine %Type1BuildChar, except perhaps for tracing or
debugging.
<font> <charname> %Type1BuildGlyph -
BuildGlyph.
<number> arccos <number>
<number> arcsin <number>
mark <key1> <value1> <key2> <value2> ... .dicttomark <dict>
>> operator,
but is available even in Level 1 configurations.
<dict> <key> <value> .forceput -
put, but works even if
dict is not writable, and (if dict is
systemdict or the current save level is 0) even if
dict is in global VM and key and/or
value is in local VM. This operator should be used
only initialization code, and only in executeonly procedures: it must not be
accessible after initialization.
<dict> <key> .forceundef -
undef, but works even if
dict is not writable. This operator should be used
only initialization code, and only in executeonly procedures: it must not be
accessible after initialization.
<dict> <key> .knownget <value> true
<dict> <key> .knownget false
known and get in the
obvious way.
<dict> <integer> .setmaxlength -
maxlength) of a dictionary.
Causes a dictfull error if the dictionary has more
occupied entries than the requested capacity.
<integer> .bytestring <bytestring>
<name> .namestring <string>
<string> <charstring> .stringbreak <index|null>
string that appears
somewhere in charstring. If such a character is found,
returns the index of the first such character; if no such character is
found, returns null.
<obj> <pattern> .stringmatch <bool>
obj against a pattern in which '*' matches 0 or
more characters and '?' matches any single character. If
obj is a string or a name, matches its characters against
the pattern; if obj is of any other type, the result is
true if the pattern is the single character "*" and
false otherwise.
<state> <fromString> <toString> .type1encrypt <newState> <toSubstring>
fromString according to the algorithm for
Adobe Type 1 fonts, writing the result into toString.
toString must be at least as long as
fromString, or a rangecheck error occurs.
state is the initial state of the encryption algorithm (a
16-bit non-negative integer); newState is the new state of
the algorithm.
<state> <fromString> <toString> .type1decrypt <newState> <toSubstring>
fromString according to the algorithm for
Adobe Type 1 fonts, writing the result into toString.
Other specifications are as for type1encrypt.
<number|string> <number|string> max <number|string>
<number|string> <number|string> min <number|string>
<file> .filename <string> true
<file> .filename false
file or
.tempfile operator, returns the file name and
true; if the file is a filter, returns
false.
<file> .fileposition <integer> true
file. Unlike the standard
fileposition operator, which causes an error if the file is
not positionable, .fileposition works on all files,
including filters: for non-positionable files, it returns the total number
of bytes read or written since the file was opened.
<string> findlibfile <foundstring> <file> true
<string> findlibfile <string> false
findlibfile simply
pushes false on the stack and returns, rather than causing an error.
<file> <string> .peekstring <substring> <filled_bool>
readstring, but also leaves
the bytes in the file buffer so they will be read again by a subsequent read
operation. Currently gives a rangecheck error if
string is larger than the file's buffer.
<prefix_string|null> <access_string> .tempfile
<string> <file>
file operator, also returning the file name. There
are three cases for the <prefix_string|null> operand:
null: create the file in the same directory and with the
same name conventions as other temporary files created by the Ghostscript
implementation on this platform. E.g., the temporary file might be named
/tmp/gs_a1234.
<prefix_string> as the first part of the file name.
E.g., if <prefix_string> is xx, the
temporary file might be named /tmp/xxa1234.
<prefix_string> as the first part of the file name.
E.g., if <prefix_string> is
/my/tmpdir/zz, the temporary file might be named
/my/tmpdir/zza1234.
When running in SAFER mode, the absolute path must
be one of the strings on the list given by the PermitFileWriting
userparameter. Temporary files created with .tempfile can
be deleted when in SAFER mode, and can be renamed to one of the paths
that is on both the PermitFileControl and PermitFileWriting
paths.
<file> <integer> .unread -
ioerror
error. May also cause an ioerror if the last operation on
the file was not a reading operation. This operator is now deprecated:
use .peekstring in new code.
Ghostscript also supports the following IODevice in
addition to a subset of those defined in the Adobe documentation:
%pipe%command, which opens a pipe on the given command.
This is supported only on operating systems that provide
popen (primarily Unix systems, and not all of those).
%disk#%, which emulates the %disk0
through %disk9 devices on some Adobe PostScript printers. This pseudo
device provides a flat filenaming system with a user definable location
for the files (/Root). These devices will only be present if the
diskn.dev feature is specified during the build.
This feature is intended to allow compatibility with font downloaders that expect to store fonts on the %disk device of the printer.
Use of the %disk#% devices requires that the location of files be given by the user setting the /Root device parameter. The syntax for setting the /Root parameter is:
mark /Root (directory_specification) (%disk#) .putdevparams
For example, to store the files of the %disk0 device on the directory
/tmp/disk0, use:
mark /Root (/tmp/disk0/) (%disk0) .putdevparams
The files will be stored in the specified directory with arbitrary names.
A mapping file is used to store the association between the file
names given for the file operations on the %diskn# device and the file
that resides in the /Root directory.
<save> .forgetsave -
<array> bind <array>
bind is redefined as:
Flag Definition
NOBIND /bind {} def ; no operation, returns the argument DELAYBIND returns the argument, stores the argument for later use by .bindnow
<array> .bind <array>
bind operation as defined in PLRM regardless of
NOBIND or DELAYBIND flags.
- .bindnow -
bind operator to all savad procedures after binding has been
deferred through -dDELAYBIND. Note that idiom recognition has no effect for the deferred
binding because the value returned from bind is discarded.
Since v. 8.12 .bindnow undefines itself and restores standard definition of
bind operator. In earlier versions after calling .bindnow,
the postscript bind operator needs to be rebound to the internal implementation
.bind, as in this fragment from the ps2ascii script:
DELAYBIND {
.bindnow
/bind /.bind load def
} if
This is necessary for correct behavior with later code that uses the bind operator.
<obj1> <obj2> ... <objn> <n> .execn ...
obj1 through objn in that
order, essentially equivalent to
<obj1> <obj2> ... <objn> <n> array astore {exec} forall
except that it doesn't actually create the array.
<string> getenv <string> true
<string> getenv false
.defaultpapersize <string> true
.defaultpapersize false
a4 for countries using the metric system, and
letter for countries using the imperial system.
<name> <array> .makeoperator <operator>
Operators defined in this way do one other thing besides running the procedure: if an error occurs during the execution of the procedure, and there has been no net reduction in operand or dictionary stack depth, the operand or dictionary stack pointer respectively is reset to its position at the beginning of the procedure.
<string> <boolean> .setdebug -
<string> based on the value of
<boolean>. These correspond to the debug
flags set by -Z on the command line and enable
debug and tracing output from various internal modules.
Note that most tracing output is only produced if the Ghostscript
interpreter was built with the DEBUG preprocessor
symbol defined.
The zsetdebug() C function, which implements this
operator, is a useful breakpoint for debuggers.
Inserting '() true .setdebug' in the interpreted code will
trigger a breakpoint at that location without side effects. The
current flag state is available in C as the gs_debug[]
array, indexed by character value. The zsetdebug function will
be entered, and gs_debug[] updated, whether or not Ghostscript
is built with the DEBUG preprocessor symbol defined, so this
is useful even with release builds.
- .oserrno <errno>
- .oserrorstring <string>
<array> <procedure> .runandhide ... <array>
This operator is intended to allow hiding a <save> object
during execution of procedures or files that run in SAFER mode.
If a save is performed prior to entering SAFER mode
with .setsafe, using the save object as the operand to
restore will return to NOSAFER mode. In order to
prevent the procedures running in SAFER mode from being able to
return to NOSAFER mode, this operator should be used.
Upon return from the file or procedure restore can be used
to return to NOSAFER mode.
Note: The array operand hidden during the execution of the file or
procedure will be placed at the top of the operand stack which may be on
top of objects that the file or procedure leaves on top of the stack.
Thus removing objects below the array may be needed to prevent an
invalidrestore error.
For example, in order for a script or job server to execute a file somefile.ps with the SAFER mode restrictions in place, returning to unrestricted NOSAFER mode when the procedure exits is as follows:
Start Ghostscript with -dNOSAFER
... % perform any device set up w/o restrictions
[ save ] % create a save object before SAFER
(somefile.ps) (r) file cvx % open the file to process
.setsafe % enter SAFER mode
.runandhide % run the file hiding the save object
count 1 roll % place array below anything left over
count 1 sub { pop } repeat % pop left over stuff
cleardictstack % prevent invalidrestore from dicts
0 get restore % go back to NOSAFER mode
Another refinement on the above would be to execute .runandhide
using stopped in order to report errors but continue processing.
- .setsafe -
-dNOSAFER or
-dDELAYSAFER, this operator can be used to enter SAFER
mode (see -dSAFER)
Since SAFER mode is implemented with userparameters and device parameters,
it is possible to use save and restore before
and after .setsafe to return to NOSAFER mode, but care
should be taken to ensure that the save object is not
accessible to any procedures or file run in SAFER mode (see
.runandhide above).
Note: This uses setpagedevice to change .LockSafetyParams, so the page will be erased as a side effect of this operator
- .locksafe -
.LockSafetyParams
and the LockFilePermissions userparameter true as well as
adding the paths on LIBPATH and FONTPATH and the paths given by the
system params /GenericResourceDir and /FontResourceDir to the current
PermitFileReading list of paths.
If Ghostscript is started with -dNOSAFER or
-dDELAYSAFER, this operator can be used to enter SAFER
mode with the current set of PermitFile... user parameters
in effect. Since .setsafe sets the PermitFile...
user parameters to empty arrays, a script or job server that needs to
enable certain paths for file Reading, Writing and/or Control can use this
operator to perform the locking needed to enter SAFER mode.
For example, to enable reading everywhere, but disallow writing and file control (deleting and renaming files), the following can be used:
{ << /PermitFileReading [ (*) ]
/PermitFileWriting [ ]
/PermitFileControl [ ]
>> setuserparams
.locksafe
} stopped pop
In the above example, use of stopped will allow the use of this sequence on
older versions of Ghostscript where .locksafe was not an operator.
Note: This uses setpagedevice to change .LockSafetyParams, so the page will be erased as a side effect of this operator
See also .LockSafetyParams and User Parameters.
.setpdfwritegs -q -dSAFER -dNOPAUSE -dBATCH -sOutputFile=file.pdf[more options]\source1.ps [more files]
-sDEVICE=pdfwrite -c .setpdfwrite -f
Currently, the operator just sets a minimum 3 MB vmthreshold to allow for accumulating shared object data and to reduce the incidence of garbage collection as a performance improvement. Additional settings may be added in the future.
.color_test and .color_test_all
<device> copydevice <device>
<devicename> finddevice <device>
finddevice is called more than
once with the same device name, it creates the default instance the first
time, and returns the same instance thereafter.
<devicename> findprotodevice <device>
.getdeviceparams or other parameter-reading
operators, but it is read-only and cannot be set with
setdevice: it must be copied first.
<device> <x> <y> <width> <max_height> <alpha?> <std_depth|null> <string> .getbitsrect <height> <substring>
alpha? is 0 for no alpha, -1 for alpha first, 1 for alpha
last. std_depth is null for native pixels, number of bits
per component for a standard color space.
<index> .getdevice <device>
index is out of
range, a rangecheck error occurs.
This device is actually a prototype, not a directly usable device,
and is marked read-only; it cannot have its parameters changed or be
installed as the current device.
- .getdefaultdevice <device>
copydevice to obtain a workable device.
<matrix> <width> <height> <palette> makeimagedevice <device>
matrix is the initial transformation matrix: it must be orthogonal
(that is, [a 0 0 b x y] or
[0 a b 0 x y]). palette is a
string of 2^N or
3 × 2^N elements,
specifying how the 2^N possible pixel
values will be interpreted. Each element is interpreted as a gray value,
or as RGB values, multiplied by 255. For example, if you want a monochrome
image for which 0=white and 1=black, the palette should be
<ff 00>; if you want a 3-bit deep image with
just the primary colors and their complements (ignoring the fact that 3-bit
images are not supported), the palette might be <000000 0000ff
00ff00 00ffff ff0000 ff00ff ffff00 ffffff>. At present, the
palette must contain exactly 2, 4, 16, or 256 entries, and must contain an
entry for black and an entry for white; if it contains any entries that
aren't black, white, or gray, it must contain at least the six primary
colors (red, green, blue, and their complements cyan, magenta, and yellow);
aside from this, its contents are arbitrary.
Alternatively, palette can be 16, 24, 32, or null (equivalent to 24). These are interpreted as:
Palette Bits allocated per color
16 5 red, 6 green, 5 blue 24 8 red, 8 green, 8 blue 32 8C, 8M, 8Y, 8K
Note that one can also make an image device (with the same palette as an
existing image device) by copying a device using the
copydevice operator.
<matrix> <width> <height> <palette> <word?> makewordimagedevice <device>
word? is a
Boolean value indicating whether the data should be stored in a
word-oriented format internally. No ordinary PostScript programs should
use this operator.
<device> <index> <string> copyscanlines <substring>
image operator. It is an error if the device is
not an image device or if the string is too small to hold at least one
complete scan line. Always copies an integral number of scan lines.
<device> setdevice -
Sets the current device to the specified device. Also resets the
transformation and clipping path to the initial values for the device.
Signals an invalidaccess error if the device is a
prototype or if .LockSafetyParams
is true for the current device.
Some device properties may need to be set with putdeviceprops before
setdevice is called. For example, the pdfwrite device will try
to open its output file, causing an undefinedfilename error if
OutputFile hasn't been set to a valid filename. Another
method in such cases is to use the level 2 operator instead:
<< /OutputDevice /pdfwrite /OutputFile
(MyPDF.pdf) >> setpagedevice.
- currentdevice <device>
<device> getdeviceprops <mark> <name1> <value1> ... <namen> <valuen>
<mark> <name1> <value1> ... <namen> <valuen> <device> putdeviceprops <device>
undefined,
invalidaccess, typecheck, rangecheck, or
limitcheck errors.
- flushpage -
In its usual configuration, Ghostscript supports all the standard PostScript LanguageLevel 3 filters, both encoding and decoding, except that it does not currently support:
EarlyChange key in the LZWEncode
filter.
Ghostscript also supports additional keys in the optional dictionary
operands for some filters. For the LZWDecode filter:
InitialCodeLength <integer> (default 8)
FirstBitLowOrder <boolean> (default false)
BlockData <boolean> (default false)
For the CCITTFaxEncode and CCITTFaxDecode
filters:
DecodedByteAlign <integer> (default 1)
In addition to the standard PostScript LanguageLevel 3 filters, Ghostscript supports the following non-standard filters. Many of these filters are used internally to implement standard filters or facilities; they are almost certain to remain, in their present form or a backward-compatible one, in future Ghostscript releases.
<target> /BCPEncode filter <file>
<source> /BCPDecode filter <file>
<target> <seed_integer> /eexecEncode filter <file>
seed_integer must be 55665 for the eexec
section of a font, or 4330 for a CharString. Note that for
the eexec section of a font, this filter produces binary
output and does not include the initial 4 (or lenIV) garbage
bytes.
<source> <seed_integer> /eexecDecode filter <file>
<source> <dict> /eexecDecode filter <file>
seed_integer must be
55665 or 4330 as described just above. PDF interpreters don't skip space characters
after operator eexec. Use keep_spaces = true for
decoding embedded PDF fonts. Recognized dictionary keys are:
seed <16-bit integer>(required)
lenIV <non-negative integer>(default=4)
eexec <bool>(default=false)
keep_spaces <bool>(default=false)
<target> /MD5Encode filter <file>
<source> <hex_boolean> /PFBDecode filter <file>
.PFB format, the
usual semi-binary representation for Type 1 font files on IBM PC and
compatible systems. If hex_boolean is true, binary packets
are converted to hex; if false, binary packets are not converted.
<target> <dict> /PixelDifferenceEncode filter <file>
<source> <dict> /PixelDifferenceDecode filter <file>
Colors <integer>(1 to 4, default=1)
BitsPerComponent <integer>(1, 2, 4, or 8, default=8)
Columns <integer>(>= 0, required)
See the Adobe PDF Reference Manual for details.
<target> <dict> /PNGPredictorEncode filter <file>
<source> <dict> /PNGPredictorDecode filter <file>
Keys recognized in PNG filter algorithms
Key Range Default
Colors <integer>1 to 16 16 BitsPerComponent <integer>1, 2, 4, 8, or 16 8 Columns <integer>>= 0 1 Predictor <integer>10 to 15 15
The Predictor is the PNG algorithm number + 10 for the
Encoding filter; the Decoding filter
ignores Predictor. 15 means the encoder attempts to
optimize the choice of algorithm. For more details see the PNG
specification
http://www.w3.org/TR/WD-png-960128.html
<target> /TBCPEncode filter <file>
<source> /TBCPDecode filter <file>
<target> /zlibEncode filter <file>
<source> /zlibDecode filter <file>
Flate filters are actually a combination of
this filter with an optional predictor filter.
Some versions of Ghostscript may also support other non-standard filters for experimental purposes. The current version includes the following such filters, which are not documented further. No code should assume that these filters will exist in compatible form, or at all, in future versions.
<target/source> <string> ByteTranslateEncode/Decode filter <file>
string must be a string of exactly 256 bytes. Creates a
filter that converts each input byte b to
string[b]. Note that the Encode
and Decode filters operate identically: the client must
provide a string for the Decode filter that
is the inverse mapping of the string for the
Encode filter.
<target/source> <dict> BoundedHuffmanEncode/Decode filter <file>
FirstBitLowOrder <bool>(default=false)
MaxCodeLength <int>(default=16)
EndOfData <bool>(default=true)
EncodeZeroRuns <int>(default=256)
Tables <int_array>
<target/source> <dict> BWBlockSortEncode/Decode filter <file>
bzip2
compression application. See http://sources.redhat.com/bzip2/
for more information. The only recognized dictionary key is:
BlockSize <integer> (default=16384)
<target/source> MoveToFrontEncode/Decode filter <file>
Encode filter starts by initializing an internal
256-byte array a to the values 0 .. 255. This array will
always hold a permutation of these values. Then for each input byte
b, the filter outputs the index i such that
a[i] = b, and moves that element to the
front (element 0) of a, moving elements 0 .. i-1 to
positions 1 .. i. The Decode filter inverts this
process.
getdeviceprops and putdeviceprops, as
indicated above.) Here are the currently defined parameters for all
devices:
.LockSafetyParams <boolean>
If this parameter is true for the current device, attempt to set a new
device that has .LockSafetyParams false will signal an
invalidaccess error.
BitsPerPixel <integer> (usually read-only)
.HWMargins [<four floats>]
HWSize [<integer> <integer>]
%MediaSource <integer>
%MediaDestination <integer>
.IgnoreNumCopies <boolean>
Name <string> (read-only)
OutputDevice.
Colors, GrayValues, RedValues, GreenValues, BlueValues, ColorValues (usually read-only)
deviceinfo operator of Display PostScript.
Red, Green, Blue, and
ColorValues are only defined if
Colors > 1.
TextAlphaBits, GraphicsAlphaBits (usually read-only)
Ghostscript also supports the following read-only parameter that is not a true device parameter:
.EmbedFontObjects <integer>
In addition, the following are defined per Adobe's documentation for the
setpagedevice operator:
Duplex(if supported)
HWResolution
ImagingBBox
Margins
LeadingEdge
MediaPosition
NumCopies(for printers only)
Orientation(if supported)
OutputDevice
PageOffset(write-only)
PageSize
ProcessColorModel(usually read-only)
Some devices may only allow certain values for HWResolution
and PageSize. The null device ignores attempts to set
PageSize; its size is always [0 0].
It should be noted that calling setpagedevice with one of the above keys may reset the effects of any pdfmark commands up to that point. In particular this is true of HWResolution, a behavior that differs from Adobe Distiller.
For raster printers and image format (jpeg*, tiff*, png* ...) devices these page device parameters are also defined:
MaxBitmap <integer>
This value includes the space for padding raster lines and for an array of
pointers for each raster line, thus the MaxBitmap value to allow
a given PageSize of a specific number of bits per pixel to be rendered in a
full page buffer may be somewhat larger than the bitmap size alone.
BandListStorage <file|memory>
BAND_LIST_STORAGE.
Since memory is always included, specifying -sBandListStorage=memory
when the default is file will use memory based storage for the
band list of the page. This is primarily intended for testing, but if the disk I/O is
slow, band list storage in memory may be faster.
BufferSpace <integer>
MaxBitmap (see above.)
The buffer space is used to collect display list (clist) commands for the bands and then to consolidate those commands when writing the clist to the selected BAND_LIST_STORAGE device (memory or file) set when Ghostscript is compiled.
If MaxBitmap (above) forces banding mode, and if BufferSpace
is large enough, the display list (clist) will consist of a single band.
The BufferSpace will determine the size of the 'consolidation'
buffer (above) even if the MaxBitmap value is low enough to force
banding/clist mode.
BGPrint <boolean>
false, causes the rendering and printing to be
done in the same thread as the parser. When -dBGPrint=true, the
page output will be overlapped with parsing and writing the clist for the next page.
If the device does not support background printing, rendering and printing will
be performed as if -dBGPrint=false.
Note that the background printing thread will allocate a band buffer (size determined
by the BufferSpace or BandBufferSpace values) in addition to
the band buffer in the 'main' parsing thread.
If NumRenderingThreads is > 0, then the background printing thread
will use the specified number of rendering threads as children of the background printing
thread. The background printing thread will perform any processing of the raster data
delivered by the rendering threads.
GrayDetection <boolean>
true, and when the display list (clist) banding mode is being used,
during writing of the clist, the color processing logic collects information about the
colors used before the device color profile is applied. This allows special devices
that examine pageneutralcolor with the information that all colors on
the page are near neutral, i.e. monochrome, and converting the rendered raster to
gray may be used to reduce the use of color toners/inks.
Since the determination of whether or not the page uses colors is determined before the conversion to device colors, this information is independent of the device output profile.
Among the devices distributed with the source, currently only the pnmcmyk
device supports this parameter and will produce either a P7 PAM CMYK output
or a P5 PGM Gray output depending on the use of color on the page.
Note: Since -dGrayDetection=true requires extra checking during
writing of the clist, this option should only be used for devices that
support the optimization of pages to monochrome, otherwise performance may be degraded
for no benefit.
NumRenderingThreads <integer>
NumRenderingThreads
of 1 or higher results in bands rendering in the specified number of 'background'
threads.
The number of threads should generally be set to the number of available processor cores for best throughput.
Note that each thread will allocate a band buffer (size determined by the
BufferSpace or BandBufferSpace values) in addition to
the band buffer in the 'main' thread.
OutputFile <string>
%d is replaced by the page number
for page-oriented output devices;
on Unix systems %pipe%command writes to a pipe.
(|command also writes to a pipe, but is now
deprecated). Also see the -o parameter.
Attempts to set this parameter if .LockSafetyParams is true
will signal an invalidaccess error.
OpenOutputFile <boolean>
PageCount <integer> (read-only)
The following parameters are for use only by very specialized applications
that separate band construction from band rasterization. Improper use may
cause unpredictable errors. In particular, if you only want to allocate
more memory for banding, to increase band size and improve performance, use
the BufferSpace parameter, not BandBufferSpace.
BandHeight <integer>
BandBufferSpace (or BufferSpace,
if BandBufferSpace is not specified). If BandHeight
is larger than the number of lines that will fit in the buffer, opening the device will fail.
BandWidth <integer>
BandBufferSpace <integer>
Ghostscript supports the following parameter for
setpagedevice and currentpagedevice that is
not a device parameter per se:
ViewerPreProcess <procedure>
ProcessDSCComment <procedure|null>
%% or %!).
There are two operands, the file and the comment (minus any terminating
EOL), which the procedure must consume.
ProcessComment <procedure|null>
ProcessDSCComment is also not null, a
comment other than a DSC comment). The operands are the same as for
ProcessDSCComment.
LockFilePermissions <boolean>
invalidaccess.
Also, when this value is true, the file operator
will give invalidaccess when attempting to open files
(processes) using the %pipe device.
Also when LockFilePermissions is true, strings
cannot reference the parent directory (platform specific). For example
(../../xyz) is illegal on unix, Windows
and Macintosh, and ([.#.#.XYZ]) is illegal on VMS.
This parameter is set true by the .setsafe and
.locksafe operators.
PermitFileReading <array of strings>
PermitFileWriting <array of strings>
PermitFileControl <array of strings>
deletefile and renamefile.
For renamefile, the filename for the current filename
must match one of the paths on the PermitFileControl list, and the
new filename must be on both the PermitFileControl and the
PermitFileWriting lists of paths.
The strings can contain wildcard characters as for the filenameforall
operator and unless specifying a single file, will end with a *
for directories (folders) to allow access to all files and sub-directories
in that directory.
Note: The strings are used for stringmatch operations similar
to filenameforall, thus on MS Windows platforms, use the '/'
character to separate directories and filenames or use '\\\\' to
have the string contain '\\' which will match a single '\' in the
target filename (use of '/' is strongly recommended).
The SAFER mode and the
.setsafe operator set all three lists to empty arrays,
thus the only files that can be read are the %stdin device and
on LIBPATH or FONTPATH or the Resource paths specified by the /FontResourceDir
or /GenericResourceDir system params. Files cannot be opened for writing
anywhere and cannot be deleted or renamed except for files created with the
.tempfile operator).
Note: Limiting file reading as above is NOT compatible with
SAFER mode in release versions before 7.11 and corresponds to the use of
-dPARANOIDSAFER in version 7.04 (up to and not including
version 7.10) and GPL versions 6.53 (up to and not including 6.60).
AlignToPixels <integer>
TextAlphaBits. If the
latter is 1, the same rendering results regardless of the value of
AlignToPixels. The initial value defaults to 1, but this
may be overridden by the command line argument
-dAlignToPixels.
GridFitTT <integer>
The reduced interpreter can't properly grid fit fonts with patented instructions. Therefore Ghostscript implements another grid fitting method for True Type fonts, based on a spot topology analysis.
This parameter controls the action of the reduced interpreter and the grid fitter:
This parameter defaults to 2, but this
may be overridden on the command line with
-dGridFitTT=n.
The reduced bytecode interpreter is based in part of the work of the FreeType Team. The topological grid fitting is a new original Ghostscript method.
The operator run can take either a string or a file as its argument. In
the latter case, it just runs the file, closing it at the end, and trapping
errors just as for the string case.
Decoding is a Ghostscript-specific resource category. It contains
various resources for emulating PostScript fonts with other font technologies.
Instances of the Decoding category are tables which map PostScript glyph
names to character codes used with TrueType, Intellifont, Microtype and other font formats.
Currently Ghostscript is capable of PostScript font emulation in 2 ways :
Decoding resources are not currently used by the native font renderer.
An instance of the Decoding resource category is
a dictionary. The dictionary keys are PostScript glyph names and the
values are either character codes, or arrays of character codes.
Arrays are used when a single name may be mapped to various character codes -
in this case Ghostscript tries all alternatives until a success.
The name of the resource instance should
reflect the character set for which it maps. For example,
/Unicode /Decoding resource maps to
Unicode UTF-16.
The rules for using Decoding resources in particular
cases are specified in the configuration file
lib/xlatmap. See the file itself for more
information.
The file format for Decoding resource files is
generic PostScript.
Users may want to define custom Decoding resources.
The ParseDecoding procset defined in
Resource/Init/gs_ciddc.ps allows representation
of the table in a comfortable form.
CIDDecoding resources are similar to Decoding
resources, except they map Character Identifiers (CIDs) rather than glyph names.
Another difference is that the native Ghostscript font renderer uses
CIDDecoding resources while emulate CID fonts with TrueType or OpenType fonts.
An instance of the CIDDecoding resource category is
a dictionary of arrays. Keys in the dictionary are integers,
which correspond to high order byte of a CID.
Values are 256-element arrays, and their indices correspond to the low order byte of a CID.
Each elemet of an array is either null, or character code (integer), or an array
of character codes (integers). The zero code represents mapping to the default character.
The dictionary includes the additional key CIDCount.
Its value is the maximal CID defined, plus one.
The Ghostscript library is capable of generating some CIDDecoding
instances automatically, using the appropriate CMap (character map)
resources. This covers most of practical cases if the neccessary CMap
resources are provided. See the table .CMapChooser in
Resource/Init/gs_ciddc.ps
for the names of automatically gerenated resources and associated CMaps.
They allow to mapping CNS1, GB1, Japan1, Japan2 and Korea1 CID sets to TrueType
character sets known as Unicode (exactly UTF-16), Big5,
GB1213, ShiftJIS, Johab and Wansung.
The file format for CIDDecoding resource file is
generic PostScript.
Users may want to define custom resources to CIDDecoding
resource category.
GlyphNames2Unicode is an undocumented dictionary which Adobe
PostScript printer driver uses to communicate with Adobe Distiller.
In this dictionary the keys are glyph names, the values are Unicode UTF-16 codes for them.
The dictionaly is stored in the FontInfo dictionary under
the key GlyphNames2Unicode. Ghostscript recognises it and uses
to generate ToUnicode CMaps with pdfwrite.
Since 8.10 release Ghostscript maintains multiple resource directories.
Ghostscript does not distinguish lib and
Resource directories.
There is no file name conflicts because lib does not
contain subdirectories, but Resource
always store files in subdirectories.
The search method with multiple resource directories
appears not fully conforming to PLRM. We cannot unconditionally call
ResourceFileName while executing findresource
or resourcestatus, resourceforall, because
per PLRM it always returns a single path. Therefore Ghostscript
implements an extended search method in findresource,
resourcestatus and resourceforall, which
first calls ResourceFileName and checks whether the
returned path points to an existing file. If yes, the file is used,
othervise Ghostscript searches all directories specified in
LIB_PATH. With a single resource directory
it appears conforming to PLRM and equivalent to Adobe implementations.
ResourceFileName may be used for obtaining a path
where a resource file to be installed. In this case
Ghostscript to be invoked with -sGenericResourceDir=path,
specifying an absolute path. The default value for
GenericResourceDir is a relative path. Therefore
a default invocation with a PostScript installer
will install resource files into /gs/Resource.
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.09, 21 August 2013