在Ghostscript中查询输出设备的默认选项/设置(例如"pdfwrite"或"tiffg4") [英] Querying Ghostscript for the default options/settings of an output device (such as 'pdfwrite' or 'tiffg4')

查看:98
本文介绍了在Ghostscript中查询输出设备的默认选项/设置(例如"pdfwrite"或"tiffg4")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此答案中,将EPS转换为PDF的GhostScript命令行参数" ;据说Ghostscript的pdfwrite设备的默认分辨率是720x720,我最初发现这太不可思议了!

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!

是否可以列出Ghostscript设备的默认选项?

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

推荐答案

由于Ghostscript是完善的PostScript解释器,因此您也可以向其发送PostScript代码段,这些代码段不会导致绘制页面元素,但是会查询页面元素内部状态.

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.

如果您想知道 Display 的默认设置是什么,当您通过gs some.pdf要求它仅在屏幕上显示PDF时,您可以尝试以下操作:

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:

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

在Windows上,它变为:

On Windows this becomes:

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

结果是一个/SomeName somevalue对的列表,这些对描述了用于将页面呈现到当前屏幕的设置.

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

之所以这样,是因为通常显示器是Ghostscript将其输出发送到的默认设备.现在您可能会注意到,将弹出一个空的Ghostscript窗口,您必须将其关闭....嗯,如何添加一些避免弹出窗口的选项?

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?

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

或者,在Windows上:

Or, on Windows:

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

但这将更改查询的返回值,因为您(无意间)更改了输出设备设置:

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

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

结果:

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

将此与

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

结果:

/HWResolution [72.0 72.0]
/.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...

现在假设您要查询PDF书写设备的默认设置,请运行以下命令:

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

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

您现在将在* .txt文件中具有pdfwrite设备的所有设置.然后您可以将其与其他一些有趣的Ghostscript设备重复进行,然后将它们的所有详细差异进行比较:

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:

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

比较这样的pswriteps2write设备的设置非常有趣(并且还会发现适用于一个设备而不是另一设备的参数):

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):

sdiff -sbB ghostscript-ps*write-default-pagedevice-settings.txt


更新:

您可能会想到,这也是比较不同Ghostscript版本以及跟踪最新版本中不同设备的默认设置可能如何变化的一种好方法.如果您想了解Ghostscript中现在提供的所有新实施的颜色配置文件和ICC支持,则尤其有趣.

As you may imagine this is also a great way to compare 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.

此外,为避免某些键值仅返回-dict-,请使用===而不是==宏. ===的行为与==相似,但也会打印字典的 content .

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.

因此,这是pdfwrite设备的示例输出.请记住,Ghostscript的pdfwrite设备旨在提供与 Adob​​e Acrobat Distiller 大致相同的功能(其附加功能是它不仅接受PostScript作为输入,而且还接受PDF,因此您可以 redistill 现有的PDF文件,以便对其进行修复,改进或其他操作).因此,Ghostscript的pdfdevice尊重了原Distiller还支持的大多数setdistillerparams运算符:

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:

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

