【问题标题】:Querying Ghostscript for the default options/settings of an output device (such as 'pdfwrite' or 'tiffg4')查询 Ghostscript 以获取输出设备的默认选项/设置(例如“pdfwrite”或“tiffg4”)
【发布时间】:2012-06-15 14:20:54
【问题描述】:

this answer to 'GhostScript command line parameters to convert EPS to PDF';据说Ghostscript的pdfwrite设备的默认分辨率是720x720,我一开始觉得难以置信!

有没有办法列出 Ghostscript 设备的默认选项?

【问题讨论】:

    标签: ghostscript


    【解决方案1】:

    由于 Ghostscript 是一个成熟的 PostScript 解释器,您还可以向它发送 PostScript sn-ps,它不会导致页面元素的绘制,但会查询它的内部状态。

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

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

    在 Windows 上变成:

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

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

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

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

    或者,在 Windows 上:

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

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

    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]
    

    所以,请避开这个陷阱。几年前就成功掉进去了,好久都没注意到……

    现在假设你要查询 PDF 书写设备的默认设置,运行这个:

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

    您现在将在 *.txt 文件中拥有pdfwrite 设备的所有设置。你可以用其他一些有趣的 Ghostscript 设备重复这一点,然后比较它们的所有细节差异:

    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 设备的设置是相当有趣的(并且还发现可用于一个设备但不能用于其他设备的参数):

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

    更新:

    正如您所想象的,这也是比较不同 Ghostscript 版本的好方法,并跟踪最近版本中不同设备的默认设置可能发生的变化。如果您想了解 Ghostscript 现在提供的所有新实现的颜色配置文件和 ICC 支持,这将特别有趣。

    另外,为了避免某些键值只返回-dict-,请使用=== 而不是== 宏。 === 的作用类似于 ==,但也打印字典的内容

    下面是pdfwrite 设备的示例输出。请记住,Ghostscript 的pdfwrite 设备旨在提供与 Adobe Acrobat Distiller 大致相同的功能(具有附加功能,它不仅接受 PostScript 作为输入,还接受 PDF,因此您可以排序重新提取现有的 PDF 文件以修复、改进或以其他方式操作它们)。因此,Ghostscript 的 pdfdevice 尊重大部分 setdistillerparams 操作符,原始 Distiller 也支持:

    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

    【讨论】:

    • 哇,太棒了——非常感谢@pipitas!直到现在我才真正理解“PostScript 解释器”的含义 - 记录这些命令方法非常有用......再次非常感谢 - 干杯!
    • 感谢@pipitas 的更新——这是一个很棒的在线资源;干杯!
    • @sdaau: 呵呵...在线7天后已经有41个浏览量... :-)
    • @sdaau:您是否也想知道如何查询 Ghostscript 以获取其内部 字典 的内容?
    • @sdaau:你可以结合起来问“PostScript 中的字典是什么?” :-)
    猜你喜欢
    • 2018-12-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-22
    • 2017-01-12
    • 2019-11-14
    • 2011-05-07
    • 1970-01-01
    • 2022-04-04
    相关资源
    最近更新 更多