Determining if a printer is capable of color output.
Q: How do I determine if the current printer can print in color?
A: How do I determine if the current printer can print in color?
It is not possible to definitively determine if a printer can print in color. You can determine if a PPD declares the associated printer as color capable, but a PPD is not required to declare this. Alternatively a printer can be capable of color, but placed in grayscale mode by the user. Finally, it is not generally possible to determine if a non-color printer can produce grayscale output.
You can determine if the PPD believes that the printer is capable of color by looking for the *ColorDevice keyword in the printer's PPD file. Printer Dialog Extensions (PDEs) may retrieve the corresponding PPD for the current printer by using the -ppdFile
method of the callback object they are given when initialized. CUPS filters can obtain the path to the PPD file for the current printer from the PPD
environment variable.
Listing 1 below shows how to do this from an application's perspective.
If you are using color support to influence how to render printed output, you should always provide a method for the user to override your initial selection.
Listing 1 Determining if a PPD declares a ColorDevice
bool isPrinterColor(PMPrinter printer) { bool isColor = true; CFURLRef ppdURL = NULL; OSStatus err = PMPrinterCopyDescriptionURL(printer, kPMPPDDescriptionType, &ppdURL); if((err == noErr) && (ppdURL != NULL)) { char ppdPath[MAXPATHLEN]; if(CFURLGetFileSystemRepresentation(ppdURL, true, (UInt8*)ppdPath, sizeof(ppdPath))) { ppd_file_t *ppd = ppdOpenFile(ppdPath); if(ppd != NULL) { ppd_attr_t *attr = ppdFindAttr(ppd, "ColorDevice", NULL); if((attr != NULL) && (attr->value != NULL)) { isColor = ppd->color_device; } ppdClose(ppd); } } CFRelease(ppdURL); } return isColor; } |
Cocoa applications should use NSPrintInfo's PMPrintSession
method to obtain a PMPrintSession, then call PMSessionGetCurrentPrinter
to get the PMPrinter reference needed for isPrinterColor
above.
Document Revision History
Date | Notes |
---|---|
2009-09-24 | New document that describes a heuristic that you can use to determine if a printer supports color output. |
Copyright © 2009 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2009-09-24