如何使用Java API设置打印副本和打印范围?

时间:2019-01-14 10:55:41

标签: java

我发现PageRanges对象和Copies对象无法设置打印副本和打印范围。我该如何修改

PrinterJob job = PrinterJob.getPrinterJob();

job.setPrintService(defaultService);

PageFormat pageFormat = new PageFormat();

Paper paper = new Paper();

Double width = 60;
Double height = 210;

Double realWidth = UnitConv.mm2pt(width);
Double realHeight = UnitConv.mm2pt(height);

paper.setSize(realWidth, realHeight);

Double marginTop = UnitConv.mm2pt(0);
Double marginLeft = UnitConv.mm2pt(0);

paper.setImageableArea(marginLeft, marginTop, realWidth, realHeight);

pageFormat.setOrientation(1);

pageFormat.setPaper(paper);

Book book = new Book();
book.append(printable, pageFormat);
job.setPageable(book);


PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();

PageRanges pageRanges = new PageRanges(1, 10);
pras.add(pageRanges);
pras.add(new Copies(4));
pras.add(PrintQuality.HIGH);

job.print(pras);

我尝试调试,但是很容易丢失。

0 个答案:

没有答案