I can not print a thermal receipt beyond (almost) A4 height paper size. Program only prints till (some default almost) A4 size is reached. and rest of receipt is lost.
everything works fine with smaller receipts. problem occurs only with long receipts, where bill is cut short.
I dynamically set paper height counting the lines to print. I also tried setting paper size and imageablearea to big size manually but in vain.
I tried to use Print.Book class object as well with no improvement.
(Note: Another program written in another language, prints same bill fine on same printer)
please let me know if I am missing something or how to remove this limitation. I would appreciate urgent response.
public void printReciept()
{
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPrintable(new BillPrintable(),getPageFormat(pj));
try {
pj.print();
}
catch (PrinterException ex) {
ex.printStackTrace();
}
}
public PageFormat getPageFormat(PrinterJob pj)
{
PageFormat pf = pj.defaultPage();
Paper paper = pf.getPaper();
double middleHeight =this.productList.size()*1.0; //dynamic----->change with the row count of jtable
double headerHeight = 5.0; //fixed----->but can be mod
double footerHeight = 5.0; //fixed----->but can be mod
double width = convert_CM_To_PPI(8); //printer know only point per inch.default value is 72ppi
double height = convert_CM_To_PPI(headerHeight+middleHeight+footerHeight);
paper.setSize(width, height);
paper.setImageableArea(
0,
10,
width,
height - convert_CM_To_PPI(1)
); //define boarder size after that print area width is about 180 points
pf.setOrientation(PageFormat.PORTRAIT); //select orientation portrait or landscape but for this time portrait
pf.setPaper(paper);
return pf;
}
public class BillPrintable implements Printable {
@Override
public int print(Graphics graphics, PageFormat pageFormat,int pageIndex)
throws PrinterException
{
String title[] = {"Product Name","Disc","Rate","Qty","AMT"};
int result = NO_SUCH_PAGE;
if (pageIndex == 0) {
Graphics2D g2d = (Graphics2D) graphics;
g2d.translate((int) pageFormat.getImageableX(),(int) pageFormat.getImageableY());
***** Below will be Code to print bill records *****
}
}