Skip to content
Related Articles
Get the best out of our app
Open App

Related Articles

gs command in Linux with Examples

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

gs command invokes Ghostscript, which is an interpreter of Adobe Systems PostScript and Portable Document Format(PDF) languages. After executing Ghostscript it reads further input from the standard input stream until it encounters ‘quit‘ command. 


gs [ options ] [ files ] ...

Options: Below are some important options of gs command.  

  • P : Makes Ghostscript to look first in the current directory for library files.
  • -q : Quiet startup: suppress normal startup messages, and also do the equivalent of -dQUIET.
  • -rnumber, -rnumber1xnumber2 : Same as -dDEVICEXRESOLUTION=number1 and -dDEVICEYRESOLUTION=number2.If only one number is given, it is used for both X and Y resolutions.
  • -dNOCACHE : Disables character caching. Useful only for debugging.
  • -dNOBIND : Disables the “bind” operator. Useful only for debugging.
  • -dNODISPLAY : Suppresses the normal initialization of the output device. This may be useful when debugging.
  • -dNOPAUSE : Disables the prompt and pause at the end. This may be desirable for applications where another program is driving Ghostscript.
  • -dSAFER : Restricts the file operations that job can perform.
  • -sDEVICE=device : Selects an alternate initial output device.
  • -sOutputFile=filename : Selects an alternate output file (or pipe) for the initial output device.


  1. PDF writer: The pdfwrite device outputs PDF.
  2. PS2 writer: The ps2write device outputs postscript language level 2. It is recommended that this device is used for PostScript output.
  3. EPS writer : The eps2write device outputs encapsulated postscript.
  4. PXL : The pxlmono and pxlcolor devices output HP PCL-XL, a graphic language understood by many laser printers.
  5. Text output : The txtwrite device will output the text contained in the document as Unicode.


  • To view a PDF
gs -dSAFER syllabus.pdf

  • To convert a figure into png
gs -dSAFER -dNOPAUSE -sDEVICE=png16m -dGraphicsAlphaBits=4 -sOutputFile=front.png a.pdf

See front.png created in the directory.

  • To convert image to 150 dpi : 
gs -dSAFER -dNOPAUSE -sDEVICE=png16m -r150 -sOutputFile=front_1.png c.pdf

You can observe the difference between the two images first one is 150 dpi and second is the original image.

  • To convert all pages to image : 

gs -dSAFER -dNOPAUSE -sDEVICE=pgmraw -r150 -dTextAlphaBits=4 -sOutputFile=’paper-%d.pgm’ a.pdf

  • To concatenate two PDFs : 

gs -dSAFER -dNOPAUSE -sDEVICE=pdfwrite -r150 -sOutputFile=concatenate.pdf a.pdf b.pdf c.pdf

After executing the above command it will concatenate all three PDFs a.pdf, b.pdf, c.pdf, and save it as concatenate.pdf


My Personal Notes arrow_drop_up
Last Updated : 11 Jan, 2022
Like Article
Save Article
Similar Reads
Related Tutorials