objective-c - 如何使用 CUPS 查找打印机 URI

标签 objective-c c operating-system printers systems-programming

有人知道使用 CUPS API 获取打印机 URI 吗?

如果没有,有谁知道我在哪里可以找到可以传递给 cupsGetOption 函数 的允许选项列表。

现在我只能找到printer-info, printer-location, printer-make-and-model

最佳答案

您可能正在寻找的是“device-uri”。这是远程设备的 uri,即 lpd/socket/server 地址。如果您正在寻找本地 uri,它将是“printer-uri-supported”,这将导致 ipp://localhost:631/printers/printername。这是获取远程 uri 的方法...

#import <cups/cups.h>

const char * printer = "name_of_printer";
int num_dests;
cups_dest_t *dest,
            *dests;

const char *value;

num_dests = cupsGetDests(&dests);
dest = cupsGetDest(printer, NULL, num_dests, dests);
if( dest == NULL){
    return 0;
};
value = NULL;

if (dest->instance == NULL)
{
    value = cupsGetOption("device-uri", dest->num_options, dest->options);
}

cupsFreeDests(num_dests, dests);
printf("uri - %s",value);

关于objective-c - 如何使用 CUPS 查找打印机 URI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17662355/

相关文章:

c - 在 C 中从 stdin 读取行到二维数组而不知道行的长度

c - 什么是分段核心转储?我该如何解决它?

c++ - 我在哪里可以学习如何使 C++ 程序与操作系统 (Linux) 交互

javascript - iOS/Android 检测和重定向

iphone - iPhone SDK 中的透明按钮

objective-c - Block 如何捕获其封闭范围之外的变量?

iphone - 如何使 icon.png 显示在旧 iphone 上,而 icon@2x.png 显示在较新的 iPhone 上?

ios - View Controller 中的两个 TextField 设置为委托(delegate),导致应用程序因 NSRange、范围或索引超出范围而崩溃

ios - 带日期选择器的 UITextView

c - 在 C 中让一个函数运行特定的时间