Hey there im making an Invoice software Everything is fine just the problem is when my report is printing this is printed according to the standard printer but i want to print it through billing receipt printer
@Override
public int print(Graphics g, PageFormat format, int page_index)
throws PrinterException {
if (page_index > 0) {
return Printable.NO_SUCH_PAGE;
}
// get the bounds of the component
Dimension dim = comp.getSize();
double cHeight = dim.getHeight();
double cWidth = dim.getWidth();
// get the bounds of the printable area
double pHeight = format.getImageableHeight();
double pWidth = format.getImageableWidth();
double pXStart = format.getImageableX();
double pYStart = format.getImageableY();
double xRatio = pWidth / cWidth;
double yRatio = pHeight / cHeight;
Graphics2D g2 = (Graphics2D) g;
g2.translate(pXStart, pYStart);
g2.scale(xRatio, yRatio);
comp.paint(g2);
return Printable.PAGE_EXISTS;
}
public static void printing(){
PrinterJob pjob = PrinterJob.getPrinterJob();
PageFormat preformat = pjob.defaultPage();
preformat.setOrientation(PageFormat.PORTRAIT);
PageFormat postformat = pjob.defaultPage();
//If user does not hit cancel then print.
if (preformat != postformat) {
//Set print component
pjob.setPrintable(new reporting(frame), postformat);
// if (pjob.printDialog()) {
try {
pjob.print();
frame.dispose();
} catch (PrinterException ex) {
Logger.getLogger(reporting.class.getName()).log(Level.SEVERE, null, ex);
}
//}
//}
}
}
This code is printing my reciept but this is printing according to the standard printer and as i want to print it through billing printer and im not using jesper report to print it im jsut directly printing my jframe help? thankx in advance