Java Drawing With Apache Batik
So... I have written a book on Apache Batik. Since I do have already some experience in writing books, I hope you will find my Batik book quite readable. And since, frankly speaking, I was learning Batik myself while writing the book, I hope it will be a good tutorial. Meet "Java Drawing With Apache Batik"! Here you will find an information on the contents of the book's chapters, a couple of examples from Chapter 7 "Batik on the Server Side", working online, some screenshots... And of course your feedback will define what else I will add to this page. |
Try the Online Examples!
(see their description below, under Chapter 7)
- Batik Graph (custom font, gradient, drawing a graph)
- Batik Filters (custom font, shadow, lighting and other filters, spam protection feature with disguised random numbers)
Chapter 1, "First Steps With Apache Batik"
- Describes the contents of the package which you can download for free from the Apache Batik website.
- Explains, in general terms, the architecture of Batik.
- Shows a simple SVG (Scalable Vector Graphics) document and explains how to view it using Squiggle, the Batik SVG browser.
- Shows some transformations you can do using Squiggle.
- Demonstrates how using SVG Rasterizer you can save an SVG document as an image in a bitmap (say, PNG) format.
- Explains how to use Pretty-Printer to, well, pretty-print your SVG document.
Chapter 2, "Creating SVG"
- Shows how using one of the Batik's core modules, SVG Generator, we can create SVG documents programmatically.
- Explains how to build a very simple Swing application which, on a press of a button, writes a primitive SVG document to a file. The key steps of drawing in Java with the help of Batik are described along the way.
Chapter 3, "Viewing SVG"
- This time the simple application that we build makes use of the JSVGCanvas, another of the core Batik components, to view the SVG document which the same application generates - the first step towards creating an imaging software of your own.
- The interactive features of JSVGCanvas are demonstrated. You can do many of those transformations available in Squiggle without writing even a line of code.
- Here is the screenshot showing our new application, SVG Creator Plus, in action:

Chapter 4, "Working With Transcoders"
- Describes the Transcoder API that can be used to transcode an SVG document into several different formats (such as JPEG, PNG or TIFF), as also other documents (say, WMF) into SVG format.
- Builds on the Swing application from the previous chapter, adding the possibility to save the result of our creative self-expression in different formats. See the screenshot below.
- We also create a simple file viewer. It will be useful in the chapters that follow.

Chapter 5, "Using DOM"
- Explains how to use DOM (Document Object Model) to manipulate the contents of an XML document (such as an SVG document) in many different ways.
- Shows how to build an SVG document in Java code.
- Explains how to use gradients in SVG documents and how to implement this opportunity in a Batik application.
- Another simple Swing application, SVG Conjurer, demonstrates in practice everything discussed throughout the chapter:

Chapter 6, "Working with Text and Fonts"
- Discusses the possibilities for displaying text that exist in SVG specification.
- Shows how to implement these possibilities in a Batik application.
- Explains what is an SVG font and how Batik can convert just any TTF font into an SVG font.
- Practically demonstrates different ways of manipulating text while building yet another Swing application. The screenshots of some of the experiments are shown below.


Chapter 7, "Batik on the Server Side"
Brings together the topics discussed in the previous chapters - such as working with DOM, using gradients and fonts - and applies them to the sample Web applications. These applications are rather close to those you might want to build in real life.
The first of these applications is SVG Graph. It demonstrates:
- the use of an SVG font (which was created from the freely available TTF font Forgotten Futurist, created by Ray Larabie);
- the use of an SVG gradient;
- the drawing of a custom graph and displaying it as a PNG file.
The first page of the application looks like this:
Enter some name - perhaps as simple as the one shown on the screenshot - and a date. This date is used simply as a row of numbers to build the graph, but you can imagine that on some New Age website this graph could show something deeply revealing. Now, press the 'Submit' button and you will see the graph, similar to this:

The second application is SVG Filters. It demonstrates:
- again, the use of a fancy SVG font created from a TTF font, this time named Vinque, from Ray Larabie;
- the use of different effects, or filters, defined in SVG specification;
On the first page, enter an Indonesian (or any other) name:
Press submit, and the second page will greet you using the entered name and also display a code. There is probably no need to explain you what kind of code it is: similar features are used everywhere as a protection from spammers, and you can easily implement such a feature with the help of Batik.

Chapter 8, "Batik Interactive"
- Explains and shows on examples how to make SVG document dynamic and interactive using ECMAScript (a.k.a. JavaScript).
- And then shows how to do the same without any JavaScript, straight in your Java code.
Id does not make sense to show you the static screenshots of the applications developed in this chapter. Better visit the publisher's website, BrainySoftware.com, download the source code, compile and run it. Or better buy the book and it will explain you how all this works.