GhostScript命令参数详解

    xiaoxiao2021-03-25  180

    本文列出几个常用参数,然后下面附上官方的参数详解:

    一、常用参数解释

    这是一个测试的命令:gs -dQUIET -dNOSAFER -r300 -dBATCH -sDEVICE=pngalpha -dNOPAUSE -dNOPROMPT -sOutputFile=/opt/shanhy/testpng/%d.png /opt/shanhy/test.pdf

    Linux 中,到文件gs所在目录执行。

    Windows 中,到GhostScript安装目录下的bin目录下执行 gswin64c 或者 gswin32c(根据自己安装的版本)。

    这里注意一下的是:

    1、安装目录下有带“c”的和不带c的,我们使用带c的,不会弹出界面。

    2、如果我们使用Java代码调用,建议不添加“-dQUIET”,因为不添加该参数,会输出日志,这样便于我们判断捕获解析的日志,以及分析页数。

    相关参数如下说明:

        "-dQUIET",    安静的意思,指代执行过程中尽可能少的输出日志等信息。(也可以简写为“-q”)     "-dNOSAFER",    通过命令行运行     "-dBATCH",    执行到最后一页后退出     "-dNOPAUSE",    每一页转换之间没有停顿     "-dNOPROMPT",    没有相关提示                            "-dFirstPage=1",    从第几页开始     "-dLastPage=5",     到第几页结束       "-sDEVICE=pngalpha",    转换输出的文件类型装置,默认值为x11alpha     "-g720x1280",    图片像素(-g<width>x<height>),一般不指定,使用默认输出     "-r300",    图片分辨率(即图片解析度为300dpi),默认值好像是72(未测试证实)     "-sOutputFile=/opt/shanhy/error1png/%d.png",    图片输出路径,使用%d或%ld输出页数

    输出设备如下:

    Default output device: x11alpha Available devices:    alc1900 alc2000 alc4000 alc4100 alc8500 alc8600 alc9100 ap3250 appledmp    atx23 atx24 atx38 bbox bit bitcmyk bitrgb bitrgbtags bj10e bj10v bj10vh    bj200 bjc600 bjc800 bjc880j bjccmyk bjccolor bjcgray bjcmono bmp16 bmp16m    bmp256 bmp32b bmpgray bmpmono bmpsep1 bmpsep8 ccr cdeskjet cdj1600 cdj500    cdj550 cdj670 cdj850 cdj880 cdj890 cdj970 cdjcolor cdjmono cdnj500 cfax    chp2200 cif cljet5 cljet5c cljet5pr coslw2p coslwxl cp50 declj250 deskjet    devicen dfaxhigh dfaxlow dj505j djet500 djet500c dl2100 dnj650c epl2050    epl2050p epl2120 epl2500 epl2750 epl5800 epl5900 epl6100 epl6200 eplcolor    eplmono eps2write eps9high eps9mid epson epsonc escp escpage faxg3    faxg32d faxg4 fmlbp fmpr fpng fs600 gdi hl1240 hl1250 hl7x0 hpdj1120c    hpdj310 hpdj320 hpdj340 hpdj400 hpdj500 hpdj500c hpdj510 hpdj520 hpdj540    hpdj550c hpdj560c hpdj600 hpdj660c hpdj670c hpdj680c hpdj690c hpdj850c    hpdj855c hpdj870c hpdj890c hpdjplus hpdjportable ibmpro ijs imagen    inferno ink_cov inkcov itk24i itk38 iwhi iwlo iwlq jetp3852 jj100 jpeg    jpegcmyk jpeggray la50 la70 la75 la75plus laserjet lbp310 lbp320 lbp8    lex2050 lex3200 lex5700 lex7000 lips2p lips3 lips4 lips4v lj250 lj3100sw    lj4dith lj4dithp lj5gray lj5mono ljet2p ljet3 ljet3d ljet4 ljet4d    ljet4pjl ljetplus ln03 lp1800 lp1900 lp2000 lp2200 lp2400 lp2500 lp2563    lp3000c lp7500 lp7700 lp7900 lp8000 lp8000c lp8100 lp8200c lp8300c    lp8300f lp8400f lp8500c lp8600 lp8600f lp8700 lp8800c lp8900 lp9000b    lp9000c lp9100 lp9200b lp9200c lp9300 lp9400 lp9500c lp9600 lp9600s    lp9800c lps4500 lps6500 lq850 lxm3200 lxm5700m m8510 mag16 mag256    md1xMono md2k md50Eco md50Mono md5k mgr4 mgr8 mgrgray2 mgrgray4 mgrgray8    mgrmono miff24 mj500c mj6000c mj700v2c mj8000c ml600 necp6 npdl nullpage    oce9050 oki182 oki4w okiibm oprp opvp paintjet pam pamcmyk32 pamcmyk4 pbm    pbmraw pcl3 pcx16 pcx24b pcx256 pcx2up pcxcmyk pcxgray pcxmono pdfwrite    pgm pgmraw pgnm pgnmraw photoex picty180 pj pjetxl pjxl pjxl300 pkm    pkmraw pksm pksmraw plan plan9bm planc plang plank planm png16 png16m    png256 png48 pngalpha pnggray pngmono pnm pnmraw ppm ppmraw pr1000    pr1000_4 pr150 pr201 ps2write psdcmyk psdcmykog psdrgb pxlcolor pxlmono    r4081 rinkj rpdl samsunggdi sgirgb sj48 spotcmyk st800 stcolor sunhmono    t4693d2 t4693d4 t4693d8 tek4696 tiff12nc tiff24nc tiff32nc tiff48nc    tiff64nc tiffcrle tiffg3 tiffg32d tiffg4 tiffgray tifflzw tiffpack    tiffscaled tiffsep tiffsep1 txtwrite uniprint x11 x11alpha x11cmyk    x11cmyk2 x11cmyk4 x11cmyk8 x11gray2 x11gray4 x11mono x11rg16x x11rg32x    xcf xes xpswrite

    二、官方参数详解

    How to use Ghostscript

    Table of contents

    Invoking Ghostscript Help at the command line: gs -h Selecting an output device Output resolutionOutput to files One page per file Choosing paper sizeChanging the installed default paper size Interacting with pipesUsing Ghostscript with PDF files Switches for PDF filesProblems interpreting a PDF filePDF files from standard input Using Ghostscript with EPS filesUsing Ghostscript with overprinting and spot colorsHow Ghostscript finds files Finding PostScript Level 2 resourcesFont lookupCID fontsCID font substitutionUsing Unicode True Type fontsTemporary files Notes on specific platforms UnixVMS Using X Windows on VMS MS WindowsX Windows X resourcesWorking around bugs in X serversX fontsUsing Ghostscript fonts on X displaysX device parameters SCO Unix Command line options General switches Input controlFile searchingSetting parametersSuppress messages Parameter switches (-d and -s) Rendering parametersPage parametersFont-related parametersResource-related parametersInteraction-related parametersDevice and output selection parametersEPS parametersDeferred Page RenderingICC color parametersOther parameters Improving performanceSummary of environment variablesDebugging Debug SwitchesVisual Trace Appendix: Paper sizes known to GhostscriptAppendix: X default font mappings Standard X servers Regular fontsSymbol fontsDingbat fonts Sun OpenWindows Appendix: Running Ghostscript with third-partyfont renderers

    For other information, see the Ghostscriptoverview and, if necessary, how toinstall Ghostscript.


    Invoking Ghostscript

    This document describes how to use the command line Ghostscript client.Ghostscript is also used as a general engine inside other applications (for viewing files for example).Please refer to the documentation for those applications for using Ghostscript in other contexts.

    The command line to invoke Ghostscript isessentially the same on all systems, although the name of the executableprogram itself may differ among systems. For instance, to invokeGhostscript on unix-like systems type:

    gs [options] {filename 1} ... [options] {filename N} ...

    Here are some basic examples. The details of how these work are described below.

    To view a file:

    gs -dSAFER -dBATCH document.pdf You'll be prompted to press return between pages.

    To convert a figure to an image file:

    gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -dGraphicsAlphaBits=4 \ -sOutputFile=tiger.png tiger.eps

    To render the same image at 300 dpi:

    gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r300 \ -sOutputFile=tiger_300.png tiger.eps

    To render a figure in grayscale:

    gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pnggray -sOutputFile=figure.png figure.pdf

    To rasterize a whole document:

    gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pgmraw -r150 \ -dTextAlphaBits=4 -sOutputFile='paper-d.pgm' paper.ps

    There are also a number of utility scripts for commonto convert a PostScript document to PDF:

    ps2pdf file.ps The output is saved as file.pdf.

    There are other utility scripts besides ps2pdf, including pdf2ps, ps2epsi, pdf2dsc, ps2ascii,ps2ps and ps2ps2. These just call Ghostscript with the appropriate(if complicated) set of options. You can use the 'ps2' set with eps files.

    Ghostscript is capable of interpreting PostScript, encapsulated PostScript(EPS), DOS EPS (EPSF), and Adobe Portable Document Format (PDF). The interpreter reads and executes the files in sequence, using the method described under "File searching" to find them.

    The interpreter runs in interactive mode by default. After processing the files given on the command line (if any) it reads further lines of PostScript language commands from the primary input stream, normally the keyboard, interpreting each line separately. To quit the interpreter, type "quit". The -dBATCH -dNOPAUSE options in the examples above disable the interactive prompting. The interpreter also quits gracefully if it encounters end-of-file or control-C.

    The interpreter recognizes many options. An option may appear anywhere in the command line, and applies to all files named after it on the line. Many of them include "="followed by a parameter. The most important are described in detail here. Please see the reference sections on options and devices for a more complete listing.

    Help at the command line: gs -h

    You can get a brief help message by invoking Ghostscript with the-h or -? switch, like this:

    gs -h gs -?

    The message shows for that version of the Ghostscript executable:

    the version and release informationthe general format of the command linea few of the most useful optionsthe formats it can interpretthe available output devicesthe search paththe bug report address

    On other systems the executable may have a different name:

    System invocation nameUnix gsVMS gsMS Windows 95 and later gswin32cOS/2 gsos2

    Selecting an output device

    Ghostscript has a notion of 'output devices' which handle saving or displaying the results in a particular format. Ghostscript comes with a diverse variety of such devices supporting vector and raster file output, screen display, driving various printers and communicating with other applications.

    The command line option '-sDEVICE=device' selects which output device Ghostscript should use. If this option isn't given the default device (usually a display device) is used. Ghostscript's built-in help message (gs -h) liststhe available output devices. For complete description of the devices distributed with Ghostscript and their options, please see the devices section of the documentation.

    Note that this switch must precede the name of the first input file, andonly its first use has any effect. For example, for printer output in aconfiguration that includes an Epson printer driver, instead of just'gs myfile.ps' you might use

    gs -sDEVICE=epson myfile.ps

    The output device can also be set through the GS_DEVICE environment variable.

    Once you invoke Ghostscriptyou can also find out what devices are available by typing'devicenames ==' at the interactive prompt.You can set the output device and process a file from the interactive prompt as well:

    (epson) selectdevice (myfile.ps) run All output then goes to the Epson printer instead of the display until youdo something to change devices. You can switch devices at any time byusing the selectdevice procedure, forinstance like one of these: (x11alpha) selectdevice (epson) selectdevice

    Output resolution

    Some printers can print at several different resolutions, letting youbalance resolution against printing speed. To select the resolution onsuch a printer, use the -r switch:

    gs -sDEVICE= printer -r XRES x YRES where XRES and YRES are the requested number of dots (or pixels) per inch. Where the two resolutions are same, as is the common case, you can simply use -r res.

    The -r option is also useful for controlling the density of pixels when rasterizing to an image file. It is used this way in the examples at the beginning of this document.

    Output to files

    Ghostscript also allows you to control where it sends its output. With a display device this isn't necessary as the device handles presenting the output on screen internally. Some specialized printer drivers operate this way as well, but most devices are general and need to be directed to a particular file or printer.

    To send the output to a file, use the -sOutputFile= switch or the -o switch (below).For instance, to direct all output into the file ABC.xyz, use

    gs -sOutputFile=ABC.xyz

    When printing on MS Windows systems, output normally goes directly to the printer, PRN. On Unix and VMS systems it normally goes to a temporary file which is sent to the printer in a separate step. When using Ghostscript as a file rasterizer (converting PostScript or PDF to a raster image format) you will of course want to specify an appropriately named file for the output.

    Ghostscript also accepts the special filename '-' which indicates the output should be written to standard output (the command shell).

    Be aware that filenames beginning with the character % have a special meaning in PostScript. If you need to specify a file name that actuallybegins with %, you must prepend the %os% filedevice explicitly. For example to output to a file named

    转载请注明原文地址: https://ju.6miu.com/read-6578.html

    最新回复(0)