gs Command Examples in Linux

Ghostscript (gs) is a command-line interpreter for PostScript and PDF files. It is an open-source software developed by Aladdin Enterprises, now maintained by Artifex Software. Ghostscript can be used to convert PostScript and PDF files to other formats, such as raster images (JPEG, PNG, etc.) and to perform other operations on the files, such as adding watermarks, creating PDFs from multiple files, and more.

Ghostscript can be used to convert PostScript and PDF files to a wide variety of image formats, such as TIFF, JPEG, PNG, and more. For example, the following command can be used to convert a PDF file to a PNG image:

# gs -sDEVICE=png16m -dNOPAUSE -dBATCH -dSAFER -sOutputFile=output.png input.pdf

It can also be used to create a pdf from multiple files, for example:

# gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -sOutputFile=output.pdf input1.ps input2.ps

Ghostscript can also be used to perform other operations on PostScript and PDF files, such as adding watermarks, creating PDFs from multiple files, and more. Ghostscript is widely used by many applications, such as PDF viewers, printers and print servers, and more.

gs Command Examples

1. To view a file:

# gs -dQUIET -dBATCH file.pdf

2. Reduce PDF file size to 150 dpi images for reading on a e-book device:

# gs -dNOPAUSE -dQUIET -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -sOutputFile=output.pdf input.pdf

3. Convert PDF file (pages 1 through 3) to an image with 150 dpi resolution:

# gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=jpeg -r150 -dFirstPage=1 -dLastPage=3 -sOutputFile=output_%d.jpg input.pdf

4. Extract pages from a PDF file:

# gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=output.pdf input.pdf

5. Merge PDF files:

# gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=output.pdf input1.pdf input2.pdf

6. Convert from PostScript file to PDF file:

# gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=output.pdf input.ps
Related Post