RFR: 8297191: [macos] printing page range "page 2 to 2" or "page 2 to 4" on macOS leads to not print [v2]

Prasanta Sadhukhan psadhukhan at openjdk.org
Fri Sep 12 08:42:55 UTC 2025


On Fri, 18 Jul 2025 13:19:10 GMT, Christian Heilmann <duke at openjdk.org> 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 with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains five additional commits since the last revision:
> 
>  - 8297191 fixed printing page range for e.g. page 2 to 2 on macOS
>  - 8297191 fixed printing page range for e.g. page 2 to 2 on macOS
>  - Merge branch 'master' of https://github.com/openjdk/jdk into pr/11266
>  - Merge branch 'master' into pr/11266
>  - 8297191 fixed printing page range for e.g. page 2 to 2 on macOS

> In CPrinterJob there is a method called javaPrinterJobToNSPrintInfo() This is invoked from within the printing loop and has this code
> 
> ```
> [printingDictionary setObject:[NSNumber numberWithInteger:fromPage] forKey:NSPrintFirstPage];
> [printingDictionary setObject:[NSNumber numberWithInteger:toPage] forKey:NSPrintLastPage];
> ```

> So deleting/commenting out these lines
> [printingDictionary setObject:[NSNumber numberWithInteger:fromPage] forKey:NSPrintFirstPage];
> [printingDictionary setObject:[NSNumber numberWithInteger:toPage] forKey:NSPrintLastPage];
> and ensuring we always set
> [printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintAllPages];
> Also fixes this bug.

There is some issue with using `NSPrintAllPages`. If the number of pages to be printed is 0 i.e, `Pageable.getNumberOfPages()` is 0 and we made `[printingDictionary setObject:[NSNumber numberWithBool:NO] forKey:NSPrintAllPages];` it still selects "All Pages" option and doesn't disable the Page Ranges option
Also, if we want to have `Pageable.getNumberOfPages()` 2 i.e, fromPage 1 to toPage 2 and do

 [printingDictionary setObject:[NSNumber numberWithBool:NO] forKey:NSPrintAllPages];
 [printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintSelectionOnly];

it does not select any of the radiobutton and Page Ranges still has 1 to 1 despite firsPage and toPage is correctly being passed as 1 and 2 to printingDictionary
It can be seen with test` java/awt/print/Dialog/PrintDlgPageable.java`..Not sure if it's an Apple bug..

-------------

PR Comment: https://git.openjdk.org/jdk/pull/11266#issuecomment-3284327405


More information about the client-libs-dev mailing list