Printing with java under FreeBSD

Nicolas Blais nb_root at videotron.ca
Mon Sep 4 00:31:46 UTC 2006


Hi,

I've been developing several applications in Java (diablo-jdk15) and am quite 
satisfied with the result on FreeBSD and other OS. 

My only complaint so far is that I haven't had any success printing with Java. 
I'm using CUPS-1.2.2. 
Every little bits of code I find on the net do not work in FreeBSD. Is this a 
known issue? Any workaround?

Here's one small bit of code I've tried to get to work, but throws an 
exception:

//START
import java.awt.*;
import java.awt.print.*;
import java.awt.geom.*;


class PrintObject implements Printable
{
   public int print (Graphics g, PageFormat f, int pageIndex)
   {
      Graphics2D g2 = (Graphics2D) g;  // Allow use of Java 2 graphics on
                                       // the print pages :

      Rectangle2D rect = new Rectangle2D.Double(f.getImageableX(),
                                                f.getImageableY(),
                                                f.getImageableWidth(),
                                                f.getImageableHeight());

      Ellipse2D circle = new Ellipse2D.Double(100,100,100,100);

      switch (pageIndex)
      {
         case 0 : g2.setColor(Color.black);   // Page 1 : print a rectangle
                  g2.draw(rect);
                  return PAGE_EXISTS;
         case 1 : g2.setColor(Color.red);     // Page 2 : print a circle
                  g2.draw(circle);
                  return PAGE_EXISTS;
         default: return NO_SUCH_PAGE;        // No other pages
      }
   }
}

public class Sample1
{
   public static void main (String[] args)
   {
      PrinterJob job = PrinterJob.getPrinterJob();

      job.setPrintable(new PrintObject());

      if (job.printDialog())
      {

         try { job.print(); }
         catch (PrinterException e) { System.out.println(e); }
      }
   }
}
//END
-- 
FreeBSD 7.0-CURRENT #18: Sat Sep  2 14:06:41 EDT 2006     
root at clk01a:/usr/obj/usr/src/sys/CLK01A 
PGP? : http://www.clkroot.net/security/nb_root.asc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-java/attachments/20060904/3c389a32/attachment.pgp


More information about the freebsd-java mailing list