如何用java打印尺寸大于A4纸高的收据?(POS打印机)

如何用java打印尺寸大于A4纸高的收据?(POS打印机),java,printing,java-print,Java,Printing,Java Print,在这里,我必须处理pageIndex,但不知道如何设置它,这样我就可以在POS打印机(纸卷)上打印尺寸超过A4纸张高度的长收据 配置方法为: private void printerConfiguration() throws PrinterException { PrintService printService = PrintServiceLookup.lookupDefaultPrintService(); PrintService defaultPrintSer

在这里,我必须处理pageIndex,但不知道如何设置它,这样我就可以在POS打印机(纸卷)上打印尺寸超过A4纸张高度的长收据

配置方法为:

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

而不是依赖于
pageIndex
,维护关于您打印了多少内容的信息,以及当您打印的内容用完时,发回
NO\u这样的页面
。。。但请记住,您可能会被要求多次打印一页。此外,您应该使用
pageIndex
来决定您的当前位置printing@MadProgrammer但是pos打印机驱动程序处理了这个问题。比如,如果只打印4行,它将只打印4行&然后撕开页面。除此之外还有别的办法吗?难道不能用pageIndex来完成吗?不太可能,我可以考虑一下。您可以尝试将页面高度设置为所需的长度。但是请记住,打印API通常在72dpiOkie上工作。那我就走那条路。计算打印多少的好方法?
    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();
}