/%MediaDestination 0
/%MediaSource 0
/.AlwaysEmbed []
/.HWMargins [0.0 0.0 0.0 0.0]
/.IgnoreNumCopies false
/.LockSafetyParams false
/.MarginsHWResolution [720.0 720.0]
/.MediaSize [612.0 792.0]
/.NeverEmbed [/Courier /Courier-Bold /Courier-Oblique /Courier-BoldOblique /Helvetica /Helvetica-Bold /Helvetica-Oblique /Helvetica-BoldOblique /Times-Roman /Times-Bold /Times-Italic /Times-BoldItalic /Symbol /ZapfDingbats]
/ASCII85EncodePages false
/AllowIncrementalCFF false
/AllowPSRepeatFunctions false
/AlwaysEmbed []
/AntiAliasColorImages false          [*]
/AntiAliasGrayImages false           [*]
/AntiAliasMonoImages false           [*]
/AutoFilterColorImages true
/AutoFilterGrayImages true
/AutoPositionEPSFiles true
/AutoRotatePages /PageByPage
/BeginPage {--.callbeginpage--}
/Binding /Left                       [*]
/BitsPerPixel 24
/BlueValues 256
/CalCMYKProfile (None)               [*]
/CalGrayProfile (None)               [*]
/CalRGBProfile (None)                [*]
/CannotEmbedFontPolicy /Warning      [*]
/CenterPages false
/ColorACSImageDict << /Blend 1 /VSamples [2 1 1 2] /QFactor 0.9 /HSamples [2 1 1 2] >>
/ColorConversionStrategy /LeaveColorUnchanged
/ColorImageDepth -1
/ColorImageDict << /Blend 1 /VSamples [2 1 1 2] /QFactor 0.9 /HSamples [2 1 1 2] >>
/ColorImageDownsampleThreshold 1.5
/ColorImageDownsampleType /Subsample
/ColorImageFilter /DCTEncode
/ColorImageResolution 150
/ColorValues 16777216
/Colors 3
/CompatibilityLevel 1.4
/CompressEntireFile false
/CompressFonts true
/CompressPages true
/ConvertCMYKImagesToRGB false
/ConvertImagesToIndexed true
/CoreDistVersion 5000
/CreateJobTicket false               [*]
/DSCEncodingToUnicode []
/DefaultRenderingIntent /Default
/DetectBlends true                   [*]
/DetectDuplicateImages true
/DeviceGrayToK true
/DeviceLinkProfile ()
/DoNumCopies false
/DoThumbnails false                  [*]
/DocumentTimeSeq 0
/DocumentUUID ()
/DownsampleColorImages false
/DownsampleGrayImages false
/DownsampleMonoImages false
/EmbedAllFonts true
/EmitDSCWarnings false               [*]
/EncodeColorImages true
/EncodeGrayImages true
/EncodeMonoImages true
/EncryptionR 0
/EndPage {--.callendpage--}          [*]
/FirstObjectNumber 1
/FitPages false
/ForOPDFRead false
/GraphicICCProfile ()
/GraphicIntent 0
/GraphicsAlphaBits 1
/GrayACSImageDict << /Blend 1 /VSamples [2 1 1 2] /QFactor 0.9 /HSamples [2 1 1 2] >>
/GrayImageDepth -1
/GrayImageDict << /Blend 1 /VSamples [2 1 1 2] /QFactor 0.9 /HSamples [2 1 1 2] >>
/GrayImageDownsampleThreshold 1.5
/GrayImageDownsampleType /Subsample
/GrayImageFilter /DCTEncode
/GrayImageResolution 150
/GrayValues 256
/GreenValues 256
/HWResolution [720.0 720.0]
/HWSize [6120 7920]
/HaveCIDSystem false
/HaveTransparency true
/HaveTrueTypes true
/HighLevelDevice true
/ImageICCProfile ()
/ImageIntent 0
/ImageMemory 524288                  [*]
/ImagingBBox null
/InputAttributes << 59 << /PageSize [612 792] >> 36 << /PageSize [649 918] >> 13 << /PageSize [595 842] >> 49 << /PageSize [354 499] >> 26 << /PageSize [2004 2835] >> 3 << /PageSize [792 1224] >> 62 << /PageSize [595 792] >> 39 << /PageSize [612 936] >> 16 << /PageSize [297 420] >> 52 << /PageSize [1460 2064] >> 29 << /PageSize [709 1001] >> 6 << /PageSize [2448 3168] >> 42 << /PageSize [396 612] >> 19 << /PageSize [105 148] >> 55 << /PageSize [516 729] >> 32 << /PageSize [2599 3677] >> 9 << /PageSize [1684 2384] >> 45 << /PageSize [1417 2004] >> 22 << /PageSize [1296 1728] >> 58 << /PageSize [612 1008] >> 35 << /PageSize [918 1298] >> 12 << /PageSize [842 1191] >> 48 << /PageSize [499 709] >> 25 << /PageSize [2835 4008] >> 2 << /PageSize [612 792] >> 61 << /PageSize [612 792] >> 38 << /PageSize [323 459] >> 15 << /PageSize [420 595] >> 51 << /PageSize [2064 2920] >> 28 << /PageSize [1001 1417] >> 5 << /PageSize [1585 2448] >> 64 << /PageSize [0 0 524287 524287] >> 41 << /PageSize [283 420] >> 18 << /PageSize [148 210] >> 54 << /PageSize [729 1032] >> 31 << /PageSize [354 499] >> 8 << /PageSize [2384 3370] >> 44 << /PageSize [2004 2835] >> 21 << /PageSize [864 1296] >> 57 << /PageSize [1224 792] >> 34 << /PageSize [1298 1837] >> 11 << /PageSize [1191 1684] >> 47 << /PageSize [709 1001] >> 24 << /PageSize [2592 3456] >> 1 << /PageSize [792 1224] >> 60 << /PageSize [612 792] >> 37 << /PageSize [459 649] >> 14 << /PageSize [595 842] >> 50 << /PageSize [2920 4127] >> 27 << /PageSize [1417 2004] >> 4 << /PageSize [1224 1585] >> 63 << /PageSize [792 1224] >> 40 << /PageSize [612 936] >> 17 << /PageSize [210 297] >> 53 << /PageSize [1032 1460] >> 30 << /PageSize [499 709] >> 7 << /PageSize [2016 2880] >> 43 << /PageSize [2835 4008] >> 20 << /PageSize [648 864] >> 56 << /PageSize [363 516] >> 33 << /PageSize [1837 2599] >> 10 << /PageSize [73 105] >> 46 << /PageSize [1001 1417] >> 23 << /PageSize [1728 2592] >> 0 << /PageSize [612.0 792.0] >> >>
/Install {--.callinstall--}
/InstanceUUID ()
/IsDistiller true
/KeyLength 0
/LZWEncodePages false
/Margins [0.0 0.0]
/MaxClipPathSize 12000
/MaxInlineImageSize 4000
/MaxPatternBitmap 0
/MaxSeparations 3
/MaxShadingBitmapSize 256000
/MaxSubsetPct 100
/MaxViewerMemorySize -1
/MonoImageDepth -1
/MonoImageDict << /K -1 >>
/MonoImageDownsampleThreshold 1.5
/MonoImageDownsampleType /Subsample
/MonoImageFilter /CCITTFaxEncode
/MonoImageResolution 300
/Name (pdfwrite)
/NeverEmbed [/Courier /Courier-Bold /Courier-Oblique /Courier-BoldOblique /Helvetica /Helvetica-Bold /Helvetica-Oblique /Helvetica-BoldOblique /Times-Roman /Times-Bold /Times-Italic /Times-BoldItalic /Symbol /ZapfDingbats]
/NoEncrypt ()
/NoT3CCITT false
/NumCopies null
/OPM 1
/OffOptimizations 0
/Optimize false                      [*]
/OutputAttributes << 0 << >> >>
/OutputDevice /pdfwrite
/OutputFile (/dev/null)
/OutputICCProfile (default_rgb.icc)
/OwnerPassword ()
/PDFA 0
/PDFACompatibilityPolicy 0
/PDFEndPage -1
/PDFStartPage 1
/PDFX false
/PDFXBleedBoxToTrimBoxOffset [0.0 0.0 0.0 0.0]
/PDFXSetBleedBoxToMediaBox true
/PDFXTrimBoxToMediaBoxOffset [0.0 0.0 0.0 0.0]
/PageCount 0
/PageDeviceName null
/PageOffset [0 0]
/PageSize [612.0 792.0]
/ParseDSCComments true
/ParseDSCCommentsForDocInfo true
/PatternImagemask false
/Permissions -4
/Policies << /PolicyReport {--dup-- /.LockSafetyParams --known-- {/setpagedevice --.systemvar-- /invalidaccess signalerror} --if-- --pop--} /PageSize 0 /PolicyNotFound 1 >>
/PreserveCopyPage true               [*]
/PreserveDeviceN true
/PreserveEPSInfo true                [*]
/PreserveHalftoneInfo false          [*]
/PreserveOPIComments true            [*]
/PreserveOverprintSettings true
/PreserveSMask true
/PreserveSeparation true
/PreserveTrMode true
/PrintStatistics false
/ProcessColorModel /DeviceRGB
/ProduceDSC true
/ProofProfile ()
/ReAssignCharacters true
/ReEncodeCharacters true
/RedValues 256
/RenderIntent 0
/RotatePages false
/SeparationColorNames []
/Separations false
/SetPageSize false
/SubsetFonts true
/TextAlphaBits 1
/TextICCProfile ()
/TextIntent 0
/TransferFunctionInfo /Preserve
/UCRandBGInfo /Preserve
/UseCIEColor false
/UseFastColor false
/UseFlateCompression true
/UsePrologue false                   [*]
/UserPassword ()
/WantsToUnicode true
/sRGBProfile (None)                  [*]

