15 Can I query the default settings Ghostscript uses for an output device (such as ‘pdfwrite’ or ‘tiffg4’)?

In this answer to ‘Ghostscript command line parameters to convert EPS to PDF’; it is stated that the default resolution for the pdfwrite device of Ghostscript is 720x720, which I initially found unbelievable!

Is there a way to list the default options of a Ghostscript device?

15.1 Answer

Since Ghostscript is a full-blown PostScript interpreter, you can also send PostScript snippets to it which do not cause the drawing of page elements, but which query it for its internal state.

If you want to know what the default settings of the Display are, when you ask it via gs some.pdf to just display a PDF on screen, you could try this:

Sample command line (Linux, Unix, Mac OS X):

1 gs                                                         \
2   -c "currentpagedevice {exch ==only ( ) print == } forall"

On Windows this becomes:

1 gswin32c.exe                                                 ^
2    -c "currentpagedevice {exch ==only ( ) print == } forall"

The result is a list of /SomeName somevalue pairs which describe the settings used for rendering pages to the current screen.

This is so because usually the display is the default device for Ghostscript to send its output to. Now you may notice that you’ll see an empty Ghostscript window pop up, which you’ll have to close…. Ah, how about adding some options to avoid the popup window?

1 gs                                                           \
2    -o /dev/null                                              \
3    -dNODISPLAY                                               \
4    -c "currentpagedevice {exch ==only ( ) print == } forall"

Or, on Windows:

1 gswin32c.exe                                                 ^
2    -o nul                                                    ^
3    -dNODISPLAY                                               ^
4    -c "currentpagedevice {exch ==only ( ) print == } forall"

But this will change the query return values, because you (unintentionally) changed the output device settings:

1 gs -c "currentpagedevice {exch ==only ( ) print == } forall" | grep Resolution

Result:

1 HWResolution [86.5426483 86.5426483]
2 /.MarginsHWResolution [1152.0 1152.0]

Compare this to

1 gs                                                          \
2   -o /dev/null                                              \
3   -dNODISPLAY                                               \
4   -c "currentpagedevice {exch ==only ( ) print == } forall" \
5 | grep Resolution

Result:

1 /HWResolution [72.0 72.0]
2 /.MarginsHWResolution [72.0 72.0]

So, please avoid this trap. I successfully fell into it a few years ago, and didn’t even notice it for quite a long time…

Now assuming you want to query for the default settings of the PDF writing device, run this one:

1 gs                                                          \
2   -o /dev/null                                              \
3   -sDEVICE=pdfwrite                                         \
4   -c "currentpagedevice {exch ==only ( ) print == } forall" \
5 | tee ghostscript-pdfwrite-default-pagedevice-settings.txt

You’ll now have all settings for the pdfwrite device in a *.txt file. And you may repeat that with some other interesting Ghostscript devices and then compare them for all their detailled differences:

 1 for _dev in                                                 \
 2   pswrite ps2write pdfwrite                                 \
 3   tiffg3 tiffg4 tiff12nc tiff24nc tiff32nc tiff48nc tiffsep \
 4   jpeg jpeggray jpegcmyk                                    \
 5   png16 png16m png256 png48 pngalpha pnggray pngmono;       \
 6 do                                                            \
 7   gs                                                          \
 8     -o /dev/null                                              \
 9     -sDEVICE=${_dev}                                          \
10     -c "currentpagedevice {exch ==only ( ) print == } forall" \
11    | sort                                                     \
12    | tee ghostscript-${_dev}-default-pagedevice-settings.txt; \
13 done

It’s rather interesting to compare the settings for, say, the pswrite and ps2write devices like this (and also discover parameters which are available for the one, but not the other device). One method that gives you a quick overview is to apply the commandline tool sdiff to the two text files:

1 sdiff -sbB ghostscript-ps{2,}write-default-pagedevice-settings.txt

