0

ここでは、pageIndex で作業する必要がありますが、設定方法を取得していないため、サイズが A4 用紙の高さを超える長いレシートを POS-Printer (ロール紙) で印刷できます。

    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;
    }

構成方法は次のとおりです。

    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();
}
4

0 に答える 0