Wednesday, September 24, 2008

Step 2 - SVG printer - Continued

As I mentioned before in the previous post, I was not able to find a batik print example. It turned out, that information about SVG printing I was able to find in batik-user mailing list. It took some time to collect working solution from little parts. So mailing list helped again.

Printed out SVG document looks as it should, currently haven't noticed any issues. This is definitely a good sign. 

Here is a java code that works for me.


public void actionPerformed(ActionEvent e) {

PrinterJob printerJob = PrinterJob.getPrinterJob();
PageFormat pageFormat = printerJob.defaultPage();

PrintTranscoder transcoder = new PrintTranscoder();
TranscoderInput ti = new TranscoderInput(svgCanvas.getSVGDocument());
transcoder.transcode(ti, null);

if (printerJob.pageDialog(pageFormat) != pageFormat) {
if (printerJob.printDialog()) {
printerJob.setPrintable(transcoder);
try {
printerJob.print();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
} else {
System.err.println("Print was cancelled");
}
}







No comments: