How to get all available Paper Feeds and how to change it in NSPrintInfo obj

与世无争的帅哥 提交于 2021-02-11 04:31:28

问题


I'm trying to set the paper feed in a NSPrintInfo object

By now, I'm obtaining the paper feed options (from now on trays) from an IPP call

ipp_t *request;

request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, printer_uri);
respose = cupsDoRequest(http, request, "/");
...

string trays = ippGetString(ippFindAttribute(response, "media-source-supported", IPP_TAG_KEYWORD), 0, NULL);

This returns me a comma-separated string with the trays of the printer, for example: auto,top,manual,tray-1

Question 1: Is there other way to get supported trays from a given printer? (If the text is localized, would be better)

After this, to set the paper feed into the NSPrintInfo object, what I've tried is:

Option 1

NSPrintInfo *printInfo; 
// Initialization of printInfo and others...
PMPrintSettingsSetValue([printInfo PMPrintSettings], kPMPrimaryPaperFeedKey, (__bridge CFTypeRef _Nullable)(@<TRAY INDEX>), false);

The problem with this, is that I don't know what index tray is. I've supposed a relation between the IPP output, and a 0-index array (0=auto, 1=top, 2=manual, 3=tray-1), so I've putted the IPP output into an ordered array, but it doesn't work.

Option 2

NSPrintInfo *printInfo;
// Initialization of printInfo and others...
[[printInfo printSettings]setObject:@"<TRAY NAME>", forKey:@"InputSlot"];

The problem with this is that I couldn't get the "right" tray string to put on (See screenshot image)

As you can see, there is no relation between the IPP output, the localized text (in the printer dialog) and what the printer dialog writes into the NSPrintInfo (The equivalence is top = Cassette = Upper)

(NOTE I have to do this by code, I can't use any OS dialog)

来源:https://stackoverflow.com/questions/60196454/how-to-get-all-available-paper-feeds-and-how-to-change-it-in-nsprintinfo-obj

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!