Steve, we implemented the first version of the feature. It is not available for download yet, so please contact support pd4ml com

Now PD4ML checks if there is PD4CanvasHandler class available in the classpath and invokes its getImage() method for each tag occurrence.

Below is a dummy implementation of the handler class.

[language=java:hg0efl8i]import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;

import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.MemoryCacheImageOutputStream;

import org.zefer.cache.DynamicImageHandler;

public class PD4CanvasHandler extends DynamicImageHandler
public byte[] getImage(String tagName, int width, int height, String id, HashMap attributes, String onBodyLoad, Vector scriptSections) throws Exception {

System.out.println(“canvas ID: ” + id);
System.out.println(“onBodyLoad: ” + onBodyLoad);
System.out.println(“attributes: ” + attributes);

if (scriptSections != null) {
Iterator ii = scriptSections.iterator();
while (ii.hasNext()) {
String js = (String)ii.next();

System.out.println( js );


BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED);
Graphics g = bi.getGraphics();

g.setColor( Color.white );
g.fillRect(0, 0, width, height);
g.setColor( Color.red );
g.drawString(“Canvas handler test”, 30, 30);

Iterator iter = ImageIO.getImageWritersByFormatName(“png”);
ImageWriter writer = (ImageWriter)iter.next();
ImageWriteParam iwp = writer.getDefaultWriteParam();

ByteArrayOutputStream baos = new ByteArrayOutputStream();
MemoryCacheImageOutputStream output = new MemoryCacheImageOutputStream(baos);
IIOImage image = new IIOImage(bi, null, null);
writer.write(null, image, iwp);

return baos.toByteArray();

If your idea with RhinoCanvas works, we’ll add a new method to make possible a canvas output in vector form.

For the time being PD4ML parser is not able to read tags. It needs explicit opening and closing tags: and