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


Reply via email to