On my Mac OS X system, this yields the following result (left column: ps2write, right column: pswrite output):

 1 /AllowIncrementalCFF false                    <
 2 /AllowPSRepeatFunctions true                  <
 3 /AutoFilterColorImages true                   | /AutoFilterColorImages false
 4 /AutoFilterGrayImages true                    | /AutoFilterGrayImages false
 5 /AutoPositionEPSFiles true                    <
 6 /CalCMYKProfile (None)                        | /CalCMYKProfile ()
 7 /CalGrayProfile (None)                        | /CalGrayProfile ()
 8 /CalRGBProfile (None)                         | /CalRGBProfile ()
 9 /CannotEmbedFontPolicy /Error                 | /CannotEmbedFontPolicy /Warning
10 /CenterPages false                            <
11 /ColorImageDownsampleType /Bicubic            | /ColorImageDownsampleType /Subsample
12 /ColorImageResolution 600                     | /ColorImageResolution 150
13 /CompatibilityLevel 1.2                       <
14 /CompressEntireFile false                     <
15 /CompressFonts true                           <
16 /CoreDistVersion 5000                         <
17 /CreateJobTicket false                        <
18 /DSCEncodingToUnicode []                      <
19 /DetectDuplicateImages true                   <
20 /DoNumCopies false                            <
21 /DocumentTimeSeq 0                            <
22 /DocumentUUID ()                              <
23 /DownsampleColorImages true                   | /DownsampleColorImages false
24 /DownsampleGrayImages true                    | /DownsampleGrayImages false
25 /DownsampleMonoImages true                    | /DownsampleMonoImages false
26 /EmitDSCWarnings false                        <
27 /EncryptionR 0                                <
28 /FirstObjectNumber 1                          <
29 /FitPages false                               <
30 /GrayImageDownsampleType /Bicubic             | /GrayImageDownsampleType /Subsample
31 /GrayImageResolution 600                      | /GrayImageResolution 150
32 /HaveCIDSystem false                          <
33 /HaveTransparency true                        <
34 /HaveTrueTypes true                           <
35 /HighLevelDevice true                         <
36 /ImageMemory 524288                           | /ImageMemory 500000
37 /InstanceUUID ()                              <
38 /IsDistiller true                             <
39 /KeyLength 0                                  <
40                                               > /LanguageLevel 2.0
41 /MaxClipPathSize 12000                        <
42 /MaxInlineImageSize -1                        <
43 /MaxShadingBitmapSize 256000                  <
44 /MaxViewerMemorySize -1                       <
45 /MonoImageDownsampleThreshold 1.5             | /MonoImageDownsampleThreshold 2.0
46 /MonoImageDownsampleType /Bicubic             | /MonoImageDownsampleType /Subsample
47 /MonoImageResolution 1200                     | /MonoImageResolution 300
48 /Name (ps2write)                              | /Name (pswrite)
49 /NoEncrypt ()                                 <
50 /OffOptimizations 0                           <
51 /Optimize true                                <
52 /OutputDevice /ps2write                       | /OutputDevice /pswrite
53 /OwnerPassword ()                             <
54 /PDFA false                                   <
55 /PDFACompatibilityPolicy 0                    <
56 /PDFEndPage -1                                <
57 /PDFStartPage 1                               <
58 /PDFX false                                   <
59 /PDFXBleedBoxToTrimBoxOffset [0.0 0.0 0.0 0.0]<
60 /PDFXSetBleedBoxToMediaBox true               <
61 /PDFXTrimBoxToMediaBoxOffset [0.0 0.0 0.0 0.0]<
62 /ParseDSCComments true                        <
63 /ParseDSCCommentsForDocInfo true              <
64 /PatternImagemask false                       <
65 /Permissions -4                               <
66 /PreserveCopyPage true                        <
67 /PreserveDeviceN true                         <
68 /PreserveEPSInfo true                         <
69 /PreserveHalftoneInfo true                    | /PreserveHalftoneInfo false
70 /PreserveOPIComments true                     | /PreserveOPIComments false
71 /PreserveOverprintSettings true               | /PreserveOverprintSettings false
72 /PreserveSMask false                          <
73 /PreserveSeparation true                      <
74 /PreserveTrMode false                         <
75 /PrintStatistics false                        <
76 /ProduceDSC true                              <
77 /ReAssignCharacters true                      <
78 /ReEncodeCharacters true                      <
79 /RotatePages false                            <
80 /SetPageSize false                            <
81 /UCRandBGInfo /Preserve                       | /UCRandBGInfo /Remove
82 /UsePrologue false                            <
83 /UserPassword ()                              <
84 /WantsToUnicode false                         <
85 /sRGBProfile (None)                           | /sRGBProfile ()

