Is this the best way to get the size of a Paper via CUPS?
I've got a CUPS job control file (these can be found at /var/spool/cups/cnnnnn). I need to get the actual dimensions of the print that was made.
This is the way I've figured out to do it:
- Get the paper name using the
media
attribute. (e.g.Letter
) 开发者_开发技巧 - Get the printer uri from the
printer-uri
attribute. (e.g.ipp://localhost/printers/MyPrinter
) - Get the printer name by passing the printer uri to the
IPP_GET_PRINTER_ATTRIBUTES
operation and getting theprinter-name
attribute. (e.g.MyPrinter
) - Get the path to the PPD passing the printer name to the the
cupsGetPPD
method. - Open the PPD passing the path to the PPD to the
ppdOpenFile
method. - Get the paper size by passing the PPD and paper name to the
ppdPageSize
method.
This will work, but it seems a bit roundabout. Is there a more efficient way of getting what I need?
The job control file will contain all the job options of the file used for printing. There are 3 types of job options:
- ones which were specifically and explicitely selected by the user on the commandline or by clicking some GUI elements (these ones will appear in the control files);
- ones which were implicitely set because they are contained in and read from a user-specific
~/.lpoptions
or a system-wide/etc/cups/lpoptions
file (the user specific file has been migrated to~/.cups/lpoptions
in more recent versions of CUPS (these ones will also appear in the control files); - ones which were added by CUPS by parsing the PPD and looking for default settings contained there (these ones will not appear in the control files, since CUPS only evaluates them in the moment the job is processed -- which may be 2 days in the future if you used
-o job-hold-until=indefinite
.
If you know the printqueuename and the cupsserver used, you can query the default queue settings for that combo with these two commands:
lpoptions -h cupsserver \
-U username \
-d printqueuename
This will return all current settings as noted in the (.)loptions
file(s).
lpoptions -h cupsserver \
-U username \
-d printqueuename \
-l
This will return all user-selectable settings contained in the PPD. Note how the asterisks *
marks the default setting for each option. Also note that -U username
is significant here -- different users may use different default settings...
Now watch out for the results of these commands noting the PageSize
used...
You can actually use the CUPS_GET_PPD request to get the ppd directly instead of steps 3 and 4. This seems more efficient.
精彩评论