import java.awt.Rectangle;
import java.awt.Graphics2D;
import java.awt.Color;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.IOException;
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.dom.GenericDOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.DOMImplementation;
import org.apache.fop.svg.*;
import java.awt.*;
import org.apache.batik.ext.awt.g2d.*;

public class TestPDFGen {

    public static void main(String [] args) throws Exception {

	// Initialize objects
	
	// Obtain the image
	Image img=null;
	try {
    		img=Toolkit.getDefaultToolkit().createImage("Glob.JPEG");
	}
	catch (Exception e) {
		throw new Exception("Failed to load node image:" + e.getMessage() );
	}	
	if (img==null) {
		throw new Exception("Failed to load node image");	
	}
	
	Panel panel = new Panel();
	
	//Thread.sleep(5000);
	//
	//if (!(Toolkit.getDefaultToolkit().prepareImage(img,-1,-1,panel))) {
	//	throw new Exception("prepareImage failed!");
	//}
	
	PDFDocumentGraphics2D PDFGenerator1=null;
	try {
	        // Create an instance of the SVG Generator
        	PDFGenerator1 = new PDFDocumentGraphics2D(true,System.out,800,1100);
	}
	catch (Exception e) {
		System.out.println("new PDFDocumentGraphics2D failed: " + e.getMessage());
	}
	PDFGenerator1.setGraphicContext(new GraphicContext());
	PDFGenerator1.create();

	// Paint first page
        PDFGenerator1.setColor(Color.red);
	PDFGenerator1.drawRect(100,100,100,100);
	PDFGenerator1.drawImage(img,400,300,100,100,panel);
	panel.paint(PDFGenerator1);
	PDFGenerator1.drawImage(img,400,300,100,100,panel);
	
	// Finish PDF document
	PDFGenerator1.finish();
    }
}