I am using PersonaC30 card printer to print my Jpanel data on card. My print method is working fine with paper printer, but when i print with card printer it’s not printing my data. It’s printing well externally but its not working with my application.
Here is my code:
private void printCard(){ PrinterJob printjob = PrinterJob.getPrinterJob(); printjob.setJobName(' TESSCO CUSTOMER CARD '); printjob.setPrintable (new Printable() { public int print(Graphics pg, PageFormat pf, int pageNum){ Paper card = pf.getPaper(); // card.setImageableArea(0, 0, 153, 243); card.setSize(243, 154); pf.setPaper(card); 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); } }
Try this. I added some code to resize the image of the panel.