apache > xml > graphics
Apache Batik
 

SVG Pretty Printer

This page describes the features of the SVG pretty printer utility that comes with the Batik distribution. The SVG pretty printer is a utility that can format SVG files. The tool formats an SVG document according to the arguments passed on the command line.

Downloading the pretty printer

Refer to the install page and the download page to find out what to download and how to download it. Remember that you can get either the source or binary distribution.

Pretty printing an SVG file

The method for starting the pretty-printer depends on the distribution of Batik that you chose to download. The following describes how to run the pretty printer for each distribution.

Using the binary distribution

If you downloaded the binary distribution of Batik, you should have a file called batik-1.6.zip (or similar), and, after expanding that file, a jar file called batik-svgpp.jar. To start the pretty printer, open a console, change to the directory where you expanded the distribution (and where batik-svgpp.jar is located) and simply type the following at the command prompt:

java -jar batik-svgpp.jar [OPTIONS] FILES

For example, if you type:

java -jar batik-svgpp.jar samples/batikFX.svg

you will see the indented document written to standard output.

For the options:

-newline cr|cr-lf|lf

specifies the newline character(s) generated in the printed document, the default being lf (Unix-style newlines),

-tab-width number

specifies the tabulation width, the default being 4,

-doc-width number

specifies the maximum number of columns for the whole document, the default being 80,

-no-format

specifies that the current indentation should be preserved, useful for performing doctype or newline substitutions,

-xml-decl string

specifies the XML declaration,

-doctype change|remove

specifies whether the doctype should be changed or removed,

-publid-id string

specifies the public ID to in the doctype declaration, when -doctype change is specified, and

-system-id string

specifies the system ID to in the doctype declaration, when -doctype change is specified.

For example:

java -jar batik-svgpp.jar -tab-width 2 -newline cr-lf src.svg dest.svg

will format src.svg and write it to dest.svg using a tabulation width of 2 and Windows-style newlines, and:

java -jar batik-svgpp.jar -no-format -doctype change -public-id "-//W3C//DTD SVG 1.1//EN" \
     -system-id "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" src.svg dest.svg

will format src.svg and write it to dest.svg unchanged, except for the doctype public and system IDs, which will be replaced by those specified.

Using the source distribution

If you downloaded the source distribution of Batik, you will have a zip or tar file that expanded into a directory called xml-batik or batik-version. In that directory, you can find build scripts for the platform you are running on. For example, there is a build.bat script for users of the Windows platform and there is a build.sh script for UNIX users.

To start the pretty printer you should:

  • Make sure that your JAVA_HOME environment variable is set to your JDK installation directory.

  • Open a command line window and go to the xml-batik or batik-version directory where the Batik distribution was expanded.

  • For windows, type the following at the command prompt:

    build svgpp

    and for Unix:

    ./build.sh svgpp

    This will print out a help message for the pretty printer.

You can pass options to the rasterizer as follows, for Windows:

build svgpp [OPTIONS] FILES

and for Unix:

./build.sh svgpp [OPTIONS] FILES

Refer to “Using the binary distribution” for an explanation of these options.