{
    "mode": "man",
    "parameter": "gs",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/gs/1/json",
    "generated": "2026-11-08T04:00:08Z",
    "synopsis": "gs [ options ] [ files ] ...",
    "sections": {
        "NAME": {
            "content": "gs - Ghostscript (PostScript and PDF language interpreter and previewer)\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "gs [ options ] [ files ] ...\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The  gs  command  invokes  Ghostscript,  an  interpreter of Adobe Systems' PostScript(tm) and\nPortable Document Format (PDF) languages.  gs reads \"files\" in sequence and executes them  as\nGhostscript programs. After doing this, it reads further input from the standard input stream\n(normally  the  keyboard),  interpreting  each line separately and output to an output device\n(may be a file or an X11 window preview, see below). The interpreter exits gracefully when it\nencounters the \"quit\" command (either in a file or from the keyboard), at end-of-file, or  at\nan interrupt signal (such as Control-C at the keyboard).\n\nThe  interpreter  recognizes  many option switches, some of which are described below. Please\nsee the usage documentation for complete information. Switches may  appear  anywhere  in  the\ncommand  line  and  apply  to  all  files thereafter.  Invoking Ghostscript with the -h or -?\nswitch produces a message which shows several useful switches, all the devices known to  that\nexecutable,  and  the  search  path for fonts; on Unix it also shows the location of detailed\ndocumentation.\n\nGhostscript may be built to use many different output devices.  To see which devices your ex‐\necutable includes, run \"gs -h\".\n\nUnless you specify a particular device, Ghostscript normally opens the first one of those and\ndirects output to it.\n\nIf you have installed the ghostscript-x Debian package and are under X, the default device is\nan X11 window (previewer), else ghostscript will use the bbox device and print on stdout  the\ndimension of the postscript file.\n\nSo if the first one in the list is the one you want to use, just issue the command\n\ngs myfile.ps\n\nYou  can  also check the set of available devices from within Ghostscript: invoke Ghostscript\nand type\n\ndevicenames ==\n\nbut the first device on the resulting list may not be the default device you  determine  with\n\"gs -h\".  To specify \"AbcXyz\" as the initial output device, include the switch\n\n-sDEVICE=AbcXyz\n\nFor example, for output to an Epson printer you might use the command\n\ngs -sDEVICE=epson myfile.ps\n\nThe  \"-sDEVICE=\"  switch  must  precede  the  first  mention of a file to print, and only the\nswitch's first use has any effect.\n\nFinally, you can specify a default device in the environment variable GSDEVICE.   The  order\nof  precedence for these alternatives from highest to lowest (Ghostscript uses the device de‐\nfined highest in the list) is:\n\nSome devices can support different resolutions (densities).  To  specify  the  resolution  on\nsuch a printer, use the \"-r\" switch:\n\ngs -sDEVICE=<device> -r<xres>x<yres>\n\nFor  example,  on a 9-pin Epson-compatible printer, you get the lowest-density (fastest) mode\nwith\n\ngs -sDEVICE=epson -r60x72\n\nand the highest-density (best output quality) mode with\n\ngs -sDEVICE=epson -r240x72.\n\nIf you select a printer as the output device, Ghostscript also allows  you  to  choose  where\nGhostscript  sends  the  output -- on Unix systems, usually to a temporary file.  To send the\noutput to a file \"foo.xyz\", use the switch\n\n-sOutputFile=foo.xyz\n\nYou might want to print each page separately.  To do this, send the output  to  a  series  of\nfiles \"foo1.xyz, foo2.xyz, ...\" using the \"-sOutputFile=\" switch with \"%d\" in a filename tem‐\nplate:\n\n-sOutputFile=foo%d.xyz\n\nEach  resulting  file  receives  one  page of output, and the files are numbered in sequence.\n\"%d\" is a printf format specification; you can also use a variant like \"%02d\".\n\nYou can also send output to a pipe.  For example, to pipe output to the \"lpr\" command (which,\non many Unix systems, directs it to a printer), use the option\n\n-sOutputFile=%pipe%lpr\n\nYou can also send output to standard output:\n\n-sOutputFile=-\nor\n-sOutputFile=%stdout%\n\nIn this case you must also use the -q switch, to prevent Ghostscript from writing messages to\nstandard output.\n\nTo select a specific paper size, use the command line switch\n\n-sPAPERSIZE=<papersize>\n\nfor instance\n\n-sPAPERSIZE=a4\nor\n-sPAPERSIZE=legal\n\nMost ISO and US paper sizes are recognized. See the usage documentation for a full  list,  or\nthe definitions in the initialization file \"gsstatd.ps\".\n\nGhostscript  can do many things other than print or view PostScript and PDF files.  For exam‐\nple, if you want to know the bounding box of a PostScript (or EPS) file, Ghostscript provides\na special \"device\" that just prints out this information.\n\nFor example, using one of the example files distributed with Ghostscript,\n\ngs -sDEVICE=bbox golfer.ps\n\nprints out\n\n%%BoundingBox: 0 25 583 732\n%%HiResBoundingBox: 0.808497 25.009496 582.994503 731.809445\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "-- filename arg1 ...\nTakes the next argument as a file name as usual, but  takes  all  remaining  arguments\n(even if they have the syntactic form of switches) and defines the name \"ARGUMENTS\" in\n\"userdict\"  (not  \"systemdict\") as an array of those strings, before running the file.\nWhen Ghostscript finishes executing the file, it exits back to the shell.\n",
            "subsections": [
                {
                    "name": "-D_",
                    "content": ""
                },
                {
                    "name": "-d_",
                    "content": "Define a name in \"systemdict\" with the given definition.  The token  must  be  exactly\none token (as defined by the \"token\" operator) and may contain no whitespace.\n"
                },
                {
                    "name": "-D_",
                    "content": ""
                },
                {
                    "name": "-d_",
                    "content": ""
                },
                {
                    "name": "-S_",
                    "content": ""
                },
                {
                    "name": "-s_",
                    "content": "Define  a  name  in \"systemdict\" with a given string as value.  This is different from\n-d.  For example, -dname=35 is equivalent to the program fragment\n/name 35 def\nwhereas -sname=35 is equivalent to\n/name (35) def\n"
                },
                {
                    "name": "-P",
                    "content": "fault,  Ghostscript  no  longer looks in the current directory, unless, of course, the\nfirst explicitly supplied directory is \".\" in -I.  See also the  INITIALIZATION  FILES\nsection  below,  and  bundled  Use.htm for detailed discussion on search paths and how\nGhostcript finds files.\n",
                    "flag": "-P"
                },
                {
                    "name": "-q",
                    "content": "-dQUIET.\n",
                    "flag": "-q"
                },
                {
                    "name": "-g_",
                    "content": "Equivalent to -dDEVICEWIDTH=number1 and -dDEVICEHEIGHT=number2.  This is for the bene‐\nfit  of  devices  (such as X11 windows) that require (or allow) width and height to be\nspecified.\n"
                },
                {
                    "name": "-r_",
                    "content": ""
                },
                {
                    "name": "-r_",
                    "content": "Equivalent to -dDEVICEXRESOLUTION=number1 and  -dDEVICEYRESOLUTION=number2.   This  is\nfor the benefit of devices such as printers that support multiple X and Y resolutions.\nIf only one number is given, it is used for both X and Y resolutions.\n"
                },
                {
                    "name": "-I_",
                    "content": "Adds  the  designated  list  of directories at the head of the search path for library\nfiles.\n\n-      This is not really a switch, but indicates to Ghostscript that standard input is  com‐\ning  from  a  file or a pipe and not interactively from the command line.  Ghostscript\nreads from standard input until it reaches end-of-file, executing it  like  any  other\nfile,  and then continues with processing the command line.  When the command line has\nbeen entirely processed, Ghostscript exits rather  than  going  into  its  interactive\nmode.\n\nNote  that  the  normal initialization file \"gsinit.ps\" makes \"systemdict\" read-only, so the\nvalues of names defined with -D, -d, -S, or -s cannot be changed (although, of  course,  they\ncan be superseded by definitions in \"userdict\" or other dictionaries.)\n"
                }
            ]
        },
        "SPECIAL NAMES": {
            "content": "",
            "subsections": [
                {
                    "name": "-dNOCACHE",
                    "content": "Disables character caching.  Useful only for debugging.\n"
                },
                {
                    "name": "-dNOBIND",
                    "content": "Disables the \"bind\" operator.  Useful only for debugging.\n"
                },
                {
                    "name": "-dNODISPLAY",
                    "content": "Suppresses  the  normal  initialization of the output device.  This may be useful when\ndebugging.\n"
                },
                {
                    "name": "-dNOPAUSE",
                    "content": "Disables the prompt and pause at the end of each page.  This may be desirable for  ap‐\nplications where another program is driving Ghostscript.\n"
                },
                {
                    "name": "-dNOPLATFONTS",
                    "content": "Disables  the  use  of  fonts supplied by the underlying platform (for instance X Win‐\ndows). This may be needed if the platform fonts look undesirably  different  from  the\nscalable fonts.\n"
                },
                {
                    "name": "-dSAFER",
                    "content": "Restricts file operations the job can perform. Now the default mode of operation.\n"
                },
                {
                    "name": "-dWRITESYSTEMDICT",
                    "content": "Leaves  \"systemdict\"  writable.   This  is necessary when running special utility pro‐\ngrams, but is strongly discouraged as it bypasses normal Postscript security measures.\n"
                },
                {
                    "name": "-sDEVICE=_",
                    "content": "Selects an alternate initial output device, as described above.\n"
                },
                {
                    "name": "-sOutputFile=_",
                    "content": "Selects an alternate output file (or pipe) for the initial output device, as described\nabove.\n"
                }
            ]
        },
        "SAFER MODE": {
            "content": "The -dSAFER option restricts file system accesses to those files and directories  allowed  by\nthe  relevant  environment  variables (such as GSLIB) or by the command line parameters (see\nhttps://ghostscript.com/doc/current/Use.htm for details).\n\nSAFER mode is now the default mode of operation. Thus when running programs that need to open\nfiles or set restricted parameters you should pass the -dNOSAFER command line option  or  its\nsynonym -dDELAYSAFER.\n\nRunning  with NOSAFER/DELAYSAFER (as the same suggests) loosens the security and is thus rec‐\nommended ONLY for debugging or in VERY controlled workflows, and strongly NOT recommended  in\nany other circumstances.\n",
            "subsections": []
        },
        "FILES": {
            "content": "The  locations of many Ghostscript run-time files are compiled into the executable when it is\nbuilt.  Run \"gs -h\" to find the location of Ghostscript documentation on  your  system,  from\nwhich you can get more details. On a Debian system they are in /usr.\n\n/usr/share/ghostscript/[0-9]*.[0.9]*/*\nStartup  files,  utilities,  and  basic  font  definitions (where [0-9]*.[0.9]* is the\nghostscript version)\n\n/usr/share/fonts/type1/gsfonts/*\nMore font definitions from the gsfonts package\n\n/usr/share/doc/ghostscript/examples/*\nGhostscript demonstration files (if ghostscript-doc package is installed)\n\n/usr/share/doc/ghostscript/*\nDiverse document files (may need to install ghostscript-doc package)\n",
            "subsections": []
        },
        "INITIALIZATION FILES": {
            "content": "When looking for the initialization files \"gs*.ps\", the files related to fonts, or the  file\nfor  the \"run\" operator, Ghostscript first tries to open the file with the name as given, us‐\ning the current working directory if no directory is specified.  If this fails, and the  file\nname  doesn't  specify  an  explicit directory or drive (for instance, doesn't contain \"/\" on\nUnix systems), Ghostscript tries directories in this order:\n\n1.  the directories specified by the -I switches in the command line (see below), if any;\n\n2.  the directories specified by the GSLIB environment variable, if any;\n\n3.  the directories specified by the GSLIBDEFAULT macro in the  Ghostscript  makefile  when\nthe  executable  was built.  GSLIBDEFAULT is \"/usr/share/ghostscript/[0-9]*.[0-9]*/lib\"\non a Debian system where \"[0-9]*.[0-9]*\" represents the Ghostscript version number\n\nEach of these (GSLIBDEFAULT, GSLIB, and -I parameter) may be either a single directory  or\na list of directories separated by \":\".\n",
            "subsections": []
        },
        "ENVIRONMENT": {
            "content": "GSOPTIONS\nString of options to be processed before the command line options\n\nGSDEVICE\nUsed to specify an output device\n\nGSFONTPATH\nPath names used to search for fonts\n\nGSLIB Path names for initialization files and fonts\n\nTEMP   Where temporary files are made\n",
            "subsections": []
        },
        "X RESOURCES": {
            "content": "Ghostscript, or more properly the X11 display device, looks for the following resources under\nthe program name \"Ghostscript\":\n",
            "subsections": [
                {
                    "name": "borderWidth",
                    "content": "The border width in pixels (default = 1).\n"
                },
                {
                    "name": "borderColor",
                    "content": "The name of the border color (default = black).\n"
                },
                {
                    "name": "geometry",
                    "content": "The window size and placement, WxH+X+Y (default is NULL).\n"
                },
                {
                    "name": "xResolution",
                    "content": "The number of x pixels per inch (default is computed from WidthOfScreen and WidthMMOf‐\nScreen).\n"
                },
                {
                    "name": "yResolution",
                    "content": "The  number of y pixels per inch (default is computed from HeightOfScreen and HeightM‐\nMOfScreen).\n"
                },
                {
                    "name": "useBackingPixmap",
                    "content": "Determines whether backing store is to be used for saving display  window  (default  =\ntrue).\n\nSee  the  usage  document  for  a more complete list of resources.  To set these resources on\nUnix, put them in a file such as \"~/.Xresources\" in the following form:\n\nGhostscript*geometry:     612x792-0+0\nGhostscript*xResolution: 72\nGhostscript*yResolution: 72\n\nThen merge these resources into the X server's resource database:\n\n% xrdb -merge ~/.Xresources\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "The various Ghostscript document files (above), especially Use.htm.  On Debian you  may  need\nto install ghostscript-doc before reading the documentation.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "See http://bugs.ghostscript.com/ and the Usenet news group comp.lang.postscript.\n",
            "subsections": []
        },
        "VERSION": {
            "content": "This document was last revised for Ghostscript version 10.02.1.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Artifex  Software,  Inc. are the primary maintainers of Ghostscript.  Russell J. Lang, gsview\nat ghostgum.com.au, is the author of most of the MS Windows code in Ghostscript.\n\n10.02.1                                   01 November 2023                                     GS(1)",
            "subsections": []
        }
    },
    "summary": "gs - Ghostscript (PostScript and PDF language interpreter and previewer)",
    "flags": [
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "Define a name in \"systemdict\" with the given definition. The token must be exactly one token (as defined by the \"token\" operator) and may contain no whitespace."
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "Define a name in \"systemdict\" with a given string as value. This is different from -d. For example, -dname=35 is equivalent to the program fragment /name 35 def whereas -sname=35 is equivalent to /name (35) def"
        },
        {
            "flag": "-P",
            "long": null,
            "arg": null,
            "description": "fault, Ghostscript no longer looks in the current directory, unless, of course, the first explicitly supplied directory is \".\" in -I. See also the INITIALIZATION FILES section below, and bundled Use.htm for detailed discussion on search paths and how Ghostcript finds files."
        },
        {
            "flag": "-q",
            "long": null,
            "arg": null,
            "description": "-dQUIET."
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "Equivalent to -dDEVICEWIDTH=number1 and -dDEVICEHEIGHT=number2. This is for the bene‐ fit of devices (such as X11 windows) that require (or allow) width and height to be specified."
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "Equivalent to -dDEVICEXRESOLUTION=number1 and -dDEVICEYRESOLUTION=number2. This is for the benefit of devices such as printers that support multiple X and Y resolutions. If only one number is given, it is used for both X and Y resolutions."
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "Adds the designated list of directories at the head of the search path for library files. - This is not really a switch, but indicates to Ghostscript that standard input is com‐ ing from a file or a pipe and not interactively from the command line. Ghostscript reads from standard input until it reaches end-of-file, executing it like any other file, and then continues with processing the command line. When the command line has been entirely processed, Ghostscript exits rather than going into its interactive mode. Note that the normal initialization file \"gsinit.ps\" makes \"systemdict\" read-only, so the values of names defined with -D, -d, -S, or -s cannot be changed (although, of course, they can be superseded by definitions in \"userdict\" or other dictionaries.)"
        }
    ],
    "examples": [],
    "see_also": [],
    "tldr": {
        "source": "official",
        "description": "GhostScript, a PDF and PostScript interpreter.",
        "examples": [
            {
                "description": "View a file",
                "command": "gs -dQUIET -dBATCH {{file.pdf}}"
            },
            {
                "description": "Reduce PDF file size to 150 dpi images for reading on an e-book device",
                "command": "gs -dNOPAUSE -dQUIET -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -sOutputFile={{output.pdf}} {{input.pdf}}"
            },
            {
                "description": "Convert PDF file (pages 1 through 3) to an image with 150 dpi resolution",
                "command": "gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=jpeg -r150 -dFirstPage=1 -dLastPage=3 -sOutputFile={{output_%d.jpg}} {{input.pdf}}"
            },
            {
                "description": "Extract pages from a PDF file",
                "command": "gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile={{output.pdf}} {{input.pdf}}"
            },
            {
                "description": "Merge PDF files",
                "command": "gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile={{output.pdf}} {{input1.pdf}} {{input2.pdf}}"
            },
            {
                "description": "Convert from PostScript file to PDF file",
                "command": "gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile={{output.pdf}} {{input.ps}}"
            }
        ]
    }
}