Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

How can I split a PDF's pages down the middle?

Does anyone know of a good way to split a pdf's pages down the middle into two new pages?

To be clear, I'm not trying to split out already existing pages from a pdf; I am trying to create two new pages from an existing single page.

  • ghostscript

Oliver Salzburg's user avatar

  • Well MS Office is not a freeware, but if you have MS Office 2007, then you could just save documents as PDF files and do as you please... –  Owen Jan 19, 2011 at 6:49
  • See also –  Tobias Kienzler Dec 1, 2014 at 10:40
  • Possible duplicate of Convert PDF 2 sides per page to 1 side per page –  fixer1234 Feb 12, 2016 at 6:24
  • Same question on Unix&Linux SE: command line - Split pages in pdf - Unix & Linux Stack Exchange –  user202729 Nov 17, 2023 at 8:39

5 Answers 5


alt text

It lets you split each page into as many subpages as you want by defining regions with a GUI. It groups all similar pages into groups for you, so you can define regions for that group once.

It's cross-platform, free, and open-source.

frabjous's user avatar

  • It seems this increases file size (times "number of output pages per input page"), because it uses the original page content and a cropbox for each cropped page. If you need small file size, you can print the output file to PS and then convert to PDF, but you might lose quality then (for example, due to bitmap fonts). –  tanius Mar 17, 2015 at 13:44

You can solve this with the help of Ghostscript. pdftk alone cannot do that (to the best of my knowledge). I'll give you the commandline steps to do this manually. It will be easy to script this as a procedure, also with different parameters for page sizes and page numbers. But you said that you can do that yourself ;-)

How to solve this with the help of Ghostscript...

...and for the fun of it, I've recently done it not with an input file featuring "double-up" pages, but one with "treble-ups". You can read the answer for this case in this other response .

Your case is even simpler. You seem to have something similar to this:

You want to create 1 PDF with 4 pages, each of which has the size of 421 pt x 595 pt.

Let's first extract the left sections from each of the input pages:

What did these parameters do?

First, know that in PDF 1 inch == 72 points . Then the rest is:

  • -o ...............: Names output file. Implicitely also uses -dBATCH -dNOPAUSE -dSAFER .
  • -sDEVICE=pdfwrite : we want PDF as output format.
  • -g................: sets output media size in pixels. pdfwrite's default resolution is 720 dpi. Hence multiply by 10 to get a match for PageOffset.
  • -c "..............: asks Ghostscript to process the given PostScript code snippet just before the main input file (which needs to follow with -f ).
  • <</PageOffset ....: sets shifting of page image on the medium. (Of course, for left pages the shift by [0 0] has no real effect.)
  • -f ...............: process this input file.

Which result did the last command achieve?

Second Step

Next, the right sections:

Now we combine the pages into one file. We could do that with ghostscript as well, but we'll use pdftk instead, because it's faster for this job:

Done. Here is the desired result. 4 different pages, sized 421x595 pt.

Community's user avatar

  • 3 Pretty! You should really use this in every answer if you want to keep getting upvotes for free! –  Ivo Flipse Mar 1, 2011 at 22:29
  • 2 The second step only worked for me when I used a negative offset: "<</PageOffset [-421 0]>> setpagedevice" . I guess it depends on the orientation of the original file. Excellent answer nonetheless. :) –  moraes Mar 31, 2013 at 22:38
  • 1 To me the second step also worked with the minus sign –  Rafareino Aug 14, 2014 at 22:20
  • 1 It works perfectly fine but the PDF file size indicates that each page now contains the entire image from the double page it came from but half of it hidden outside the page boundary. That confuses my printer so some pages print as blank pages. Is the a way to crop everything outside the visible page somewhere in the process? –  mgd Dec 5, 2022 at 16:08
Thanks to @marttt and their answer in Unix & Linux .

You can use mutool (which comes as part of mupdf ):

You can also use -y if you want to perform a vertical split.

Peque's user avatar

  • This is a simple solution, thanks. Unfortunately, there is no way to shift the content on the page to adjust the margins - for that use the method described by Kurt Pfeifle. –  Ján Lalinský Mar 16, 2017 at 13:47
  • Segmentation fault –  nilon Apr 12, 2020 at 22:14
  • After installing the package mupdf , I had to install the package mupdf-tools to get mutool (in Ubuntu 18.04) –  Deleplace Dec 5, 2021 at 23:27

To expand upon @Kurt's answer (since I don't have enough reputation points to comment) first make sure the dimensions you use is not based on the Crop Box dimensions if they are different from the Media Box dimensions. The output size is based on Media Box dimensions, but the offset seems to use the Crop Box dimensions.

For a gatefold page that had a 20.0833 x 13.833 media box and a 19.25 x 13.0 crop box which was the same as the trim box in my document, to split it into two pages on Ubuntu, for the left side:

The right side:

And then stitched them with pdftk left.pdf right.pdf output final.pdf .

An alternative would be to set the crop box to the same as the media box; then the offset would be -723. But then the crop would have to be reset to trim in order for the pages to appear seamless. Otherwise, set media to crop.

motorbaby's user avatar

  • Note, after splitting the pages with these command options, the media boxes do not change. Only the crop changes. If you split one page into multiple pages, the new pages keep the media box dimensions from the old page. Need sed to modify the media box dimensions. Though don't know how to set media box to crop without including numbers in the command. –  motorbaby Jul 27, 2015 at 21:49
  • Oops. I mean the new pages keep the crop box dimensions from the old page. –  motorbaby Jul 28, 2015 at 19:08
  • Found a bug with Acrobat PDFs. Visually, cropBox dimensions can be seen in Set Page Boxes in Acrobat. But cropBox dimensions after using Ghostscript to divide the gatefold kept the old page dimensions on another level. This could be seen in Preflight Analyze info in Acrobat. After adjusting the crop in Acrobat on the right side of the left page temporarily to an arbitrary number and then returning it to 0, the other box dimensions (bleed, art, and trim) also adjusted. This fixed the problem where the cropBox data still showed the old page dimensions. The right page was a little different. –  motorbaby Jul 28, 2015 at 20:08

Krop (Python) & PDFscissors (Java) haven't been mentioned yet, check them out if you have f.e. pdfnup-ped lecture notes you want to reverse back into a proper presentation PDF..

eMPee584's user avatar

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged pdf ghostscript ..

  • The Overflow Blog
  • Letting algorithms guide our path to the next great invention
  • The half-life of developer skills is shrinking rapidly
  • Featured on Meta
  • Sites can now request to enable a banner to warn about their policy on...

Hot Network Questions

  • Can I remove the beeper from my older Bosch fridge?
  • Consecutive Composite Numbers
  • Where is there visible light inside the Sun?
  • What is the meaning or information given by the solar image at 4500Å?
  • In a grant proposal, should I write that I have a paper very likely to be accepted by a very prestigious journal? and how?
  • What are the laws and conventions governing an embassy building?
  • Would Starship be able to lift mass to orbit and beyond cheaper than a space elevator?
  • Why the development of mathematics was very slow between Ancient Greece and Descartes?
  • What could this OP_RETURN value be
  • Are morals and justice meaningless ? What do philosophers think about them?
  • Why is Integer Linear Programming in NP?
  • Benefits of classical ANOVA F compared to Welch's F?
  • Looking for the name of an animation technique (1930's–50's) which uses a rotating wheel to create a parallax effect
  • Quantizing Wave Vectors in 2D Electron Gas: Periodic vs Hard Wall Boundary Conditions?
  • How many people are awake?
  • Is it feasible to alter "well-established" languages?
  • how to uninstall older python3.6 from Ubuntu 22.04?
  • Alcohol duty free refused at Dubai
  • How did Iowa go from being a "blue" to "red" state?
  • Is it possible to disable symlinks when mounting a partition?
  • Authorship in work dedicated to the public domain
  • What causes these spikes in an LTspice circuit analysis of a full adder?
  • Supervisor does not want to contact reviewer after publication
  • Select twins from a list of triples

ghostscript pdf split

How to split/join pdf files


Ghostscript is a very useful tool in this situation.

  • Install ghostscript (the gs command line).
  • To extract pages from the 3rd page to the 5th page in in.pdf , write output to out.pdf

By default -dFirstPage is 1,   -dLastPage is the last page number.

  • To combine 2 pdf files in1.pdf in2.pdf , write output to out.pdf .
  • To resize a pdf size, use the -dPDFSETTINGS= argument ( reference ).

From the official manual ( reference ):

Controls and features specific to PostScript and PDF input


Presets the “distiller parameters” to one of the following predefined settings:

  • /screen selects low-resolution output similar to the Acrobat Distiller (up to version X) “Screen Optimized” setting.
  • /ebook selects medium-resolution output similar to the Acrobat Distiller (up to version X) “eBook” setting.
  • /printer selects output similar to the Acrobat Distiller “Print Optimized” (up to version X) setting.
  • /prepress selects output similar to Acrobat Distiller “Prepress Optimized” (up to version X) setting.
  • /default selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file.

Sign up for more like this.

Ghostscript documentation

How to use ghostscript, table of contents, invoking ghostscript, help at the command line: gs -h, selecting an output device, output resolution, output to files, one page per file, choosing paper size, changing the installed default paper size, interacting with pipes, using ghostscript with pdf files, switches for pdf files, problems interpreting a pdf file, pdf files from standard input, using ghostscript with eps files, using ghostscript with overprinting and spot colors, how ghostscript finds files, finding postscript level 2 resources, font lookup, cid font substitution, using unicode true type fonts, temporary files, notes on specific platforms, word size (32 or 64 bits), using x windows on vms, x resources, working around bugs in x servers, x device parameters, command line options, general switches, input control, file searching, setting parameters, suppress messages, parameter switches ( -d and -s ), rendering parameters, page parameters, font-related parameters, resource-related parameters, interaction-related parameters, device and output selection parameters, eps parameters, deferred page rendering, icc color parameters, other parameters, improving performance, summary of environment variables.

  • Debug Switches

Visual Trace

Appendix: paper sizes known to ghostscript, appendix: x default font mappings, standard x servers, regular fonts, symbol fonts, dingbat fonts, sun openwindows.

  • Appendix: Running Ghostscript with third-party font renderers

For other information, see the Ghostscript overview and, if necessary, how to install 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 is essentially the same on all systems, although the name of the executable program itself may differ among systems. For instance, to invoke Ghostscript 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-%00d.pgm'

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


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.

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 information
  • the general format of the command line
  • a few of the most useful options
  • the formats it can interpret
  • the available output devices
  • the search path
  • the bug report address

