I am building a Invoice program & I need to print whats on the Jpanel which is called contentPane in my code. But I can't get it to print anything other then blank pages.
Not sure what I am missing but this is the print code I am trying to use.
PrinterJob job = PrinterJob.getPrinterJob();
job.setJobName("Print Data");
job.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.scale(0.24,0.24);
contentPane.paint(g2);
return Printable.PAGE_EXISTS;
}
});
boolean ok = job.printDialog();
if(ok){
try{
job.print();
}
catch (PrinterException ex){}
}
I have tried contentPane.print(); as well as contentPane.printall(); Also commented the g2.scale to see what happeneds
Still prints a blank page?
Any idea's or suggestions. I am still learning Java so be easy on me lol