How to interpret this output?

  • Lines with param key entries on both halves indicate: there is the same key available for both output devices, but each one uses a different default value.
  • Lines with an entry for one half only indicate: this parameter key is unknown to the other output device.

One example is the /GrayImageResolution key: ps2write has this set to 600 by default whereas pswrite uses 150. Another example is /LanguageLevel: ps2write has set it to 2.0, while pswrite doesn’t know about this setting. (It produces PostScript language level 1 only). The third example is /CompressFonts: ps2write will compress fonts by default. (You could override this, by specifying a different behavior on the commandline and force uncompressed fonts in the PostScript output.) pswrite does not support this setting at all.


15.2 Update

As you may imagine this is also a great way to compaare different Ghostscript versions, and track how default settings may have changed for different devices in recent releases. This is especially interesting if you want to find out about all the newly implemented color profile and ICC support which is now present in Ghostscript.

Also, to avoid the return of just -dict- for certain key values, use the === instead of == macro. === acts like == but also prints the content of dictionaries.

So here is the example output for the pdfwrite device. Remember, Ghostscript’s pdfwrite device is meant to provide mostly the same functionality as Adobe Acrobat Distiller (with the additional feature that it does not only accept PostScript as input, but also PDFs, so you can sort of redistill existing PDF files in order to repair, improve or otherwise manipulate them). Therefore, Ghostscript’s pdfdevice honors most of the setdistillerparams operator which the original Distiller also supports. This is the command to use:

1 gs                                                           \
2   -o /dev/null                                               \
3   -sDEVICE=pdfwrite                                          \
4   -c "currentpagedevice {exch ==only ( ) print === } forall" \
5 | sort