On other systems the executable may have a different name:

System Invocation Name Unix gs VMS gs MS Windows 95 and later gswin32.exe gswin32c.exe gswin64.exe gswin64c.exe OS/2 gsos2

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 ) lists the 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, and only its first use has any effect. For example, for printer output in a configuration that includes an Epson printer driver, instead of just 'gs' you might use

gs -sDEVICE=epson

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

Once you invoke Ghostscript you 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 ( run

All output then goes to the Epson printer instead of the display until you do something to change devices. You can switch devices at any time by using the selectdevice procedure, for instance like one of these:

(x11alpha) selectdevice (epson) selectdevice

Some printers can print at several different resolutions, letting you balance resolution against printing speed. To select the resolution on such 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.

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 , use


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 actually begins with % , you must prepend the %os% filedevice explicitly. For example to output to a file named %abc , you need to specify

gs -sOutputFile=%os%%abc

Please see Ghostscript and the PostScript Language and the PostScript Language Reference Manual for more details on % and filedevices.

Note that on MS Windows systems, the % character also has a special meaning for the command processor (shell), so you will have to double it.

gs -sOutputFile=%%os%%%%abc (on MS Windows)

Note, some devices (e.g. pdfwrite, ps2write, ...) only write the output file upon exit, but changing the OutputFile device parameter will cause these devices to emit the pages received up to that point and then open the new file name given by OutputFile.

For example, in order to create two PDF files from a single invocation of ghostscript the following can be used:

gs -sDEVICE=pdfwrite -o tiger.pdf examples/tiger.eps -c " > setpagedevice" -f examples/

Specifying a single output file works fine for printing and rasterizing figures, but sometimes you want images of each page of a multi-page document. You can tell Ghostscript to put each page of output in a series of similarly named files. To do this place a template ' %d ' in the filename which Ghostscript will replace with the page number.

Note: Since the % character is used to precede the page number format specification, in order to represent a file name that contains a % , double % characters must be used. For example for the file my%foo the OutputFile string needs to be my%%foo .

The format can in fact be more involved than a simple ' %d '. The format specifier is of a form similar to the C printf format. The general form supported is:

For more information, please refer to documentation on the C printf format specifications. Some examples are:

-sOutputFile=ABC-%d.png produces ' ABC-1.png ', ... , ' ABC-10.png ', .. -sOutputFile=ABC-%03d.pgm produces ' ABC-001.pgm ', ... , ' ABC-010.pgm ', ... -sOutputFile=ABC_p%04d.tiff produces ' ABC_p0001.tiff ', ... , ' ABC_p0510.tiff ', ... , ' ABC_p5238.tiff '

Note, however that the one page per file feature may not supported by all devices. Also, since some devices write output files when opened, there may be an extra blank page written (pdfwrite, ps2write, eps2write, pxlmono, pxlcolor, ...).

As noted above, when using MS Windows console ( or cmd.exe), you will have to double the % character since the % is used by that shell to prefix variables for substitution, e.g.,


As a convenient shorthand you can use the -o option followed by the output file specification as discussed above. The -o option also sets the -dBATCH and -dNOPAUSE options . This is intended to be a quick way to invoke ghostscript to convert one or more input files.

For instance, to convert to JPEG image files, one per page, use:

gs -sDEVICE=jpeg -o out-%d.jpg

is equivalent to:

gs -sDEVICE=jpeg -sOutputFile=out-%d.jpg -dBATCH -dNOPAUSE

Ghostscript is distributed configured to use U.S. letter paper as its default page size. There are two ways to select other paper sizes from the command line:


Where w be the desired paper width and h be the desired paper height in points (units of 1/72 of an inch).

Individual documents can (and often do) specify a paper size, which takes precedence over the default size. To force a specific paper size and ignore the paper size specified in the document, select a paper size as just described, and also include the -dFIXEDMEDIA switch on the command line.

The default set of paper sizes will be included in the currentpagedevice in the InputAttributes dictionary with each paper size as one of the entries. The last entry in the dictionary (which has numeric keys) is a non-standard (Ghostscript extension) type of PageSize where the array has four elements rather than the standard two elements. This four element array represents a page size range where the first two elements are the lower bound of the range and the second two are the upper bound. By default these are [0, 0] for the lower bound and [16#fffff, 16#fffff] for the upper bound.

The range type of PageSize is intended to allow flexible page size sepcification for non-printer file formats such as JPEG, PNG, TIFF, EPS, ...

For actual printers, either the entire InputAttributes dictionary should be replaced or the range type entry should not be included. To simplify using the default page sizes in the InputAttributes dictionary, the command line option -dNORANGEPAGESIZE can be used. Using this option will result in automatic rotation of the document page if the requested page size matches one of the default page sizes.

When the -dFIXEDMEDIA switch is given on the command line, the InputAttributes dictionary will only be populated with the single page size. This allows the -dPSFitPage option to fit the page size requested in a PostScript file to be rotated, scaled and centered for the best fit on the specified page.

You can change the installed default paper size on an installed version of Ghostscript, by editing the initialization file . This file is usually in the Resource/Init directory somewhere in the search path. See the section on finding files for details.

Find the line


Then to make A4 the default paper size, uncomment the line to change this to


For a4 you can substitute any paper size Ghostscript knows .

This supecedes the previous method of uncommenting the line % (a4) ... .

Sometimes the initialization files are compiled into Ghostscript and cannot be changed.

On Windows and some Linux builds, the default paper size will be selected to be a4 or letter depending on the locale.

As noted above, input files are normally specified on the command line. However, one can also "pipe" input into Ghostscript from another program by using the special file name ' - ' which is interpreted as standard input. Examples:

{ some program producing ps } | gs [options] - zcat | gs -

When Ghostscript finishes reading from the pipe, it quits rather than going into interactive mode. Because of this, options and files after the ' - ' in the command line will be ignored.

On Unix and MS Windows systems you can send output to a pipe in the same way. For example, to pipe the output to lpr , use the command

gs -q -sOutputFile=- | lpr

In this case you must also use the -q switch to prevent Ghostscript from writing messages to standard output which become mixed with the intended output stream.

Also, using the -sstdout=%stderr option is useful, particularly with input from PostScript files that may print to stdout.

Similar results can be obtained with the %stdout and %pipe% filedevices. The example above would become

gs -sOutputFile=%stdout -q | lpr
gs -sOutputFile=%pipe% lpr

(again, doubling the % character on MS Windows systems.)

In the last case, -q isn't necessary since Ghostscript handles the pipe itself and messages sent to stdout will be printed as normal.

Ghostscript is normally built to interpret both PostScript and PDF files, examining each file to determine automatically whether its contents are PDF or PostScript. All the normal switches and procedures for interpreting PostScript files also apply to PDF files, with a few exceptions. In addition, the pdf2ps utility uses Ghostscript to convert PDF to (Level 2) PostScript.

Here are some command line options specific to PDF

At present the old PostScript-based interpreter remains the default, in future releases the new C-based interpreter will become the default, though we would encourage people to experiment with the new interpreter and send us feedback. While there are two interpreters the command-line switch NEWPDF will allow selection of the existing interpreter when false and the new interpreter when true.

This is useful for creating fixed size images of PDF files that may have a variety of page sizes, for example thumbnail images.

This option is also set by the -dFitPage option.

In addition, finer control is available by defining an array /ShowAnnotTypes . Annotation types listed in this array will be drawn, whilst those not listed will not be drawn.

To use this feature: -c "/ShowAnnotTypes [....] def" -f <input file> Where the array can contain one or more of the following names: /Stamp , /Squiggly , /Underline , /Link , /Text , /Highlight , /Ink , /FreeText , /StrikeOut and /stamp_dict .

For example, adding the follow to the command line: -c "/ShowAnnotTypes [/Text /UnderLine] def" -f <input file> would draw only annotations with the subtypes "Text" and "UnderLine"

These command line options are no longer specific to PDF, but have some specific differences with PDF files

-sPageList=1,3,5 indicates that pages 1, 3 and 5 should be processed. -sPageList=5-10 indicates that pages 5, 6, 7, 8, 9 and 10 should be processed. -sPageList=1,5-10,12- indicates that pages 1, 5, 6, 7, 8, 9, 10 and 12 onwards should be processed.

The PDF interpreter and the other language interpreters handle these in slightly different ways. Because PDF files enable random access to pages in the document the PDF inerpreter only interprets and renders the required pages. PCL and PostScript cannot be handled in ths way, and so all the pages must be interpreted. However only the requested pages are rendered, which can still lead to savings in time. Be aware that using the '%d' syntax for OutputFile does not reflect the page number in the original document. If you chose (for example) to process even pages by using -sPageList=even , then the output of -sOutputFile=out%d.png would still be out0.png, out1.png, out2.png etc......

Because the PostScript and PCL interpreters cannot determine when a document terminates, sending multple files as input on the command line does not reset the PageList between each document, each page in the second and subsequent documents is treated as following on directly from the last page in the first document. The PDF interpreter, however, does not work this way. Since it knows about individual PDF files the PageList is applied to each PDF file separately. So if you were to set -sPageList=1,2 and then send two PDF files, the result would be pages 1 and 2 from the first file, and then pages 1 and 2 from the second file. The PostScript interpreter, by contrast, would only render pages 1 and 2 from the first file. This means you must exercise caution when using this switch, and probably should not use it at all when processing a mixture of PostScript and PDF files on the same command line.

-sPageList=1,2,1,2 indicates repeated pages. Pages processed in order 1, 2, 1, 2. -sPageList=10-5 indicates pages will be processed in the order 10, 9, 8, 7, 6, 5. -sPageList=1-,-1 indicates first processing from page 1 to end and then from end to page 1.

Occasionally you may try to read or print a 'PDF' file that Ghostscript doesn't recognize as PDF, even though the same file can be opened and interpreted by an Adobe Acrobat viewer. In many cases, this is because of incorrectly generated PDF. Acrobat tends to be very forgiving of invalid PDF files. Ghostscript tends to expect files to conform to the standard. For example, even though valid PDF files must begin with %PDF , Acrobat will scan the first 1000 bytes or so for this string, and ignore any preceding garbage.

In the past, Ghostscript's policy has been to simply fail with an error message when confronted with these files. This policy has, no doubt, encouraged PDF generators to be more careful. However, we now recognize that this behavior is not very friendly for people who just want to use Ghostscript to view or print PDF files. Our new policy is to try to render broken PDF's, and also to print a warning, so that Ghostscript is still useful as a sanity-check for invalid files.

The PDF language, unlike the PostScript language, inherently requires random access to the file. If you provide PDF to standard input using the special filename ' - ' , Ghostscript will copy it to a temporary file before interpreting the PDF.

Encapsulated PostScript (EPS) files are intended to be incorporated in other PostScript documents and may not display or print on their own. An EPS file must conform to the Document Structuring Conventions, must include a %%BoundingBox line to indicate the rectangle in which it will draw, must not use PostScript commands which will interfere with the document importing the EPS, and can have either zero pages or one page. Ghostscript has support for handling EPS files, but requires that the %%BoundingBox be in the header, not the trailer. To customize EPS handling, see EPS parameters .

For the official description of the EPS file format, please refer to the Adobe documentation in their tech note #5002. It is available from:

In general with PostScript and PDF interpreters, the handling of overprinting and spot colors depends upon the process color model of the output device . Devices that produce gray or RGB output have an additive process color model. Devices which produce CMYK output have a subtractive process color model. Devices may, or may not, have support for spot colors.

Note: The differences in appearance of files with overprinting and spot colors caused by the differences in the color model of the output device are part of the PostScript and PDF specifications. They are not due to a limitation in the implementation of Ghostscript or its output devices.

With devices which use a subtractive process color model, both PostScript and PDF allow the drawing of objects using colorants (inks) for one or more planes without affecting the data for the remaining colorants. Thus the inks for one object may overprint the inks for another object. In some cases this produces a transparency like effect. (The effects of overprinting should not be confused with the PDF 1.4 blending operations which are supported for all output devices.) Overprinting is not allowed for devices with an additive process color model. With files that use overprinting, the appearance of the resulting image can differ between devices which produce RGB output versus devices which produce CMYK output. Ghostscript automatically overprints (if needed) when the output device uses a subtractive process color model. For example, if the file is using overprinting, differences can be seen in the appearance of the output from the tiff24nc and tiff32nc devices which use an RGB and a CMYK process color models.

Most of the Ghostscript output devices do not have file formats which support spot colors. Instead spot colors are converted using the tint transform function contained within the color space definition.. However there are several devices which have support for spot colors. The PSD format (Adobe Photoshop) produced by the psdcmyk device contains both the raster data plus an equivalent CMYK color for each spot color. This allows Photoshop to simulate the appearance of the spot colors. The display device (MS Windows, OS/2, gtk+) can be used with different color models: Gray, RGB, CMYK only, or CMYK plus spot colors (separation). The display device, when using its CMYK plus spot color (separation) mode, also uses an equivalent CMYK color to simulate the appearance of the spot color. The tiffsep device creates output files for each separation (CMYK and any spot colors present). It also creates a composite CMYK file using an equivalent CMYK color to simulate the appearance of spot colors. The xcfcmyk device creates output files with spot colors placed in separate alpha channels. (The XCF file format does not currently directly support spot colors.)

Overprinting with spot colors is not allowed if the tint transform function is being used to convert spot colors. Thus if spot colors are used with overprinting, then the appearance of the result can differ between output devices. One result would be obtained with a CMYK only device and another would be obtained with a CMYK plus spot color device. In a worst case situation where a file has overprinting with both process (CMYK) and spot colors, it is possible to get three different appearances for the same input file using the tiff24nc (RGB), tiff32nc (CMYK), and tiffsep (CMYK plus spot colors) devices.

In Adobe Acrobat, viewing of the effects of overprinting is enabled by the 'Overprint Preview' item in the 'Advanced' menu. This feature is not available in the free Acrobat Reader. The free Acrobat Reader also uses the tint transform functions to convert spot colors to the appropriate alternate color space.

When looking for initialization files ( gs_*.ps , pdf_*.ps ), font files, the Fontmap file, files named on the command line, and resource files, Ghostscript first tests whether the file name specifies an absolute path.

Testing a file name for an absolute path System Does the name ... Unix Begin with / ? MS Windows Have : as its second character, or begin with / , \ , or //servername/share/ ? VMS Contain a node, device, or root specification?

If the test succeeds, Ghostscript tries to open the file using the name given. Otherwise it tries directories in this order:

  • The current directory if enabled by the -P switch ;
  • The directories specified by -I switches in the command line, if any;
  • The directories specified by the GS_LIB environment variable, if any;
  • If built with COMPILE_INITS=1 (currently the default build) the files in the %rom%Resource/ and %rom%iccprofiles/ directories are built into the executable.
  • The directories specified by the GS_LIB_DEFAULT macro (if any) in the makefile when this executable was built.

GS_LIB_DEFAULT , GS_LIB , and the -I parameter may specify either a single directory or a list of directories separated by a character appropriate for the operating system (" : " on Unix systems, " , " on VMS systems, and " ; " on MS Windows systems). By default, Ghostscript no longer searches the current directory first but provides -P switch for a degree of backward compatibility.

Note that Ghostscript does not use this file searching algorithm for the run or file operators: for these operators, it simply opens the file with the name given. To run a file using the searching algorithm, use runlibfile instead of run .

Adobe specifies that resources are installed in a single directory. Ghostscript instead maintains a list of resource directories, and uses an extended method for finding resource files.

The search for a resource file depends on whether the value of the system parameter GenericResourceDir specifies an absolute path. The user may set it as explained in Resource-related parameters .

If the user doesn't set the system parameter GenericResourceDir , or use the -sGenericResourceDir= command line option, Ghostscript creates a default value for it by looking on the directory paths explained in How Ghostscript finds files , excluding the current directory. The first path with Resource in it is used, including any prefix up to the path separator character following the string Resource . For example, when COMPILE_INITS=1 (the current default build), if the first path is %rom%Resource/Init/ , then the GenericResourceDir systemparam will be set to %rom%Resource/ by default.

If the value of the system parameter GenericResourceDir is an absolute path (the default), Ghostscript assumes a single resource directory. It concatenates :

  • The value of the system parameter GenericResourceDir ;
  • The name of the resource category (for instance, CMap );
  • The name of the resource instance (for instance, Identity-H ).

If the value of the system parameter GenericResourceDir is not an absolute path, Ghostscript assumes multiple resource directories. In this case it concatenates :

  • A directory listed in the section How Ghostscript finds files , except the current directory;
  • The name of the resource instance (for instance, Identity-H )

Due to possible variety of the part 1, the first successful combination is used. For example, if the value of the system parameter GenericResourceDir is the string ../Resource/ (or its equivalent in the file path syntax of the underlying platform), Ghostscript searches for ../Resource/CMap/Identity-H from all directories listed in How Ghostscript finds files . So in this example, if the user on a Windows platform specifies the command line option -I.;../gs/lib;c:/gs8.50/lib , Ghostscript searches for ../gs/Resource/CMap/Identity-H and then for c:/gs8.50/Resource/CMap/Identity-H .

To get a proper platform dependent syntax Ghostscript inserts the value of the system parameter GenericResourcePathSep (initially " / " on Unix and Windows, " : " on MacOS, " . " or " ] " on OpenVMS). The string ../Resource is replaced with a platform dependent equivalent.

In the case of multiple resource directories, the default ResourceFileName procedure retrieves either a path to the first avaliable resource, or if the resource is not available it returns a path starting with GenericResourceDir . Consequently Postscript installers of Postscript resources will overwrite an existing resource or add a new one to the first resource directory.

To look up fonts, after exhausting the search method described in the next section , it concatenates together

  • the value of the system parameter FontResourceDir (initially /Resource/Font/ )
  • the name of the resource font (for instance, Times-Roman )

Note that even although the system parameters are named "somethingDir", they are not just plain directory names: they have " / " on the end, so that they can be concatenated with the category name or font name.

Ghostscript has a slightly different way to find the file containing a font with a given name. This rule uses not only the search path defined by -I , GS_LIB , and GS_LIB_DEFAULT as described above , but also the directory that is the value of the FontResourceDir system parameter, and an additional list of directories that is the value of the GS_FONTPATH environment variable (or the value provided with the -sFONTPATH= switch, if present).

At startup time, Ghostscript reads in the Fontmap files in every directory on the search path (or in the list provided with the -sFONTMAP= switch, if present): these files are catalogs of fonts and the files that contain them. (See the documentation of fonts for details.) Then, when Ghostscript needs to find a font that isn't already loaded into memory, it goes through a series of steps.

  • First, it looks up the font name in the combined Fontmaps. If there is an entry for the desired font name, and the file named in the entry can be found in some directory on the general search path (defined by -I , GS_LIB , and GS_LIB_DEFAULT ), and the file is loaded successfully, and loading it defines a font of the desired name, that is the end of the process.
  • If this process fails at any step, Ghostscript looks for a file whose name is the concatenation of the value of the FontResourceDir system parameter and the font name, with no extension. If such a file exists, can be loaded, and defines a font of the desired name, that again is the end. The value of FontResourceDir is normally the string /Resource/Font/ , but it can be changed with the setsystemparams operator: see the PostScript Language Reference Manual for details.
  • If that fails, Ghostscript then looks for a file on the general search path whose name is the desired font name, with no extension. If such a file exists, can be loaded, and defines a font of the desired name, that again is the end.
  • If that too fails, Ghostscript looks at the GS_FONTPATH environment variable (or the value provided with the -sFONTPATH= switch, if present), which is also a list of directories. It goes to the first directory on the list, and it's descendants, looking for all files that appear to contain PostScript fonts (also Truetype fonts); it then adds all those files and fonts to the combined Fontmaps, and starts over.
  • If scanning the first FONTPATH directory doesn't produce a file that provides the desired font, it adds the next directory on the FONTPATH list, and so on until either the font is defined successfully or the list is exhausted.
  • Finally, if all else fails, it will try to find a substitute for the font from among the standard 35 fonts.

CID fonts (e.g. Chinese, Japanese and Korean) are found using a different method.

Differences between search path and font path Search path Font path -I switch -sFONTPATH= switch GS_LIB and GS_LIB_DEFAULT environment variables GS_FONTPATH environment variable Consulted first Consulted only if search path and FontResourceDir don't provide the file. Font-name-to-file-name mapping given in Fontmap files; aliases are possible, and there need not be any relation between the font name in the Fontmap and the FontName in the file. Font-name-to-file-name mapping is implicit – the FontName in the file is used. Aliases are not possible. Only fonts and files named in Fontmap are used. Every Type 1 font file in each directory is available; if TrueType fonts are supported (the feature was included when the executable was built), they are also available.

If you are using one of the following types of computer, you may wish to set the environment variable GS_FONTPATH to the value indicated so that Ghostscript will automatically acquire all the installed Type 1 (and, if supported, TrueType) fonts (but see below for notes on systems marked with "*"):

Suggested GS_FONTPATH for different systems   System type GS_FONTPATH   Digital Unix /usr/lib/X11/fonts/Type1Adobe   Ultrix /usr/lib/DPS/outline/decwin   HP-UX 9 /usr/lib/X11/fonts/   IBM AIX /usr/lpp/DPS/fonts/outlines /usr/lpp/X11/lib/X11/fonts/Type1 /usr/lpp/X11/lib/X11/fonts/Type1/DPS   NeXT /NextLibrary/Fonts/outline * SGI IRIX /usr/lib/DPS/outline/base /usr/lib/X11/fonts/Type1   SunOS 4.x (NeWSprint only) newsprint_2.5/SUNWsteNP/reloc/$BASEDIR/NeWSprint/     small_openwin/lib/fonts ** SunOS 4.x /usr/openwin/lib/X11/fonts/Type1/outline ** Solaris 2.x /usr/openwin/lib/X11/fonts/Type1/outline   VMS SYS$COMMON:[SYSFONT.XDPS.OUTLINE] * On SGI IRIX systems, you must use Fontmap.SGI in place of Fontmap or Fontmap.GS , because otherwise the entries in Fontmap will take precedence over the fonts in the FONTPATH directories. ** On Solaris systems simply setting GS_FONTPATH or using -sFONTPATH= may not work, because for some reason some versions of Ghostscript can't seem to find any of the Type1 fonts in /usr/openwin/lib/X11/fonts/Type1/outline . (It says: "15 files, 15 scanned, 0 new fonts". We think this problem has been fixed in Ghostscript version 6.0, but we aren't sure because we've never been able to reproduce it.) See Fontmap.Sol instead. Also, on Solaris 2.x it's probably not worth your while to add Sun's fonts to your font path and Fontmap. The fonts Sun distributes on Solaris 2.x in the directories /usr/openwin/lib/X11/fonts/Type1 /usr/openwin/lib/X11/fonts/Type1/outline

are already represented among the ones distributed as part of Ghostscript; and on some test files, Sun's fonts have been shown to cause incorrect displays with Ghostscript.

These paths may not be exactly right for your installation; if the indicated directory doesn't contain files whose names are familiar font names like Courier and Helvetica, you may wish to ask your system administrator where to find these fonts.

Adobe Acrobat comes with a set of fourteen Type 1 fonts, on Unix typically in a directory called ... /Acrobat3/Fonts . There is no particular reason to use these instead of the corresponding fonts in the Ghostscript distribution (which are of just as good quality), except to save about a megabyte of disk space, but the installation documentation explains how to do it on Unix .

CID fonts are PostScript resources containing a large number of glyphs (e.g. glyphs for Far East languages, Chinese, Japanese and Korean). Please refer to the PostScript Language Reference, third edition, for details.

CID font resources are a different kind of PostScript resource from fonts. In particular, they cannot be used as regular fonts. CID font resources must first be combined with a CMap resource, which defines specific codes for glyphs, before it can be used as a font. This allows the reuse of a collection of glyphs with different encodings.

/CIDFont-CMap findfont

CID fonts must be placed in the /Resource/CIDFont/ directory. They are not found using Font lookup on the search path or font path.

Automatic CIDFont Substitution

In general, it is highly recommended that CIDFonts used in the creation of PDF jobs should be embedded or available to Ghostscript as CIDFont resources, this ensures that the character set, and typeface style are as intended by the author.

In cases where the original CIDFont is not available, the next best option is to provide Ghostscript with a mapping to a suitable alternative CIDFont - see below for details on how this is achieved. However, Ghostscript does provide the ability to use a "fall back" CIDFont substitute. As shipped, this uses the DroidSansFallback.ttf font. This font contains a large number of glyphs covering several languages, but it is not comprehensive. There is, therefore, a chance that glyphs may be wrong, or missing in the output when this fallback is used.

Internally, the font is referenced as CIDFont resource called CIDFallBack , thus a different fallback from DroidSansFallback.ttf can be specified adding a mapping to your cidfmap file (see below for details) to map the name "CIDFallBack" as you prefer. For CIDFallBack the mapping must be a TrueType font or TrueType collection, it cannot be a Postscript CIDFont file.

As with any font containing large numbers of glyphs, DroidSansFallback.ttf is quite large (~3.5Mb at the of writing). If this is space you cannot afford in your use of Ghostscript, you can simply delete the file from: Resource/CIDFSubst/DroidSansFallback.ttf . The build system will cope with the file being removed, and the initialization code will avoid adding the internal fall back mapping if the file is missing.

If DroidSansFallback.ttf is removed, and no other CIDFallBack mapping is supplied, the final "fall back" is to use a "dumb" bullet CIDFont, called ArtifexBullet . As the name suggests, this will result in all the glyphs from a missing CIDFont being replaced with a simple bullet point.

This type of generic fall back CIDFont substitution can be very useful for viewing and proofing jobs, but may not be appropriate for a "production" workflow, where it is expected that only the original font should be used. For this situation, you can supply Ghostscript with the command line option: -dPDFNOCIDFALLBACK . By combining -dPDFNOCIDFALLBACK with -dPDFSTOPONERROR a production workflow can force a PDF with missing CIDFonts to error, and avoid realising a CIDFont was missing only after printing.

The directory in which the fallback TrueType font or collection can be specified by the command line parameter -sCIDFSubstPath="path/to/TTF" , or with the environment variable CIDFSUBSTPATH . The file name of the substitute TrueType font can be specified using the command line parameter -sCIDFSubstFont="TTF file name" or the environment variable CIDFSUBSTFONT .

Explicit CIDFont Substitution

Substitution of CID font resources is controlled, by default, by the Ghostscript configuration file Resource/Init/cidfmap , which defines a CID font resource map.

The file forms a table of records, each of which should use one of three formats, explained below. Users may modify Resource/Init/cidfmap to configure Ghostscript for a specific need. Note that the default Ghostscript build includes such configuration and resource files in a rom file system built into the executable. So, to ensure your changes have an effect, you should do one of the following: rebuild the executable; use the "-I" command line option to add the directory containing your modified file to Ghostscript's search path; or, finally, build Ghostscript to use disk based resources.

To substitute a CID font resource with another CID font resource, add a record like this :

/Substituted /Original ;

where Substituted is a name of CID font resource being used by a document, and Original is a name of an available CID font resource. Please pay attention that both them must be designed for same character collection. In other words, you cannot substitute a Japanese CID font resource with a Korean CID font resource, etc. CMap resource names must not appear in lib/cidfmap . The trailing semicolon and the space before it are both required.

To substitute (emulate) a CID font resource with a TrueType font file, add a record like this :

/Substituted << keys&values >> ;

Where keys&values are explained in the table below.

Currently only CIDFontType 2 can be emulated with a TrueType font. The TrueType font must contain enough characters to cover an Adobe character collection, which is specified in Ordering and used in documents.

To point Ghostscript at a specific CIDFont file outside it's "normal" resource search path :

/CIDName (path/to/cid/font/file) ;

where CIDName is a name of CID font resource being used by a document, and "path/to/cid/font/file" is the path to the Postscript CIDFont file, including the file name. NOTE: the CIDFont file, when executed by the Postscript interpreter, must result in a CIDFont resource being defined whose CIDFontName matches the "CIDName" key for the current record. I.E. an entry with the key /PingHei-Bold must reference a file which creates a CIDFont resource called "PingHei-Bold". To substitute a file based CIDFont for a differently named CIDFont, use formats 1 and 3 in combination (the order of the entries is not important).

The trailing semicolon and the space before it are both required.

Format 1: /Ryumin-Medium /ShinGo-Bold ; /Ryumin-Light /MS-Mincho ; Format 2: /Batang << /FileType /TrueType /Path (C:/WINDOWS/fonts/batang.ttc) /SubfontID 0 /CSI [(Korea1) 3] >> ; /Gulim << /FileType /TrueType /Path (C:/WINDOWS/fonts/gulim.ttc) /SubfontID 0 /CSI [(Korea1) 3] >> ; /Dotum << /FileType /TrueType /Path (C:/WINDOWS/fonts/gulim.ttc) /SubfontID 2 /CSI [(Korea1) 3] >> ; Format 1 & 2 /SimSun << /FileType /TrueType /Path (C:/WINDOWS/fonts/simsun.ttc) /SubfontID 0 /CSI [(GB1) 2] >> ; /SimHei << /FileType /TrueType /Path (C:/WINDOWS/fonts/simhei.ttf) /SubfontID 0 /CSI [(GB1) 2] >> ; /STSong-Light /SimSun ; /STHeiti-Regular /SimHei ; Format 3: /PMingLiU (/usr/local/share/font/cidfont/PMingLiU.cid) ; Format 1 & 3 /Ryumin-Light /PMingLiU ; /PMingLiU (/usr/local/share/font/cidfont/PMingLiU.cid) ;

The win32 installer of recent version of ghostscript has a checkbox for "Use Windows TrueType fonts for Chinese, Japanese and Korean" to optionally update lib/cidfmap with the common CJK fonts provided by Microsoft products. The script can also be run separately (e.g. against a network drive with windows CJK fonts):

gswin32c -q -dBATCH -sFONTDIR=c:/windows/fonts -sCIDFMAP=lib/cidfmap lib/

Note that the font file path uses Postscript syntax. Because of this, backslashes in the paths must be represented as a double backslash.

This can complicate substitutions for fonts with non-Roman names. For example, if a PDF file asks for a font with the name /#82l#82r#83S#83V#83b#83N . This cannot be used directly in a cidfmap file because the #xx notation in names is a PDF-only encoding. Instead, try something like:

<82C68272835383568362834E>cvn << /Path (C:/WINDOWS/Fonts/msmincho.ttc) /FileType /TrueType /SubfontID 0 /CSI [(Japan1) 3] >> ;

Where <82C68272835383568362834E> is the same byte sequence converted to a hex string. This lets you specify a name using any sequence of bytes through the encodings available for Postscript strings.

Note that loading truetype fonts directly from /Resources/CIDFont is no longer supported. There is no reliable way to generate a character ordering for truetype fonts. The 7.0x versions of Ghostscript supported this by assuming a Japanese character ordering. This is replaced in the 8.0x and later releases with the more general cidfmap mechanism.

/CIDSystemInfo << /Registry (Adobe) /Ordering (CNS1) /Supplement 1 >>
/Registry (Adobe) /Ordering (Identity)

Consequently, if you want to handle any PDF document with non-embedded CID fonts (which isn't a correct PDF), you need to create a suitable lib/cidfmap by hand, possibly a specific one for each document.

Ghostscript can make use of Truetype fonts with a Unicode character set. To do so, you should generate a ( NOTE: non-standard!) Postscript or PDF job where the relevant text is encoded as UTF-16. Ghostscript may be used for converting such jobs to other formats (Postscript, PDF, PXL etc). The resulting output will be compliant with the spec (unlike the input).

To render an UTF-16 encoded text, one must do the following :

  • Provide a True Type font with Unicode Encoding. It must have a cmap table with platformID equals to 3 (Windows), and SpecificID eqials to 1 (Unicode).
  • Describe the font in Resource/Init/cidfmap with special values for the CSI key : [(Artifex) (Unicode) 0] .
  • In the PS or PDF job combine the font with one of CMap Identity-UTF16-H (for the horizontal writing mode) or Identity-UTF16-V (for the vertical writing mode). Those CMaps are distributed with Ghostscript in Resource/CMap .

Please note that /Registry (Adobe) /Ordering (Identity) won't properly work for Unicode documents, especially for the searchability feature (see CID font substitution ).

Where Ghostscript puts temporary files Platform Filename Location MS Windows and OpenVMS _temp_ XX.XXX Current directory OS/2 gs XXXXXX Current directory Unix gs_ XXXXX /tmp

You can change in which directory Ghostscript creates temporary files by setting the TMPDIR or TEMP environment variable to the name of the directory you want used. Ghostscript currently doesn't do a very good job of deleting temporary files if it exits because of an error; you may have to delete them manually from time to time.

The original PostScript language specification, while not stating a specific word sise, defines 'typical' limits which make it clear that it was intended to run as a 32-bit environment. Ghostscript was originally coded that way, and the heritage remains within the code base.

Because the Ghostscript PDF interpreter is currently written in PostScript, it proved necessary to add support for 64-bit integers so that we could process PDF files which exceed 2GB in size. This is the only real purpose in adding support for large integers, however since that time, we have made some efforts to allow for the use of 64-bit words; in particular the use of integers, but also lifting the 64K limit on strings and arrays, among other areas.

Even when the build supports 64-bit words, you should be aware that there are areas of Ghostscript which do not support 64-bit values. Sometimes these are dependent on the build and other times they are inherent in the architecture of Ghostscript (the graphics library does not support 64-bit co-ordinates in device space for example, and most likely never will).

Note that the extended support for 64-bit word size can be disabled by executing 'true .setcpsimode', This is important for checking the output of the Quality Logic test suite (and possibly other test suites) as the tests make assumptions about the sizes of integers (amongst other things). You can run /ghostpdl/Resource/Init/ to change Ghostscript's behaviour so that it matches the observed behaviour of Adobe CPSI interpreters.

The Ghostscript distribution includes some Unix shell scripts to use with Ghostscript in different environments. These are all user-contributed code, so if you have questions, please contact the user identified in the file, not Artifex Software.

  • To be able to specify switches and file names when invoking the interpreter, define gs as a foreign command:
$ gs == "$ disk :[ directory ]gs.exe "

where the " disk " and " directory " specify where the Ghostscript executable is located. For instance,

$ gs == "$dua1:[ghostscript]gs.exe"
  • On VMS systems, the last character of each "directory" name indicates what sort of entity the "directory" refers to. If the "directory" name ends with a colon " : ", it is taken to refer to a logical device, for instance
$ define ghostscript_device dua1:[ghostscript_510] $ define gs_lib ghostscript_device:

If the "directory" name ends with a closing square bracket " ] ", it is taken to refer to a real directory, for instance

$ define gs_lib dua1:[ghostscript]
  • Defining the logical GS_LIB
$ define gs_lib disk :[ directory ]

allows Ghostscript to find its initialization files in the Ghostscript directory even if that's not where the executable resides.

  • Although VMS DCL itself converts unquoted parameters to upper case, C programs such as Ghostscript receive their parameters through the C runtime library, which forces all unquoted command-line parameters to lower case. That is, with the command
$ gs -Isys$login:

Ghostscript sees the switch as -isys$login , which doesn't work. To preserve the case of switches, quote them like this:

$ gs "-Isys$login:"
  • If you write printer output to a file with -sOutputFile= and then want to print the file later, use " PRINT/PASSALL ".
  • PDF files (or PostScript files that use the setfileposition operator) must be "stream LF" type files to work properly on VMS systems. ( Note: This definitely matters if Ghostscript was compiled with DEC C; we are not sure of the situation if you use gcc .) Because of this, if you transfer files by FTP, you probably need to do one of these two things after the transfer:
  • If the FTP transfer was in text (ASCII) mode:
$ convert/fdl=streamlf.fdl input-file output-file

where the contents of the file STREAMLF.FDL are

  • If the FTP transfer was in binary mode:
$ set file/attribute=(rfm:stmlf)

If you are using on an X Windows display, you can set it up with the node name and network transport, for instance

$ set display/create/node=""/transport=tcpip

and then run Ghostscript by typing gs at the command line.

The name of the Ghostscript command line executable on MS Windows is gswin32c / gswin64c so use this instead of the plain ' gs ' in the quickstart examples.

To run the batch files in the ghostscript lib directory, you must add gs\ bin and gs\ lib to the PATH , where gs is the top-level Ghostscript directory.

When passing options to ghostcript through a batch file wrapper such as ps2pdf.bat you need to substitute '#' for '=' as the separator between options and their arguments. For example:

ps2pdf -sPAPERSIZE#a4 file.pdf

Ghostscript treats '#' the same internally, and the '=' is mangled by the command shell.

There is also an older version for MS Windows called just gswin32 that provides its own window for the interactive postscript prompt. The executable gswin32c / gswin64c is usually the better option since it uses the native command prompt window.

For printer devices, the default output is the default printer. This can be modified as follows.

-sOutputFile="%printer%printer name" Output to the named printer. If your printer is named "HP DeskJet 500" then you would use -sOutputFile="%printer%HP DeskJet 500" .

Note: Ghostscript is no longer supported on MS-DOS.

Invoking Ghostscript from the command prompt in Windows is supported by the Windows executable described above.

Ghostscript looks for the following resources under the program name ghostscript and class name Ghostscript ; the ones marked "**" are calculated from display metrics:

X Windows resources Name Class Default background Background white foreground Foreground black borderColor BorderColor black borderWidth BorderWidth 1 geometry Geometry NULL xResolution Resolution ** yResolution Resolution ** useExternalFonts UseExternalFonts true useScalableFonts UseScalableFonts true logExternalFonts LogExternalFonts false externalFontTolerance ExternalFontTolerance 10.0 palette Palette Color maxGrayRamp MaxGrayRamp 128 maxRGBRamp MaxRGBRamp 5 maxDynamicColors MaxDynamicColors 256 useBackingPixmap UseBackingPixmap true useXPutImage UseXPutImage true useXSetTile UseXSetTile true
  • To set X resources, put them in a file (such as ~/.Xdefaults on Unix) in a form like this:
Ghostscript*geometry: 595x842-0+0 Ghostscript*xResolution: 72 Ghostscript*yResolution: 72

Then merge these resources into the X server's resource database:

xrdb -merge ~/.Xdefaults
  • Ghostscript doesn't look at the default system background and foreground colors; if you want to change the background or foreground color, you must set them explicitly for Ghostscript. This is a deliberate choice, so that PostScript documents will display correctly by default -- with white as white and black as black -- even if text windows use other colors.
  • The geometry resource affects only window placement.
  • Resolution is expressed in pixels per inch (1 inch = 25.4mm).
  • The font tolerance gives the largest acceptable difference in height of the screen font, expressed as a percentage of the height of the desired font.
  • The palette resource can be used to restrict Ghostscript to using a grayscale or monochrome palette.
  • maxRGBRamp and maxGrayRamp control the maximum number of colors that ghostscript allocates ahead of time for the dither cube (ramp). Ghostscript never preallocates more than half the cells in a colormap. maxDynamicColors controls the maximum number of colors that Ghostscript will allocate dynamically in the colormap.

The " use ..." resources exist primarily to work around bugs in X servers.

  • Old versions of DEC's X server (DECwindows) have bugs that require setting useXPutImage or useXSetTile to false .
  • Some servers do not implement backing pixmaps properly, or do not have enough memory for them. If you get strange behavior or "out of memory" messages, try setting useBackingPixmap to false .
  • Some servers do not implement tiling properly. This appears as broad bands of color where dither patterns should appear. If this happens, try setting useXSetTile to false .
  • Some servers do not implement bitmap or pixmap displaying properly. This may appear as white or black rectangles where characters should appear; or characters may appear in "inverse video" (for instance, white on a black rectangle rather than black on white). If this happens, try setting useXPutImage to false .

In addition to the device parameters recognized by all devices , Ghostscript's X driver provides parameters to adjust its performance. Users will rarely need to modify these. Note that these are parameters to be set with the -d switch in the command line (e.g., -dMaxBitmap=10000000 ), not resources to be defined in the ~/.Xdefaults file.

Because of bugs in the SCO Unix kernel, Ghostscript will not work if you select direct screen output and also allow it to write messages on the console. If you are using direct screen output, redirect Ghostscript's terminal output to a file.

Unless otherwise noted, these switches can be used on all platforms.

Because Ghostscript must initialize the PostScript environment before executing the commands specified by this option it should be specified after other setup options. Specifically this option 'bind's all operations and sets the systemdict to readonly.

Note that by "library files" here we mean all the files identified using the search rule under " How Ghostscript finds files " above: Ghostscript's own initialization files, fonts, and files named on the command line.

/XYZ 35 def

whereas -sXYZ=35 is equivalent to

/XYZ (35) def
-pFoo="<< /Bar[1 2 3]/Baz 0.1 /Whizz (string) /Bang <0123> >>"

This means that -p can do the job of both -d and -s . For example:


can be equivalently performed by


Note, that there are some 'special' values that should be set using -s , not -p , such as DEVICE and DefaultGrayProfile . Broadly, only use -p if you cannot set what you want using -s or -d .

Also, internally, after setting an parameter with -p we perform an initgraphics operation. This is required to allow changes in parameters such as HWResolution to take effect. This means that attempting to use -p other than at the start of a page is liable to give unexpected results.

Note that the initialization file makes systemdict read-only, so the values of names defined with -D , -d , -S , and -s cannot be changed -- although, of course, they can be superseded by definitions in userdict or other dictionaries. However, device parameters set this way ( PageSize , Margins , etc.) are not read-only, and can be changed by code in PostScript files.

As noted above, -d and -s define initial values for PostScript names. Some of these names are parameters that control the interpreter or the graphics engine. You can also use -d or -s to define a value for any device parameter of the initial device (the one defined with -sDEVICE= , or the default device if this switch is not used). For example, since the ppmraw device has a numeric GrayValues parameter that controls the number of bits per component, -sDEVICE=ppmraw -dGrayValues=16 will make this the default device and set the number of bits per component to 4 (log2(16)).

By default InterpolateControl is 1 and the image rendering for images that have /Interpolate true are interpolated to the full device resolution. Otherwise, images are rendered using the nearest neighbour scaling (Bresenham's line algorithm through the image, plotting the closest texture coord at each pixel). When downscaling this results in some source pixels not appearing at all in the destination. When upscaling, each source pixels will cover at least one destination pixel.

When the control_value is 0 no interpolation is performed, whether or not the file has images with /Interpolate true .

When the control_value is greater than 1 interpolation is performed for images with /Interpolate true as long as the image scaling factor on either axis is larger than the control_value . Also, the interpolation only produces images that have (device resolution / control_value) maximum resolution rather than full device resolution. This allows for a performance vs. quality tradeoff since the number of pixels produced by the interpolation will be a fraction of the interpolated pixels at full device resolution. Every source pixel will contribute partially to the destination pixels.

When the InterpolateControl control_value is less than 0 interpolation is forced as if all images have /Interpolate true , and the interpolation is controlled by the absolute value of the control_value as described above. Thus, -dInterpolateControl=-1 forces all images to be interpolated at full device resolution.

Computationally, image interpolation is much more demanding than without interpolation (lots of floating point muliplies and adds for every output pixel vs simple integer additions, subtractions, and shifts).

In all but special cases image interpolation uses a Mitchell filter function to scale the contributions for each output pixel. When upscaling, every output pixel ends up being the weighted sum of 16 input pixels, When downscaling more source pixels will contribute to the interpolated pixels. Every source pixel has some effect on the output pixels.

Note that because of the way antialiasing blends the edges of shapes into the background when they are drawn some files that rely on joining separate filled polygons together to cover an area may not render as expected with GraphicsAlphaBits at 2 or 4. If you encounter strange lines within solid areas, try rendering that file again with -dGraphicsAlphaBits=1 .

Further note; because this feature relies upon rendering the input it is incompatible, and will generate an error on attempted use, with any of the vector output devices.

The parameter has no effect if -dTextAlphaBits=1 . Default value is 0.

Setting -dAlignToPixels=0 can improve rendering of poorly hinted fonts, but may impair the appearance of well-hinted fonts.

-sPageList=1,3,5 indicates that pages 1, 3 and 5 should be processed. -sPageList=5-10 indicates that pages 5, 6, 7, 8, 9 and 10 should be processed. -sPageList=1, 5-10, 12- indicates that pages 1, 5, 6, 7, 8, 9, 10 and 12 onwards should be processed.

The PDF interpreter and the other language interpreters handle these in slightly different ways. Because PDF files enable random access to pages in the document the PDF inerpreter only interprets and renders the required pages. PCL andPostScript cannot be handled in ths way, and so all the pages must be interpreted. However only the requested pages are rendered, which can still lead to savings in time. Be aware that using the '%d' syntax for OutputFile does not reflect the page number in the original document. If you chose (for example) to process even pages by using -sPageList=even , then the output of -sOutputFile=out%d.png would still be out0.png, out1.png, out2.png etc......

This option sets the -dEPSFitPage , -dPDFFitPage , and the -dFitPage options.

  • -sNupControl= An empty string will turn off nesting. If there are any nested pages on the master page, the partially filled master page will be output.

A note for Windows users, Artifex recommends the use of the forward slash delimiter due to the special interpretation of \" by the Microsoft C startup code. See Parsing C Command-Line Arguments for more information.

Adobe specifies GenericResourceDir to be an absolute path to a single resource directory. Ghostscript instead maintains multiple resource directories and uses an extended method for finding resources, which is explained in "Finding PostScript Level 2 resources" .

Due to the extended search method, Ghostscript uses GenericResourceDir only as a default directory for resources being not installed. Therefore GenericResourceDir may be considered as a place where new resources to be installed. The default implementation of the function ResourceFileName uses GenericResourceDir when (1) it is an absolute path, or (2) the resource file is absent. The extended search method does not call ResourceFileName .

Default value is (./Resource/) for Unix, and an equivalent one on other platforms.

Default value is (./Font/) for Unix, and an equivalent one on other platforms.

Note that this redirects PostScript output to %stdout but does not change the destination FILE of device output as with -sOutputFile=- or even -sOutputFile=%stdout since devices write directly using the stdout FILE * pointer with C function calls such as fwrite or fputs.

Pages that are saved instead of printed are retained until the list of saved pages is emptied by the flush command of the saved-pages= command string.

Pages can be printed in reverse or normal order, or selected pages, including all even or all odd, and multiple collated copies can be produced. Since pages are saved until the flush command, pages can be printed multiple times, in any order.

Refer to the SavedPages document for details.

This option behaves the same way as the UsePDFX3Profile , but the selection criteria are different. Because its possible (as of PDF 2.0) for each page to have a different array, its not sufficient just to supply an array index, as the same profile might potentially be at different indices in each array.

Instead this option takes a string, which is first compared against the OutputConditionIdentifier in each OutputIntent in the array. If the OutputConditionIdentifier is not a standard identifier then it should be Custom and the UseOutputIntent string will be matched against the value of the Info key instead. If the OutputConditionIdentifier or Info matches the value of UseOuttpuIntent , then that OutputIntent is selected if the OutputIntent contains a DestOutputProfile key.

If the user doesn't use the -sICCProfilesDir= command line option, Ghostscript creates a default value for it by looking on the directory paths explained in How Ghostscript finds files . If the current directory is the first path a test is made for the iccprofiles directory. Next, the remaining paths with the string Resource in it are tested. The prefix up to the path separator character preceding the string Resource, concatenated with the string iccprofiles is used and if this exists, then this path will be used for ICCProfilesDir.

Note that if the build is performed with COMPILE_INITS=1, then the profiles contained in gs/iccprofiles will be placed in the ROM file system. If a directory is specified on the command line using -sICCProfilesDir=, that directory is searched before the iccprofiles/ directory of the ROM file system is searched.

This also requires that the input be from stdin, otherwise an error will result ( Error: /invalidrestore in --restore-- ).

Example usage is: gs ... -dJOBSERVER - < -or- cat | gs ... -dJOBSERVER - Note: The ^D does not result in an end-of-file action on stdin as it may on some PostScript printers that rely on TBCP (Tagged Binary Communication Protocol) to cause an out-of-band ^D to signal EOF in a stream input data. This means that direct file actions on stdin such as flushfile and closefile will affect processing of data beyond the ^D in the stream.

This mode should be used with caution, and .setsafe should be run prior to running any PostScript file with unknown contents.

save .setsafe Postscript ops restore

This mode also sets the .LockSafetyParams parameter of the default device, or the device specified with the -sDEVICE= switch to protect against programs that attempt to write to files using the OutputFile device parameter. Note that since the device parameters specified on the command line (including OutputFile) are set prior to SAFER mode, the -sOutputFile=... on the command line is unrestricted.

SAFER mode also prevents changing the /GenericResourceDir, /FontResourceDir and either the /SystemParamsPassword or the /StartJobPassword.

When running -dNOSAFER it is possible to perform a save , followed by .setsafe , execute a file or procedure in SAFER mode, then use restore to return to NOSAFER mode. It is possible that the a crafted foreign file could restore back to a point when NOSAFER was in operation.

Ghostscript attempts to find an optimum balance between speed and memory consumption, but there are some cases in which you may get a very large speedup by telling Ghostscript to use more memory.

Please note that this discussion relates to devices which produce a bitmap format as the output. These parameters have no effect on the vector devices, such as pdfwrite.

  • For raster printers and image format (jpeg*, tiff*, png* ...) devices, performance can be 'tuned' by adjusting some of the parameters related to banding (clist) options (refer to: Banding Parameters ).

All devices may use a display list ("clist") and use banding when rendering PDF 1.4 transparency. This prevents allocation of excessively large amounts of memory for the transparency buffer stack. The -dMaxBitmap= option is used to control when to use the display list, and the other banding parameters mentioned above control the band size.

In general, page buffer mode is faster than banded/clist mode (a full page buffer is used when -dMaxBitmap=# is large enough for the entire raster image) since there is no need to write, then interpret the clist data.

On a multi-core system where multiple threads can be dispatched to individual processors/cores, banding mode may provide higher performance since -dNumRenderingThreads=# can be used to take advantage of more than one CPU core when rendering the clist. The number of threads should generally be set to the number of available processor cores for best throughput.

In general, larger -dBufferSpace=# values provide slightly higher performance since the per-band overhead is reduced.

  • If you are using X Windows, setting the -dMaxBitmap= parameter described above may dramatically improve performance on files that have a lot of bitmap images.

This can also be useful in processing large documents when using a high-level (vector) output device (like pdfwrite) that maintains significant internal state.

For pattern tiles that are very large, Ghostscript uses an internal display list (memory based clist), but this can slow things down. The current default threshold is 8Mb -- pattern tiles larger than this will be cached as clist rather than bitmap tiles. The parameter -dMaxPatternBitmap=# can be used to adjust this threshold, smaller to reduce memory requirements and larger to avoid performance impacts due to clist based pattern handling.

For example, -dMaxPatternBitmap=200000 will use clist based patterns for pattern tiles larger than 200,000 bytes.

The information here describing is probably interesting only to developers.

Debug switches

There are several debugging switches that are detected by the interpreter. These switches are available whether or not Ghostscript was built with the DEBUG macro defined to the compiler (refer to building a debugging configuration ).

Previous to 8.10, there was a single DEBUG flag, enabled with -dDEBUG on the command line. Now there are several debugging flags to allow more selective debugging information to be printed containing only what is needed to investigate particular areas. For backward compatibilty, the -dDEBUG option will set all of the subset switches.

The PDF interpreter normally tries to repair, or ignore, all problems encountered in PDF files. Setting -dPDFSTOPONERROR instead causes the interpreter to signal an error and stop processing the PDF file, instead of printing a warning.

The -dPDFSTOPONWARNING switch behaves the same, but will stop if a condition which would normally merit a warning (instead of an error) is encountered. Note that setting -dPDFSTOPONWARNING also sets -dPDFSTOPONERROR .

The -Z and -T switches apply only if the interpreter was built for a debugging configuration . In the table below, the first column is a debugging switch, the second is an equivalent switch (if any) and the third is its usage.

Switches used in debugging Switch  Description -B size Run all subsequent files named on the command line (except for -F ) through the run_string interface, using a buffer of size bytes -B- Turn off -B : run subsequent files (except for -F ) directly in the normal way -F file Execute the file with -B1 temporarily in effect -K n Limit the total amount of memory that the interpreter can have allocated at any one time to n K bytes. n is a positive decimal integer. -M n Force the interpreter's allocator to acquire additional memory in units of n K bytes, rather than the default 20K. n is a positive decimal integer, on 16-bit systems no greater than 63. -N n Allocate space for n K names, rather than the default (normally 64K). n may be greater than 64 only if EXTEND_NAMES was defined (in inameidx.h) when the interpreter was compiled . -Z xxx -Z- xxx Turn debugging printout on (off). Each of the xxx characters selects an option. Case is significant: "a" and "A" have different meanings. 0 garbage collector, minimal detail 1 type 1 and type 42 font interpreter 2 curve subdivider/rasterizer     3 curve subdivider/rasterizer, detail 4 garbage collector (strings)     5 garbage collector (strings, detail) 6 garbage collector (clumps, roots)     7 garbage collector (objects)     8 garbage collector (refs)     9 garbage collector (pointers) a allocator (large blocks only)     A allocator (all calls) b bitmap image processor     B bitmap images, detail c color/halftone mapper d dictionary put/undef     D dictionary lookups e external (OS-related) calls f fill algorithm (summary)     F fill algorithm (detail) g gsave/grestore[all] h halftone renderer     H halftones, every pixel i interpreter, just names     I interpreter, everything j (Japanese) composite fonts k character cache and xfonts     K character cache, every access l command lists, bands     L command lists, everything m makefont and font cache n name lookup (new names only) o outliner (stroke)     O stroke detail p band list paths     P all paths q clipping r arc renderer s streams     S scanner t tiling algorithm u undo saver (for save/restore), finalization     U undo saver, more detail v compositors: alpha/transparency/overprint/rop     V compositors: alpha/transparency/overprint/rop, more detail w compression encoder/decoder x transformations y Type 1 hints     Y Type 1 hints, every access z trapezoid fill # operator error returns % externally processed comments * image and RasterOp parameters : command list and allocator/time summary ~ math functions and Functions ' contexts, create/destroy     " contexts, every operation ^ reference counting _ high-level (vector) output ! Postscript operator names (this option is available only when Ghostscript is compiled with a predefined macro DEBUG_TRACE_PS_OPERATORS) | (reserved for experimental code) The following switch affects what is printed, but does not select specific items for printing: / include file name and line number on all trace output These switches select debugging options other than what should be printed: $ set unused parts of object references to identifiable garbage values + use minimum-size stack blocks , don't use path-based banding ` don't use high-level banded images ? validate pointers before, during and after garbage collection, also before and after save and restore; also make other allocator validity checks @ fill newly allocated, garbage-collected, and freed storage with a marker (a1, c1, and f1 respectively) -T xxx -T- xxx       Turn Visual Trace on (off). Each of the xxx characters selects an option. Case is significant: "f" and "F" have different meanings. f the filling algorithm with characters F the filling algorithm with non-character paths h the Type 1 hinter s the shading algorithm S the stroking algorithm

In addition, calling ghostscript with --debug will list all the currently defined (non visual trace) debugging flags, both in their short form (as listed above for use with -Z ) and in a long form, which can be used as in: --debug=tiling,alloc . All the short form flags for -Z have an equivalent long form. Future flags may be added with a long form only (due to all the short form flags being used already).

Visual Trace allows to view internal Ghostscript data in a graphical form while execution of C code. Special instructions to be inserted into C code for generating the output. Client application rasterizes it into a window.

Currently the rasterization is implemented for Windows only, in clients gswin32.exe and gswin32c.exe. They open Visual Trace window when graphical debug output appears, -T switch is set, and Ghostscript was built with DEBUG option. There are two important incompletenesses of the implementation :

1. The graphical output uses a hardcoded scale. An advanced client would provide a scale option via user interface.

2. Breaks are not implemented in the client. If you need a step-by-step view, you should use an interactive C debugger to delay execution at breakpoints.

The paper sizes known to Ghostscript are defined at the beginning of the initialization file ; see the comments there for more details about the definitions. The table here lists them by name and size. defines their sizes exactly in points, and the dimensions in inches (at 72 points per inch) and centimeters shown in the table are derived from those, rounded to the nearest 0.1 unit. A guide to international paper sizes can be found at

* Note: Initially the B paper sizes are the ISO sizes, e.g., b0 is the same as isob0 . Running the file lib/ makes the B paper sizes be the JIS sizes, e.g., b0 becomes the same as jisb0 .

For Sun's X11/NeWS one can use the OpenWindows scalable fonts instead, which gives good output for any point size. In this environment, the relevant section of the resource file should look like this:

Running Ghostscript with third-party font renderers

Font API (FAPI) is a feature which allows to attach third-party font renderers to Ghostscript. This section explains how to run Ghostscript with third-party font renderers, such as UFST. NOTE: FreeType is now the default font renderer for Ghostscript.

Note: To run Ghostscript with UFST you need a license from Monotype Imaging. Please ignore issues about UFST if you haven't got it.

Important note: Third-party font renderers may be incompatible with devices that can embed fonts in their output (such as pdfwrite), because such renderers may store fonts in a form from which Ghostscript cannot get the necessary information for embedding, for example, the Microtype fonts supplied with the UFST. Ghostscript can be configured to disable such renderers when such a device is being used.

As of Ghostscript version 9.0, Ghostscript uses Freetype 2.4.x as the default font scaler/renderer.

With this change, we added a new switch: -dDisableFAPI=true to revert to the older behavior, just in case serious regression happens that cannot be resolved in a timely manner. It is intended that this switch will be removed once the FAPI/Freetype implementation has proven itself robust and reliable in the "real world".

NOTE: With version 9.18 recently released we have, for some time, regarded FAPI/Freetype as being the canonical glyph rendering solution for Ghostscript and associated products, and the non-FAPI rendering to be deprecated. As such, the -dDisableFAPI=true option is also considered deprecated, and should be expected to be removed shortly after the next release.

To run Ghostscript with UFST, you first need to build Ghostscript with the UFST bridge. Refer How to build Ghostscript with UFST . Both bridges may run together.

There are 2 ways to handle fonts with a third-party font renderer (FAPI). First, you can substitute any FAPI-handled font to a resident PostScript font, using special map files FAPIfontmap and FAPIcidfmap . Second, you can redirect PostScript fonts to FAPI, setting entries in FAPIconfig file.

Names FAPIfontmap , FAPIcidfmap , FAPIconfig in this text actually are placeholders, which may be substituted with command line arguments : -sFAPIfontmap= name1 -sFAPIcidfmap= name2 -sFAPIconfig= name3 . Ghostscript searches the specified file names as explained in How Ghostscript finds files . Default values for these arguments are equal to argument names. When building Ghostscript with COMPILE_INITS=1 , only default values are used.

Font files, which are being handled with FAPI, may reside in any directory in your hard disk. Paths to them to be specified in FAPIfontmap and with special command line arguments, explained below. The path may be either absolute or relative. Relative ones are being resolved from the path, which is specified in FAPIconfig file.

The file FAPIfontmap is actually special PostScript code. It may include records of 2 types : general records and FCO records (see below).

A general record describes a font, which is being rendered with FAPI. They must end with semicolon. Each general record is a pair. The first element of the pair is the font name (the name that PostScript documents use to access the font, which may differ from real name of the font which the font file defines). The second element is a dictionary with entries :

Example of a general FAPI font map record :

/FCO1 << /Path (/AFPL/UFST/fontdata/MTFONTS/PCLPS3/MT1/PCLP3__F.fco) /FontType 1 /FAPI /UFST >> ;

FCO records work for UFST only. A group of FCO records start with a line name ReadFCOfontmap: , where name is a name of a command line argument, which specify a path to an FCO file. The group of FCO records must end with the line EndFCOfontmap . Each record of a group occupy a single line, and contains a number and 1, 2 or 3 names. The number is the font index in the FCO file, the first name is the Postscript font name, the secong is an Encoding resource name, and the third is a decoding resource name.

Note that FAPIfontmap specifies only instances of Font category. CID fonts to be listed in another map file.

Ghostscript distribution includes sample map files gs/lib/FAPIfontmap , gs/lib/FCOfontmap-PCLPS2 , gs/lib/FCOfontmap-PCLPS3 , gs/lib/FCOfontmap-PS3 , which may be customized by the user. The last 3 ones include an information about UFST FCO files.

The file FAPIcidfmap defines a mapping table for CIDFont resources. It contains records for each CID font being rendered with FAPI. The format is similar to FAPIfontmap , but dictionaries must contain few different entries :

Example of FAPI CID font map record :

/HeiseiKakuGo-W5 << /Path (/WIN2000/Fonts/PMINGLIU.TTF) /CIDFontType 0 /FAPI /UFST /CSI [(Japan1) 2] >> ;

The control file FAPIconfig defines 4 entries :

Ghostscript distribution includes sample config files gs/lib/FAPIconfig , gs/lib/FAPIconfig-FCO . which may be customized by the user. The last ones defines the configuration for handling resident UFST fonts only.

In special cases you may need to customize the file lib/xlatmap . Follow instructions in it.

Some UFST font collections need a path for finding an UFST plugin. If you run UFST with such font collection, you should run Ghostscript with a special command line argument -sUFST_PlugIn= path , where path specifies a disk path to the UFST plugin file, which Monotype Imaging distributes in ufst/fontdata/MTFONTS/PCL45/MT3/plug__xi.fco . If UFST needs it and the command line argument is not specified, Ghostscript prints a warning and searches plugin file in the current directory.

If you want to run UFST with resident UFST fonts only (and allow Ghostscript font renderer to handle fons, which may be downloaded or embedded into documents), you should run Ghostscript with these command line arguments : -sFCOfontfile= path1 -sFCOfontfile2= path2 -sUFST_PlugIn= path3 -sFAPIfontmap= map-name -sFAPIconfig=FAPIconfig-FCO where path1 specifies a disk path to the main FCO file, path2 specifies a disk path to the Wingdings FCO file, path3 a disk path the FCO plugin file, path1 is either gs/lib/FCOfontmap-PCLPS2 , gs/lib/FCOfontmap-PCLPS3 , or gs/lib/FCOfontmap-PS3 . FAPIcidfmap works as usual, but probably you want to leave it empty because FCO doesn't emulate CID fonts.

Some configurations of UFST need a path for finding symbol set files. If you compiled UFST with such configuration, you should run Ghostscript with a special command line argument -sUFST_SSdir= path , where path specifies a disk path to the UFST support directory, which Monotype Imagong distributes in ufst/fontdata/SUPPORT . If UFST needs it and the command line argument is not specified, Ghostscript prints a warning and searches symbol set files in the current directory.

Note that UFST and Free Type cannot handle some Ghostscript fonts because they do not include a PostScript interpreter and therefore have stronger restrictions on font formats than Ghostscript itself does - in particular, Type 3 fonts. If their font types are listed in HookDiskFonts or in HookEmbeddedFonts , Ghostscript interprets them as PS files, then serializes font data into a RAM buffer and passes it to FAPI as PCLEOs. (see the FAPI-related source code for details).

Instantly share code, notes, and snippets.


brenopolanski /

  • Star 140 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist

A simple Ghostscript command to merge two PDFs in a single file is shown below:

Install Ghostscript:

Type the command sudo apt-get install ghostscript to download and install the ghostscript package and all of the packages it depends on.


oldi commented Apr 1, 2019

Many thanks! You saved my day :) 👍

Sorry, something went wrong.


carpediemmlf commented Aug 15, 2019


Lydnasty commented Mar 11, 2020


kepatopoc commented May 17, 2020


Abhishek-Deshmukh commented Nov 22, 2020


oliverlambson commented Jan 4, 2021 • edited

I added this to a function in my .zshrc (or .bash_profile for *nix) for easier use.

Then you can just run

Which will output the combined pdfs to a file called file1___file2.pdf

Inspired by this gist which is using ghostscript to compress a pdf.


ageek commented Jan 11, 2021

Works perfectly on Cygwin @Windows 10 64 bit . Thanks !


mrwm commented Mar 2, 2021

Is there a way to merge them together to make a double spread pdf? something like this , but with ghostscript?


alexisdal commented May 27, 2021

didn't work for me. silly errors in the output that i did not understand.

but pdftk free did work for me => beautifully simple and fast command line. might help someone else

pdftk.exe input_*.pdf output combined.pdf


madurapa commented Sep 17, 2021


IllustratedMan-code commented Nov 9, 2021

I slightly modified @oliverlambson 's function to accept n arguments, where the first argument is the name of the resulting pdf. pdfcombine () { gs -q -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=${1%.*}.pdf -dBATCH ${@:2} }


guilhemferr commented Mar 25, 2022

Added a check. Found it handy to have in .zshrc . Usage will be eg. pdfmerge mergerd.pdf in1.pdf in2.pdf


rustinlewis commented Apr 22, 2022

Any downside to using -o ?

Auto adds the -dBATCH and -dNOPAUSE ... Found in the docs here

gs -o combine.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress 1.pdf 2.pdf


frankie303 commented Jun 28, 2022


TomLaco commented Jul 19, 2022

This could not be easier ! Thank you very much !


tanimislam commented Jul 26, 2023


Steve778845 commented Nov 1, 2023

Split PDF file

Separate one page or a whole set for easy conversion into independent pdf files..

  • Extract pages
  • Custom ranges
  • Fixed ranges
  • Extract all pages
  • Select pages

Splitting PDF...


  1. PDF Batch Splitting and OCR using Ghostscript

    ghostscript pdf split

  2. Ghostscript para juntar varios PDF en uno solo

    ghostscript pdf split

  3. How To Convert PDF to Image Using Ghostscript API

    ghostscript pdf split

  4. pdf ghostscript tool download for free

    ghostscript pdf split

  5. GhostScript

    ghostscript pdf split

  6. How to Batch Compress PDF Files using Ghostscript

    ghostscript pdf split


  1. pdf solution #pdf #computer #pdfconverter

  2. Add Bookmark To PDF

  3. PDF to Images

  4. PDF Jack

  5. Password Protect PDF

  6. Editing PDF Pages (Split, Rearrange, Reverse, Delete, Duplicate pages delete)


  1. Splitting a PDF with Ghostscript

    Splitting a PDF with Ghostscript Ask Question Asked 11 years, 8 months ago Modified 1 year, 4 months ago Viewed 52k times 45 I try to split a multipage PDF with Ghostscript, and I found the same solution on more sites and even on, namely: gs -sDEVICE=pdfwrite -dSAFER -o outname.%d.pdf input.pdf

  2. Splitting a PDF file with Ghostscript results in one extra blank page

    2. I try to split the pages of one PDF file into a separated one-page PDF files. This command does the job so far: gs \ -q \ -dQUIET \ -dSAFER \ -dBATCH \ -dNOPAUSE \ -dNOPROMPT \ -dAutoRotatePages=/None \ -sDEVICE=pdfwrite \ -sOutputFile=test0%d.pdf \ -fpdf-sample.pdf. This works, but every time there is one more PDF file generated which is ...

  3. How can I split a PDF's pages down the middle?

    27 Try BRISS. It lets you split each page into as many subpages as you want by defining regions with a GUI. It groups all similar pages into groups for you, so you can define regions for that group once. It's cross-platform, free, and open-source.

  4. Split and Recombine PDF Files and Pages in Linux

    Press Select PDF or drag and drop to select a single PDF file. Choose Split settings ( Every page, every "n" pages, Odd pages, Even pages, given pages) Set name prefix or leave default ( PDFsam_) Press Run. After the above procedure, we end up with the respective page range files.

  5. PDF Post-Processing PDFs with Ghostscript

    In its most basic usage Ghostscript can be used to combine or split existing PDF files. However, by supplying a secondary file containing a list of pdfmarks it is possible to do much more. This paper will present some of the functionality that Ghostscript provides. Combining and splitting PDFs Using pdfmarks to

  6. PDF Split & Merge with Ghostscript · GitHub

    PDF Split & Merge with Ghostscript Raw # [mac] rename scans mv Scan.pdf Scan\ 0.pdf \ && rename -N 001 -v 's/Scan (\d+).pdf/scan-$N.pdf/g' Scan*.pdf # pdf merge gs -dNOPAUSE -sDEVICE=pdfwrite -dBATCH -dSAFER -sOUTPUTFILE=<target> <file1> <file2> ... # pdf split

  7. Split each page of a pdf document into separate pdfs using GhostScript

    Split each page of a pdf document into separate pdfs using GhostScript · GitHub Instantly share code, notes, and snippets. songuke / extract_pdf.bat Created 7 years ago Star 0 Fork 0 Code Revisions 1 Embed Download ZIP Split each page of a pdf document into separate pdfs using GhostScript Raw extract_pdf.bat for /l %x in (1, 1, 15) do (

  8. How to split/join pdf files

    Ghostscript is a very useful tool in this situation. Install ghostscript (the gs command line). sudo apt install -yq ghostscript To extract pages from the 3rd page to the 5th page in in.pdf , write output to out.pdf gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=3 -dLastPage=5 -sOutputFile=out.pdf in.pdf

  9. ghostscript

    This was with the code above copied and pasted into a script file. - bu5hman. Apr 9, 2019 at 19:38. Try extracting just 1 chunk with a manual run of the getChunk function. gs -q -dNOPAUSE -sDEVICE=pdfwrite -sPageList=1-100 -o output.pdf input.pdf. - bu5hman. Apr 9, 2019 at 19:42.

  10. Split PDFs Windows (ghostscript) · GitHub

    Split PDFs Windows (ghostscript). GitHub Gist: instantly share code, notes, and snippets.

  11. Using Ghostscript

    Convert a PostScript document to PDF ps2pdf The output is saved as file.pdf. Note 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.

  12. Ghostscript : Optimizing PDFs

    By Ken Sharp - Thursday, September 29, 2022. There are quite a few 'guides' or suggestions on the Internet for 'optimizing' PDF files, and many of them suggest using Ghostscript to perform the task. Confusingly, they often differ in their advice and sometimes are even contradictory, making it hard to find helpful information.

  13. How to Use Ghostscript

    This is intended to be a quick way to invoke ghostscript to convert one or more input files. For instance, to convert to JPEG image files, one per page, use: gs -sDEVICE=jpeg -o out-%d.jpg is equivalent to: gs -sDEVICE=jpeg -sOutputFile=out-%d.jpg -dBATCH -dNOPAUSE

  14. Merge multiple PDFs using Ghostscript · GitHub

    Merge multiple PDFs using Ghostscript. Raw. A simple Ghostscript command to merge two PDFs in a single file is shown below: gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=combine.pdf -dBATCH 1.pdf 2.pdf.

  15. Split PDF files online. Free service to split PDF

    Separate one page or a whole set for easy conversion into independent PDF files. Select PDF file. or drop PDF here. Split a PDF file by page ranges or extract all PDF pages to multiple PDF files. Split or extract PDF files online, easily and free.

  16. Converting a PDF to a series of images with Python

    I'm attempting to use Python to convert a multi-page PDF into a series of JPEGs. I can split the PDF up into individual pages easily enough with available tools, but I haven't been able to find anything that can covert PDFs to images. PIL does not work, as it can't read PDFs. The two options I've found are using either GhostScript or ...

  17. Ghostscript to merge PDFs compresses the result

    3 Answers Sorted by: 86 Here's some additional options that you can pass when using pdfwrite as your device. According to that page if you don't pass anything then -dPDFSETTINGS it gets set to something close to /screen, although it doesn't get more specific.