title: How to print the receipt in java whose size is more than A4 paper height?(POS-Printer)
body: <p>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)</p>
  
  <pre><code>    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 &amp; 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;
      }
  </code></pre>
  
  <p>Configuration method is:</p>
  
  <pre><code>    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();
  }
  </code></pre>