On my system, this produces the following output. I include it here in full, because this book will also serve as my personal lookup reference for certain info – in this is one I do need quite frequently:

  1 /%MediaDestination 0
  2 /%MediaSource 0
  3 /.AlwaysEmbed []
  4 /.HWMargins [0.0 0.0 0.0 0.0]
  5 /.IgnoreNumCopies false
  6 /.LockSafetyParams false
  7 /.MarginsHWResolution [720.0 720.0]
  8 /.MediaSize [612.0 792.0]
  9 /.NeverEmbed [                                                                      \
 10                /Courier /Courier-Bold /Courier-Oblique /Courier-BoldOblique         \
 11                /Helvetica /Helvetica-Bold /Helvetica-Oblique /Helvetica-BoldOblique \
 12                /Times-Roman                                                         \
 13                /Times-Bold /Times-Italic /Times-BoldItalic                          \
 14                /Symbol /ZapfDingbats                                                \
 15              ]
 16 /ASCII85EncodePages false
 17 /AllowIncrementalCFF false
 18 /AllowPSRepeatFunctions false
 19 /AlwaysEmbed []
 20 /AntiAliasColorImages false                                                        [*]
 21 /AntiAliasGrayImages false                                                         [*]
 22 /AntiAliasMonoImages false                                                         [*]
 23 /AutoFilterColorImages true
 24 /AutoFilterGrayImages true
 25 /AutoPositionEPSFiles true
 26 /AutoRotatePages /PageByPage
 27 /BeginPage {--.callbeginpage--}
 28 /Binding /Left                                                                     [*]
 29 /BitsPerPixel 24
 30 /BlueValues 256
 31 /CalCMYKProfile (None)                                                             [*]
 32 /CalGrayProfile (None)                                                             [*]
 33 /CalRGBProfile (None)                                                              [*]
 34 /CannotEmbedFontPolicy /Warning                                                    [*]
 35 /CenterPages false
 36 /ColorACSImageDict << /Blend 1 /VSamples [2 1 1 2] /QFactor 0.9 /HSamples [2 1 1 2] >>
 37 /ColorConversionStrategy /LeaveColorUnchanged
 38 /ColorImageDepth -1
 39 /ColorImageDict    << /Blend 1 /VSamples [2 1 1 2] /QFactor 0.9 /HSamples [2 1 1 2] >>
 40 /ColorImageDownsampleThreshold 1.5
 41 /ColorImageDownsampleType /Subsample
 42 /ColorImageFilter /DCTEncode
 43 /ColorImageResolution 150
 44 /ColorValues 16777216
 45 /Colors 3
 46 /CompatibilityLevel 1.4
 47 /CompressEntireFile false
 48 /CompressFonts true
 49 /CompressPages true
 50 /ConvertCMYKImagesToRGB false
 51 /ConvertImagesToIndexed true
 52 /CoreDistVersion 5000
 53 /CreateJobTicket false                                                             [*]
 54 /DSCEncodingToUnicode []
 55 /DefaultRenderingIntent /Default
 56 /DetectBlends true                                                                 [*]
 57 /DetectDuplicateImages true
 58 /DeviceGrayToK true
 59 /DeviceLinkProfile ()
 60 /DoNumCopies false
 61 /DoThumbnails false                                                                [*]
 62 /DocumentTimeSeq 0
 63 /DocumentUUID ()
 64 /DownsampleColorImages false
 65 /DownsampleGrayImages false
 66 /DownsampleMonoImages false
 67 /EmbedAllFonts true
 68 /EmitDSCWarnings false                                                             [*]
 69 /EncodeColorImages true
 70 /EncodeGrayImages true
 71 /EncodeMonoImages true
 72 /EncryptionR 0
 73 /EndPage {--.callendpage--}                                                        [*]
 74 /FirstObjectNumber 1
 75 /FitPages false
 76 /ForOPDFRead false
 77 /GraphicICCProfile ()
 78 /GraphicIntent 0
 79 /GraphicsAlphaBits 1
 80 /GrayACSImageDict << /Blend 1 /VSamples [2 1 1 2] /QFactor 0.9 /HSamples [2 1 1 2] >>
 81 /GrayImageDepth -1
 82 /GrayImageDict    << /Blend 1 /VSamples [2 1 1 2] /QFactor 0.9 /HSamples [2 1 1 2] >>
 83 /GrayImageDownsampleThreshold 1.5
 84 /GrayImageDownsampleType /Subsample
 85 /GrayImageFilter /DCTEncode
 86 /GrayImageResolution 150
 87 /GrayValues 256
 88 /GreenValues 256
 89 /HWResolution [720.0 720.0]
 90 /HWSize [6120 7920]
 91 /HaveCIDSystem false
 92 /HaveTransparency true
 93 /HaveTrueTypes true
 94 /HighLevelDevice true
 95 /ImageICCProfile ()
 96 /ImageIntent 0
 97 /ImageMemory 524288                                                                [*]
 98 /ImagingBBox null
 99 /InputAttributes << \
