Ghostscript WASM Live demo Native build Source
User documentation

The svg device

The svg device writes each page as a standalone SVG (Scalable Vector Graphics) file, which web browsers display directly and which can be enlarged without loss. Wherever SVG can express the content of the page, the device writes it as SVG, rather than as pixels:

Content which SVG cannot express, or which the device does not translate, is rendered by the graphics library and embedded as a PNG image in its place in the painting order, so that the page is always complete. This applies to function-based and mesh shadings (ShadingType 1 and 4 to 7), radial shadings whose circles are not nested (cones, for example), tiling patterns, raster operations (from PCL), and images with explicit masks (ImageType 3). The device resolution applies only to these images; everything else is independent of resolution.

Colours are converted to RGB by Ghostscript's colour management, as they are for RGB raster devices. Spot colours, and the PDF content which does not mark the page (hyperlinks, bookmarks, form fields and metadata), are not carried into the SVG.

Usage

The device writes one page per file, so the output file name for a document with more than one page needs a %d, which Ghostscript replaces with the page number (see One page per file). Without one, only the first page is written, and a warning is given. For Encapsulated PostScript, -dEPSCrop makes the page the size of the figure's bounding box:

gs -sDEVICE=svg -o page-%d.svg input.pdf
gs -sDEVICE=svg -dEPSCrop -o figure.svg figure.eps

Each SVG file is sized in points, and its user units are PostScript points, with the origin at the top left of the page.

Options

-dSVGTextLayer=true | false (default is true)

Write the invisible text layer. With false, text is still drawn, but it cannot be selected or searched, and the files are smaller.

-dSVGReuseGlyphs=true | false (default is true)

Define each glyph once per page and draw it with <use>. With false, every glyph is written out as a path of its own, which makes larger files without references between elements.

-dSVGTransparency=true | false (default is true)

Write PDF transparency as SVG. With false, Ghostscript's own transparency compositor flattens each page that uses transparency, and the result is embedded as an image.

-rres (default is 192)

The resolution, in dots per inch, of the images into which content that SVG cannot express is rendered. It has no effect on paths, text, images or gradients.

Using the output

The files are SVG 1.1, together with a few features of SVG 2 and CSS which current web browsers support: mix-blend-mode, isolation and mask-type for transparency, the fr attribute for radial shadings whose starting circle has a radius and is off centre, vector-effect for zero-width lines, and image-rendering for sharp image pixels. Other SVG renderers may not support all of these, and their rendering of the affected content will then differ.

The identifiers of the definitions in a file (glyphs, clipping paths, gradients and masks) are unique only within that file. To place several pages directly in one HTML document, give each page's identifiers a distinct prefix. A browser displays an SVG file in an <img> element as a picture, without selectable text; to keep the text selectable, place the SVG in the document itself or use an <object> or <iframe> element.