Setting Chromaticity.MONOCHROME print request attribute on macOS

Alexander Scherbatiy alexander.scherbatiy at bell-sw.com
Wed Mar 13 14:20:23 UTC 2024


Hello,

There is a known issue that a PrinterJob does not take 
Chromaticity.MONOCHROME print request attribute into account on macOS 
(JDK-8315113 [1])

The possible ways for solving the issue with black & white printing on 
macOS could be:

1. Setting black & white printing with macOS API.

    There is the deprecated PMSetColorMode [2] function:
    "There is no replacement; this function was included to facilitate 
porting legacy applications to macOS, but it serves no useful purpose."
    and I was not able to find another one.

2. Using a predefined printer.properties file with black & white 
key/value pairs for known printers.
     It needs to maintain the property file to keep list with black & 
white key/value pairs.
     Or just leave only one default  ColorModel=Gray key/value in the 
property file so users will need to add another ones for their needs.

3. Using a PPD API to get the corresponding black & white value for the 
given key.
     In this way the black & white keys are printer specific and there 
should be a way to provide these keys to the program.
     Another way is parsing a ppd file to find the black & white 
key/value pair in question. It still requires some search criteria to 
find the printer specific key.

4. Adding a custom PrintRequestAttribute which allows for a user to add 
a printer specific key values to PrintRequestAttributeSet.
      These key/value pairs are then added to the NSPrintInfo 
printSettings on macOS.

5. Providing other ways like a jvm option which allows a user to pass 
black & white key/value pairs to the program.


Are there better solutions for the black & white printing issue on macOS?
What is the best option to start solving the issue with?

Thanks,
Alexander.

[1] https://bugs.openjdk.org/browse/JDK-8315113

[2] 
https://developer.apple.com/documentation/applicationservices/core_printing/1805783-pmsetcolormode


On 8/28/23 18:00, Alexander Scherbatiy wrote:
> Hello,
>
> I am working on issue "8315113 Print request Chromaticity.MONOCHROME 
> attribute does not work on macOS" [1].
>
> There is PMSetColorMode function in the Apple Developer documentation 
> [2] but it is marked as deprecated
>   "There is no replacement; this function was included to facilitate 
> porting legacy applications to macOS, but it serves no useful purpose."
> and really does nothing.
>
>
> Using native print dialog and selecting Black & White box allows to 
> print black and white pages on macOS.
> I dumped NSPrintInfo print settings dictionary for two printers when 
> the Black & White box is selected and the logs contain
> ColorModel key, Gray value for HP ColorLaserJet MFP M178-M181-AirPrint 
> printer and
> HPColorMode key, grayscale value for HP Ink Tank 115.
> It looks like each printer can have each own key/value for Black & 
> White settings.
>
> I tried to print key/values for all presets available for NSPrintInfo 
> without using the native print dialog:
> ----------
>     PMPrinter pr;
>     PMPrintSession printSession = (PMPrintSession)[printInfo 
> PMPrintSession];
>     OSStatus status = PMSessionGetCurrentPrinter(printSession, &pr);
>     CFArrayRef presetsList = nil;
>     status = PMPrinterCopyPresets(pr, &presetsList);
>     CFIndex arrayCount = CFArrayGetCount(presetsList);
>
>     for (CFIndex index = 0; index < arrayCount; index++) {
>         PMPreset preset = 
> (PMPreset)CFArrayGetValueAtIndex(presetsList, index);
>         CFStringRef presetName = nil;
>         if (PMPresetCopyName(preset, &presetName) == noErr && 
> CFStringGetLength(presetName) > 0) {
>             NSLog(@"  presetName: '%@'", presetName);
>             NSDictionary* dict = nil;
>             if (PMPresetGetAttributes(preset, 
> (CFDictionaryRef*)(&dict)) == noErr) {
>                    // print preset dict
>
> ----------
> The printers which I tested do contain "Black and White" preset but 
> they do not include key/values related to black and white printing.
>
>
> What is the right way to use different key/values (ColorModel: Gray, 
> HPColorMode: grayscale, ...) in code to set Black & White settings for 
> NSPrintInfo?
> Could it be a configuration file which contains all color model 
> key/values for all known printers?
>
> Thanks,
> Alexander.
>
> [1] https://bugs.openjdk.org/browse/JDK-8315113
>
> [2] 
> https://developer.apple.com/documentation/applicationservices/core_printing/1805783-pmsetcolormode
>
>


More information about the client-libs-dev mailing list