On Tue, 18 Nov 2025 15:01:14 GMT, Christian Heilmann <[email protected]> wrote:
>> This PR fixes a bug that caused no or the wrong set of pages to be printed >> when using page ranges on macOS. >> >> The main fix is to change the 'location' value of the returned NSRange from >> the knowsPageRange method to 1 in the native class PrinterView.m. > > Christian Heilmann has updated the pull request incrementally with three > additional commits since the last revision: > > - Update PrinterView.m > - Update PrinterView.h > - Update CPrinterJob.m Let me add links to the Apple documentation. https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Printing/osxp_pagination/osxp_pagination.html#//apple_ref/doc/uid/20001051-119382-BBCEGCBI - Custom Pagination. https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Printing/osxp_printapps/osxp_printapps.html#//apple_ref/doc/uid/20000861-SW1 - Customizing Content for the Printed Page (NSView). Java uses the NSView to print documents, NSView is a reflection of a printing document (OpenBook or another class that extends Pageable interface). The "(BOOL) knowsPageRange:(NSRangePointer) range;" method returns TRUE if we know the document size (the Pageable.getNumberOfPages() method returns the number of pages) or FALSE if we don't know the size of the document (the Pageable.getNumberOfPages() returns UNKNOWN_NUMBER_OF_PAGES). NSView's page numbers are one-based — that is, pages run from 1 to N, so if the Pageable.getNumberOfPages() returned, for example, 10, then we should set NSRange->location = 1 and NSRange->length = 10. As described in the Apple documentation, "The printing system sends a rectForPage: message to your app before each page is printed, base on the range of pages the user selects in the Print panel". The range of pages the user selected in the Print panel is not the same range as the knowsPageRange. This is an instance of the PageRanges.class from the PrintRequestAttributeSet (a user's selection from the print dialog). I assume that "knowsPageRange" is the size of the whole document, and that printingDictionary's NSPrintFirstPage and NSPrintLastPage is the printing range of the document the user selected. ------------- PR Comment: https://git.openjdk.org/jdk/pull/11266#issuecomment-3562280885
