views:

161

answers:

1

I am working on a swings application I have a Jpanel, I am facing serious problem with printing this JPanel data with "card printer". This is working fine when i using paper color printer but when i am using card printer its printing nothing. I have tested the printer using some Images and it is printing fine when i print any Image directly but using my application having problem the card printer not receiving any data while the paper printer is printing fine. Any one faced this before or anyone please help me out. This is my code:

 private void printCard(){

    PrinterJob printjob = PrinterJob.getPrinterJob();
    printjob.setJobName(" CUSTOMER CARD ");

    printjob.setPrintable (new Printable() {      
         public int print(Graphics pg, PageFormat pf, int pageNum){                  

             pf.setOrientation(PageFormat.LANDSCAPE);

             if (pageNum > 0){
                return Printable.NO_SUCH_PAGE;
             }

             Graphics2D g2 = (Graphics2D) pg;
             g2.translate(pf.getImageableX(), pf.getImageableY());
             g2.translate( 0f, 0f );
             jLayeredPane2.paint(g2);

             return Printable.PAGE_EXISTS;
         }
    });

    if (printjob.printDialog() == false)
       return;

    try {
       printjob.print();
    }
    catch (PrinterException ex) {
       System.out.println("NO PAGE FOUND."+ex);
    }
 }
A: 

I've run across issues with some printers not liking how Java printing works, and it seems greatly to do with how the printers support vector-based printing. Try raster printing instead. Render your JLayeredPane into a BufferedImage at 300dpi and printing the BufferedImage.

CarlG