100                     0 << /PageSize [612.0 792.0] >> \
101                     1 << /PageSize [ 792 1224] >> \
102                     2 << /PageSize [ 612  792] >> \
103                     3 << /PageSize [ 792 1224] >> \
104                     4 << /PageSize [1224 1585] >> \
105                     5 << /PageSize [1585 2448] >> \
106                     6 << /PageSize [2448 3168] >> \
107                     7 << /PageSize [2016 2880] >> \
108                     8 << /PageSize [2384 3370] >> \
109                     9 << /PageSize [1684 2384] >> \
110                    10 << /PageSize [  73  105] >> \
111                    11 << /PageSize [1191 1684] >> \
112                    12 << /PageSize [ 842 1191] >> \
113                    13 << /PageSize [ 595  842] >> \
114                    14 << /PageSize [ 595  842] >> \
115                    15 << /PageSize [ 420  595] >> \
116                    16 << /PageSize [ 297  420] >> \
117                    17 << /PageSize [ 210  297] >> \
118                    18 << /PageSize [ 148  210] >> \
119                    19 << /PageSize [ 105  148] >> \
120                    20 << /PageSize [ 648  864] >> \
121                    21 << /PageSize [ 864 1296] >> \
122                    22 << /PageSize [1296 1728] >> \
123                    23 << /PageSize [1728 2592] >> \
124                    24 << /PageSize [2592 3456] >> \
125                    25 << /PageSize [2835 4008] >> \
126                    26 << /PageSize [2004 2835] >> \
127                    27 << /PageSize [1417 2004] >> \
128                    28 << /PageSize [1001 1417] >> \
129                    29 << /PageSize [ 709 1001] >> \
130                    30 << /PageSize [ 499  709] >> \
131                    31 << /PageSize [ 354  499] >> \
132                    32 << /PageSize [2599 3677] >> \
133                    33 << /PageSize [1837 2599] >> \
134                    34 << /PageSize [1298 1837] >> \
135                    35 << /PageSize [ 918 1298] >> \
136                    36 << /PageSize [ 649  918] >> \
137                    37 << /PageSize [ 459  649] >> \
138                    38 << /PageSize [ 323  459] >> \
139                    39 << /PageSize [ 612  936] >> \
140                    40 << /PageSize [ 612  936] >> \
141                    41 << /PageSize [ 283  420] >> \
142                    42 << /PageSize [ 396  612] >> \
143                    43 << /PageSize [2835 4008] >> \
144                    44 << /PageSize [2004 2835] >> \
145                    45 << /PageSize [1417 2004] >> \
146                    46 << /PageSize [1001 1417] >> \
147                    47 << /PageSize [ 709 1001] >> \
148                    48 << /PageSize [ 499  709] >> \
149                    49 << /PageSize [ 354  499] >> \
150                    50 << /PageSize [2920 4127] >> \
151                    51 << /PageSize [2064 2920] >> \
152                    52 << /PageSize [1460 2064] >> \
153                    53 << /PageSize [1032 1460] >> \
154                    54 << /PageSize [ 729 1032] >> \
155                    55 << /PageSize [ 516  729] >> \
156                    56 << /PageSize [ 363  516] >> \
157                    57 << /PageSize [1224  792] >> \
158                    58 << /PageSize [ 612 1008] >> \
159                    59 << /PageSize [ 612  792] >> \
160                    60 << /PageSize [ 612  792] >> \
161                    61 << /PageSize [ 612  792] >> \
162                    62 << /PageSize [ 595  792] >> \
163                    63 << /PageSize [ 792 1224] >> \
164                    64 << /PageSize [0 0 524287 524287] >> \
165                   >>
166 /Install {--.callinstall--}
167 /InstanceUUID ()
168 /IsDistiller true
169 /KeyLength 0
170 /LZWEncodePages false
171 /Margins [0.0 0.0]
172 /MaxClipPathSize 12000
173 /MaxInlineImageSize 4000
174 /MaxPatternBitmap 0
175 /MaxSeparations 3
176 /MaxShadingBitmapSize 256000
177 /MaxSubsetPct 100
178 /MaxViewerMemorySize -1
179 /MonoImageDepth -1
180 /MonoImageDict << /K -1 >>
181 /MonoImageDownsampleThreshold 1.5
182 /MonoImageDownsampleType /Subsample
183 /MonoImageFilter /CCITTFaxEncode
184 /MonoImageResolution 300
185 /Name (pdfwrite)
186 /NeverEmbed [                                                                     \
187                 /Courier /Courier-Bold /Courier-Oblique /Courier-BoldOblique         \
188                 /Helvetica /Helvetica-Bold /Helvetica-Oblique /Helvetica-BoldOblique \
189                 /Times-Roman /Times-Bold /Times-Italic /Times-BoldItalic             \
190                 /Symbol /ZapfDingbats                                                \
191                ]
192 /NoEncrypt ()
193 /NoT3CCITT false
194 /NumCopies null
195 /OPM 1
196 /OffOptimizations 0
197 /Optimize false                                                                    [*]
198 /OutputAttributes << 0 << >> >>
199 /OutputDevice /pdfwrite
200 /OutputFile (/dev/null)
201 /OutputICCProfile (default_rgb.icc)
202 /OwnerPassword ()
203 /PDFA 0
204 /PDFACompatibilityPolicy 0
205 /PDFEndPage -1
206 /PDFStartPage 1
207 /PDFX false
208 /PDFXBleedBoxToTrimBoxOffset [0.0 0.0 0.0 0.0]
209 /PDFXSetBleedBoxToMediaBox true
210 /PDFXTrimBoxToMediaBoxOffset [0.0 0.0 0.0 0.0]
211 /PageCount 0
212 /PageDeviceName null
213 /PageOffset [0 0]
214 /PageSize [612.0 792.0]
215 /ParseDSCComments true
216 /ParseDSCCommentsForDocInfo true
217 /PatternImagemask false
218 /Permissions -4
219 /Policies <<                                                                   \
220                 /PolicyReport                                                     \
221                        {--dup-- /.LockSafetyParams --known--                      \
222                        {/setpagedevice --.systemvar-- /invalidaccess signalerror} \
223                        --if-- --pop--                                             \
224                   }                                                               \
225                 /PageSize       0                                                 \
226                 /PolicyNotFound 1                                                 \
227              >>
228 /PreserveCopyPage true                                                               [*]
229 /PreserveDeviceN true
230 /PreserveEPSInfo true                                                                [*]
231 /PreserveHalftoneInfo false                                                          [*]
232 /PreserveOPIComments true                                                            [*]
233 /PreserveOverprintSettings true
234 /PreserveSMask true
235 /PreserveSeparation true
236 /PreserveTrMode true
237 /PrintStatistics false
238 /ProcessColorModel /DeviceRGB
239 /ProduceDSC true
240 /ProofProfile ()
241 /ReAssignCharacters true
242 /ReEncodeCharacters true
243 /RedValues 256
244 /RenderIntent 0
245 /RotatePages false
246 /SeparationColorNames []
247 /Separations false
248 /SetPageSize false
249 /SubsetFonts true
250 /TextAlphaBits 1
251 /TextICCProfile ()
252 /TextIntent 0
253 /TransferFunctionInfo /Preserve
254 /UCRandBGInfo /Preserve
255 /UseCIEColor false
256 /UseFastColor false
257 /UseFlateCompression true
258 /UsePrologue false                                                                 [*]
259 /UserPassword ()
260 /WantsToUnicode true
261 /sRGBProfile (None)                                                                [*]

[*] Notes about the above lists:

According to the official Ghostscript documentation, the following settings (which are supported by Adobe Acrobat Distiller) currently on Ghostscript can be set and queried, but setting them does have no effect:

 1 /AntiAliasColorImages
 2 /AntiAliasGrayImages
 3 /AntiAliasMonoImages
 4 /AutoPositionEPSFiles
 5 /Binding
 6 /CalCMYKProfile
 7 /CalGrayProfile
 8 /CalRGBKProfile
 9 /CannotEmbedFontPolicy
10 /ConvertImagesToIndexed
11 /CreateJobTicket
12 /DetectBlends
13 /DoThumbnails
14 /EmitDSCWarnings
15 /EndPage
16 /ImageMemory
17 /LockDistillerParams
18 /Optimize
19 /PreserveCopyPage
20 /PreserveEPSInfo
21 /PreserveHalftoneInfo
22 /PreserveOPIComments
23 /sRGBProfile
24 /StartPage
25 /UsePrologue

You may also want to read the chapter explaining the purpose of Ghostscript dictionaries.