Tags:
create new tag
view all tags

Choosing between Ghostscript and MuPDF

Ghostscript and MuPDF are both high quality renderers for page description languages. While there is considerable overlap in their abilities, each one is tailored for slightly different requirements. It can therefore sometimes be hard to know which one to use in a given situation.

Input languages

If you need the ability to handle PostScript input, then you must use Ghostscript.

If you need the ability to handle PCL input, then you must use GhostPCL (a PCL parser on top of the Ghostscript graphics library).

Similarly GhostXPS is an XPS parser written on top of the Ghostscript graphics library.

For the rest of this discussion we will just say "Ghostscript" when we actually mean "Ghostscript, GhostPCL and GhostXPS "; everything we say about Ghostscript applies to the others as they shares the same basic structure and devices. In other documents you may see all three of these referred to collectively as "GhostPDL".

If you need the ability to handle EPUB or CBZ input, then you must use MuPDF.

Both MuPDF and Ghostscript can handle PDF and XPS input.

MuPDF handles bitmap formats such as JPEG, PNG and TIF natively. Ghostscript is distributed with PostScript "helper files" to handle JPEG, GIF, MIFF (ImageMagick format) and raw files and can be persuaded to handle other formats using this type of PostScript program.

Color Management

Currently, MuPDF does not offer any color management options. Therefore if a color managed workflow is required, you need to use Ghostscript. The color management of Ghostscript uses ICC profiles and is extensive (refer to http://www.ghostscript.com/doc/current/GS9_Color_Management.pdf), supporting different color management for object types (text, images and vector graphics) and separations.

Output options

If you want to output PostScript, PCL/XL, PDF, or XPS, or you want to output to a MS Windows printer, then you need to use Ghostscript.

Printer output

As a rule of thumb, if you want printer output, you probably want to be leaning towards using Ghostscript.

If you want to output to a printer, then it is a question of whether Ghostscript or MuPDF supports your printer out of the box. Ghostscript has support for many printers that MuPDF does not, including a "uniprint" (Universal Printer) output module that allows many more printers to be supported by creating "upp" parameter files.

MuPDF does have support for some printer outputs (such as PCL and CUPS ones). If you use MuPDF and want to print to something other than a PCL printer then you are going to need to add some C code yourself.

Both MuPDF and Ghostscript can produce PWG format output (aka CUPS format, used for printing on Linux systems), but Ghostscript can handle more of the different possible output color spaces.

If you want to output for a printer type that is not currently supported by either Ghostscript, CUPS or the existing "upp" files then you are going to need to add some code yourself (possibly a "upp" file or C code).

Adding a new printer type - via bitmap output

The easiest mechanism for outputting to a printer that is not already supported or that cannot be supported using the "uniprint" module is to get Ghostscript or MuPDF to render to a bitmap, and then for convert that bitmap into a data stream for your printer.

Ghostscript has the ability to do a range of different halftoning techniques for Monochrome printers including ordered (spot) dither based on threshold arrays or functions and error diffusion. MuPDF renders in contone, and then has code in it to do simple thresholding based halftoning to give a monochrome bitmap. Other such conversions can of course be added by the integrator.

MuPDF can render in RGB, Greyscale, or CMYK. Ghostscript is capable of all this, and also of handling color separations and DeviceN colors.

Adding a new printer type - via high level output

By 'high level output' we mean making use of vector, text or image objects rather than breaking everything down to simple rasterised bitmaps.

If you wish to drive a printer with some different type of high level format, then both Ghostscript and MuPDF can handle this. Both products require you to implement a 'device' to perform graphics operations on a virtual page.

Ghostscript has high level devices to output PostScript (Level 2) and PCL-6 (aka PCL/XL).

While MuPDF does not currently offer any fully functional devices, it has both SVG output and PDF output modules that demonstrate its abilities. A third-party has implemented a GDI based output for doing rendering on Windows.

It is beyond the scope of this document to talk more about this here. Discuss your needs with an Artifex engineer to get more advice.

Bitmap output

If you are outputting to a bitmap other than monochrome, greyscale, RGB or CMYK, or if you need JPEG, TIFF, MIFF, BMP, PCX, PSD (Photoshop) or raw output use Ghostscript.

If you want TGA (TrueVision) use MuPDF.

Both Ghostscript and MuPDF support PBM, PGM, PPM, PAM, PNG and both have the ability to do anti-aliased rendering, but MuPDF has this embedded in the renderer at a lower level than Ghostscript. If anti-aliased output is important to you, then MuPDF is probably a better bet.

As a rule of thumb, if you are rendering PDF or XPS input for display based use, you probably want to be leaning towards MuPDF.

Interactive behaviour

Viewers can be built either with Ghostscript or MuPDF, but MuPDF is much better suited to this task.

Ghostscript cannot handle interactive features such as form filling, whereas MuPDF can, and MuPDF has support for incremental loading of Linearized (Web optimized) PDFs from web sites which can improve viewers response times.

Banded rendering

Both Ghostscript and MuPDF are capable of rendering pages in bands to keep memory usage down.

Ghostscript can be built with the ability to make use of RAM or disc based storage for its display list, whereas MuPDF runs entirely using RAM.

Ghostscript can make its own decisions about how big a band buffer to use (though it can be told explicitly by the caller), whereas MuPDF always leaves this to the caller to specify.

Multithreaded operation

Both Ghostscript and MuPDF interpret pages using a single thread, but both can use multiple threads to actually render the page content.

Both allow for one page to be rendered in background threads while the display list for the next page is created by the interpreter.

The decision of how to handle threads is divorced from the core of MuPDF. It is possible to implement both of the above schemes with MuPDF, as well as many others (such as rendering thumbnails for pages on a background thread, while rendering current pages at different zoom levels).

Ghostscript offers certain common tasks in a ready rolled package. MuPDF requires slightly more integration, but is ultimately more flexible for it.

Manipulation of PDF files

Ghostscript has the ability to read PDF (or other format) files, to break it down into graphical objects and to make completely new PDF files from it. Some users make use of this to 'sanitise' PDF files, reduce the size, extract pages, change the color model, etc. Some (non-graphical) information in the PDFs (such as structural information, bookmarks etc) may be lost during this process. The type of PDF file created by Ghostscript can be PDF/A-1, PDF/A-2 or PDF/X-3 and a PDF (1.4 and above) that has transparency can be "flattened" to make a PDF 1.3 that does not use transparency. Ghostscript can also encrypt the resulting PDF file allowing for separate "owner" and "user" passwords so that users can be give a restricted set of permissions.

MuPDF has the ability to directly manipulate PDF files. While it cannot convert a non-PDF file to a PDF file, it can perform operations such as page deletions, linearisation or addition of annotations without losing the existing information within the file.

Porting

Both Ghostscript and MuPDF are highly portable. Opinions differ between engineers as to which is easier to embed. Ghostscript (and GhostPCL) have been embedded in several printers and MuPDF has been embedded in many tablets and smart phones.

Speed

The actual rendering speeds of Ghostscript and MuPDF are broadly similar. MuPDF benefits from having its PDF handling written in C, so is faster at navigating and extracting information from PDF files.

The j9, j11 and j12 files are selected from the JEITA test suite, and have been used by some of our customers for performance studies. The PLRM-100 file is the first 100 pages from the PostScript Language Reference Manual - third edition. The JEITA files are available for purchase from that organization and PLRM is available from Adobe.

Ghostscript Performance

Ghostscript commit c7d005ac1c92a6fee43554fffd9a6f38c0a6b962 is run with the arguments:

-Z: -dUseFastColor=true -sBandListStorage=memory -dBufferSpace=16m -o /dev/null -sDEVICE=bit____ -r____ -dGrayValues=___ -dNumRenderingThreads=4 -dBGPrint=true

to the various "bit" devices, with -dGrayValues=2 or 256 (1-bit or 8-bit, resp.) and at either 600 or 1200 resolution. With these settings, the amount of RAM needed varies with the complexity of the page since the display list (BandList) is in RAM, and varies slightly with the resolution. For example, in Gray mode, files range from 30 Mb to 48 Mb. Note that -dUseFastColor may not be appropriate for CMYK 1-bit, since it is not possible to do color correction on a halftoned result. (TBD: run CMYK 1-bit with -dUseFastColor=false).

MuPDF (commit 35b2aeef91fdd062f54beba302726c9ea279114e) mutool is run with the arguments:

for mono 1-bit:: draw -r600 -o /dev/null -F pbm -c mono -A 0 -B 2400 -s t -P -T4

for gray 8-bit: draw -r600 -o /dev/null -F pgm -c gray -A 0 -B 2400 -s t -P -T4

for rgb: draw -r600 -o /dev/null -F ppm -c rgb -A 0 -B 880 -s t -P -T4

for cmyk 1-bit: draw -r600 -o /dev/null -F pkm -c cmyk -A 0 -B 704 -s t -P -T4

and, for cmyk 8-bit: draw -r600 -o /dev/null -F pam -c cmyk -A 0 -B 704 -s t -P -T4

For the 1200 dpi cases, mupdf Band Heights are one-half the above value for "-B". The BandHeights are set the same for 8-bit and 1-bit since mupdf first renders to 8-bit, then halftones the rendered image to 1-bit.


Running on a RaspBerry Pi 3 (Quad core ARMv8) at 1.2GHz, 1Gb RAM, with a small set of benchmark files gives some comparison for common color models and depths. Five runs of each file are performed and the fastest is used (to allow for random other processor load). All results below are in "Pages per Minute" (ppm)

Monochrome (1-bit) / Gray (8-bit)

  Ghostscript MuPDF
File # pages 600 1200 600 1200
1-bit 8-bit 1-bit 8-bit 1-bit 8-bit 1-bit 8-bit
J9.pdf 5 38.9 52.2 44.8 43.5 193.4 96.7 90.8 96.7
J11.pdf 12 36.5 56.4 17.4 26.0 120.6 127.1 60.1 64.3
J12.pdf 20 41.4 52.5 42.1 45.0 149.6 165.5 73.9 85.2
PLRM-100.pdf 100 860.8 718.3 618.9 357.2 741.1 1083.0 315.2 508.1

CMYK (1-bit per component) / contone (8-bit per component)

  Ghostscript MuPDF
File # pages 600 1200 600 1200
1-bit 8-bit 1-bit 8-bit 1-bit 8-bit 1-bit 8-bit
J9.pdf 5 49.1 47.5 43.9 33.9 105.8 129.8 35.1 44.9
J11.pdf 12 29.5 35.6 13.5 11.7 90.0 114.7 28.7 38.9
J12.pdf 20 35.7 47.1 28.2 33.8 90.6 120.1 31.2 43.2
PLRM-100.pdf 100 563.0 366.1 367.1 165.5 279.2 502.3 97.0 175.8

RGB 24-bit Contone (8-bit per component)

  Ghostscript MuPDF
File # pages 600 1200 600 1200
J9.pdf 5 43.8 37.1 165.5 61.1
J11.pdf 12 38.0 14.4 144.0 50.7
J12.pdf 20 49.1 37.1 168.9 61.1
PLRM-100.pdf 100 434.3 198.3 619.4 229.1

Running Ghostscript on a Windows XP laptop having an Intel Celeron x86 at 1.6GHz, with the same small set of benchmark files gives the results below. As with the timings above, five runs of each file are performed and the fastest is used (to allow for random other processor load). All results below are also in "Pages per Minute" (ppm).

Monochrome (1-bit) / Gray (8-bit)

File

#

pages

600

1-bit

600

8-bit

1200

1-bit

1200

8-bit

J9.pdf 5 66.1 55.1 32.5 37.7
J11.pdf 12 44.5 43.9 10.4 13.6
J12.pdf 20 46.9 54.1 32.4 26.6
PLRM-100.pdf 100 681.7 504.5 370.5 140.1

CYMK (1-bit) and 32-bit Contone (8-bit / component)

File

#

pages

600

1-bit

600

8-bit

1200

1-bit

1200

8-bit

J9.pdf 5 43.9 39.3 21.5 14.9
J11.pdf 12 22.2 19.9 5.1 4.9
J12.pdf 20 34.1 26.4 13.7 14.7
PLRM-100.pdf 100 177.9 161.3 66.7 51.4
RGB 24-bit Contone (8-bit / component)

File

#

pages

600

8-bit

1200

8-bit

J9.pdf 5 46.3 19.1
J11.pdf 12 25.5 6.8
J12.pdf 20 32.0 19.2
PLRM-100.pdf 100 216.7 74.8
Edit | Attach | Watch | Print version | History: r33 < r32 < r31 < r30 < r29 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r33 - 2017-01-25 - RobinWatts
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright 2014 Artifex Software Inc