使用 PyCups 获取可用的打印机托盘

Getting available printer trays with PyCups

我正在尝试检索可用于打印机的所有纸盘,但找不到检索可用纸盘列表的方法。

这就是我获得打印机的方式:

>>> import cups
>>> conn = cups.Connection ()
>>> printers = conn.getPrinters ()
>>> for printer in printers:
...     print printer, printers[printer]["device-uri"]
Brother_MFC_1910W_series
Photosmart_6520_series

它工作得很好,但 printers 中没有关于托盘的信息。非常感谢任何帮助或参考。

郑重声明,我正在研究 OS X。

经过几次尝试,这就是我为获得托盘所做的工作。

对于我找到的每台打印机,我都在 /etc/cups/ppd/ 中查找 printer_name.ppd 文件,我可以在其中找到我需要的托盘的所有详细信息。

它也很有用,因为我可以获得 PPD 文件中支持的每种语言的托盘。

跟进接受的答案:

由于 PPD 文件需要超级用户权限才能读取,因此使用 PyCUPS 访问它们的简单方法如下:

>>> import cups
>>> conn = cups.Connection()
>>> ppd = conn.getPPD('Brother_MFC_1910W_series')  # Your desired printer's name
>>> print(ppd)  # returns a filename of a temporary file with the PPD
'/tmp/576b35f2620f5'
>>> ppd_file = open(ppd)
>>> print(ppd_file.read())