How to print the receipt in java whose size is more than A4 paper height?(POS-Printer)

1.2k views Asked by At

Here I have to work on pageIndex but not getting how to set it, so that I could print the long receipt whose size is more than A4 paper height in POS-Printer(paper roll)

    public int print(Graphics g, PageFormat pf, int pageIndex) {
    PrinterJob pj = PrinterJob.getPrinterJob();
    pf1 = pj.getPageFormat(attr_set);
    if (pageIndex != 0) {
        return NO_SUCH_PAGE;
    }
    attr_set.add(res);
    g2 = (Graphics2D) g;
    //initialising X & Y coordinates
    int x_header = 20;
    int y_header = 0;

    Easy.log("In Print method--------------------------------------");

    //call the method which will print header
    if (printData == 1) {  //this will print KOT
        pageWidth = (float) pf1.getImageableWidth();
        y_header=printKOTDetails(x_header,y_header);
    }
     return PAGE_EXISTS;
    }

Configuration method is:

    private void printerConfiguration() throws PrinterException {

    PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
    PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
    Media res = (Media) defaultPrintService.getDefaultAttributeValue(Media.class);
    PrintRequestAttributeSet attr_set = new HashPrintRequestAttributeSet();
    attr_set.add(res);

    PrinterJob pj = PrinterJob.getPrinterJob();
    pf1 = pj.getPageFormat(attr_set);
    pj.setPrintService(printService);

    Paper paper = new Paper();
    double margin = 2;

    paper.setImageableArea(margin, 0, paper.getImageableWidth(), paper.getImageableHeight());
    pf1.setPaper(paper);

    pj.setPrintable(this, pf1);
    pj.print();
}
0

There are 0 answers