[*]注意:

根据官方文档,可以设置和查询Ghostscript上当前存在的以下设置(Adobe Acrobat Distiller支持),但但设置没有任何作用:

  • /AntiAliasColorImages
  • /AntiAliasGrayImages
  • /AntiAliasMonoImages
  • /AutoPositionEPSFiles
  • /Binding
  • /CalCMYKProfile
  • /CalGrayProfile
  • /CalRGBKProfile
  • /CannotEmbedFontPolicy
  • /ConvertImagesToIndexed
  • /CreateJobTicket
  • /DetectBlends
  • /DoThumbnails
  • /EmitDSCWarnings
  • /EndPage
  • /ImageMemory
  • /LockDistillerParams
  • /Optimize
  • /PreserveCopyPage
  • /PreserveEPSInfo
  • /PreserveHalftoneInfo
  • /PreserveOPIComments
  • /sRGBProfile
  • /StartPage
  • /UsePrologue
    • /AntiAliasColorImages
    • /AntiAliasGrayImages
    • /AntiAliasMonoImages
    • /AutoPositionEPSFiles
    • /Binding
    • /CalCMYKProfile
    • /CalGrayProfile
    • /CalRGBKProfile
    • /CannotEmbedFontPolicy
    • /ConvertImagesToIndexed
    • /CreateJobTicket
    • /DetectBlends
    • /DoThumbnails
    • /EmitDSCWarnings
    • /EndPage
    • /ImageMemory
    • /LockDistillerParams
    • /Optimize
    • /PreserveCopyPage
    • /PreserveEPSInfo
    • /PreserveHalftoneInfo
    • /PreserveOPIComments
    • /sRGBProfile
    • /StartPage
    • /UsePrologue
    • 这篇关于在Ghostscript中查询输出设备的默认选项/设置(例如"pdfwrite"或"tiffg4")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