2011-01-23

Secrets for embedding SVG images in PDF documents

Nhovestone reports don’t look good when zooming, because the charts are bitmap images. While trying to render them as vector images, a few interesting things did appear.

(Most of them relate to FOP-1.0 and Batik-1.7 which are the latest versions at this time.)

There was a bug (fixed in HEAD) preventing from embedding SVG images in PDF documents. Novelang resolves the image path (in n:vector-image/n:resource-location) as relative to the content directory. But most of times the stylesheet doesn’t reside right under the content root, so FOP (the PDF renderer) couldn’t find the SVG file. Now XSL stylesheets receive a $content-directory parameter to solve this.

There are several manners to embed an SVG file into a PDF. In order to keep the vector graphics (means: avoiding an ugly conversion to a bitmap) FOP needs a rather twisted declaration of the form:

<fo:instream-foreign-object>
  <svg:svg width="123px" height="456px" >
    <svg:image width="123px" height="456px" xlink:href="file:/my/image.svg" />
  </svg:svg>

The documentation explains that width and the height must appear two times, with exactly the same values.

It’s important to note that an SVG image must always have width and height. Moreover, they must be in pixel unit. Pixel unit is bad, as it introduces a dependency to document’s resolution. But units other than pixel don’t work.

Knowing this, the graphs started to look really good. Unfortunately, the grid becomes bigger when zooming in. In theory, the solution is to set line with to a zoom-independant value with vector-effect="non-scaling-stroke" property (thanks to StackOverflow for that hint). Unfortunately, this is SVG 1.2. Batik doesn’t support this yet and some archived mails show this is somewhat tricky to implement.

Conclusion: while SVG embedding in PDF is far from perfect, it’s much better than rasterized images that seemed to be FOP’s approach. In order to get best vector images we'll have to wait for non-scaling stroke feature in Batik, and maybe some FOP upgrade in order to propagate this feature to generated PDF.

2011-01-18

Aggregated javadoc with Maven

This generates a javadoc covering every subproject. From Novelang root project:

mvn -Dnovelang.javadoc.skip=false javadoc:aggregate

Generated HTML goes in target/site/apidocs.

2011-01-17

Nhovestone report for Novelang-0.54.0

The Nhovestone report shows that Novelang-0.54.0 is as at least as fast as previous versions. Good news!

2011-01-07

Novelang-0.54.0 released!

Just released Novelang-0.54.0!

Summary of changes:

  • Because of some cleanup, n:relative-identifier becomes illegal in stylesheets (wasn’t generated since a few versions). This might break a few existing stylesheets.
  • Better logging of accessed resources.
  • Documentation enhancements.

Download it from here.

Enjoy!

2011-01-03

Novelang-0.53.6 released!

Just released Novelang-0.53.6!

Summary of changes:

  • Fixed resource loading bug appeared in 0.53.5, that caused to ignore overriden resources (like stylesheets).

Download it from here.

Enjoy!

2011-01-01

Novelang-0.53.5 released!

Just released Novelang-0.53.5!

Summary of changes:

  • Various logging enhancements.
  • Various enhancements to the documentation.
  • Disabled full parsing and validation for SVG files.

Download it from here.

Enjoy!