RFR: 8297191: [macos] printing page range "page 2 to 2" or "page 2 to 4" on macOS leads to not print [v2]
eduardsdv
duke at openjdk.org
Fri Oct 17 10:26:40 UTC 2025
On Wed, 3 Sep 2025 01:41:44 GMT, Phil Race <prr at openjdk.org> wrote:
> So what I think happens is we are setting a range within a range.
I agree with @prrace's assumption.
I temporary changed the CPrinterJob.m and PrinterView.m files to use fix values.
The PrinterView.knowsPageRanges() method returned the range with location=2 and length=4.
The CPrinterJob.javaPrinterJobToNSPrintInfo() method used the fromPage and toPage values from the table below.
I tested it with a Java program (see the code block below), which always returned 5 when calling Pageable.getNumberOfPages().
Pageable.getNumberOfPages() |knowsPageRanges()| javaPrinterJobToNSPrintInfo() | printed pages |
|--|---|-----------------|-----------------------------|
|numberOfPages=5|location=2, length=4|fromPage=1, toPage=1| 2|
|numberOfPages=5|location=2, length=4|fromPage=1, toPage=5|2, 3, 4, 5|
|numberOfPages=5|location=2, length=4|fromPage=5, toPage=5| nothing |
|numberOfPages=5|location=2, length=4|fromPage=3, toPage=6| 4, 5 |
In my opinion, the fix is correct, and we still need the `knowsPageRanges()` method, which returns the range of available pages with location=1 and length=Pageable.getNumberOfPages(). Then, the `javaPrinterJobToNSPrintInfo()` method can process the page range that will actually be printed.
public class PageRanges {
public static final int PAGES_COUNT = 5;
public static void main(String args[]) throws Exception {
PrinterJob job = PrinterJob.getPrinterJob();
if (job.getPrintService() == null) {
System.out.println("No printers. Test cannot continue.");
return;
}
Printable printable = (g, pf, pi) -> {
if (pi >= PAGES_COUNT) {
return Printable.NO_SUCH_PAGE;
}
g.drawString("Page : " + (pi+1), 200, 200);
return Printable.PAGE_EXISTS;
};
job.setPageable(new Pageable() {
@Override
public int getNumberOfPages() {
return PAGES_COUNT;
}
@Override
public PageFormat getPageFormat(int pageIndex) throws IndexOutOfBoundsException {
return new PageFormat();
}
@Override
public Printable getPrintable(int pageIndex) throws IndexOutOfBoundsException {
return printable;
}
});
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
attributes.add(DialogTypeSelection.NATIVE);
if (!job.printDialog(attributes)) {
return;
}
job.print(attributes);
}
}
-------------
PR Comment: https://git.openjdk.org/jdk/pull/11266#issuecomment-3414847846
More information about the client-libs-dev
mailing list