[cups-devel] how to get supported media information for a particular printer

Michael Sweet msweet at apple.com
Wed Nov 1 10:57:13 PDT 2017


Only CUPS 2.2.x and later provides localizations for media-source, and any vendor-specific values (like those below) MUST have a corresponding localization file from the printer.  Otherwise you just get the original string back...

FWIW, "1-tray" (and similar) is not a valid PWG media source name - the correct name is "tray-1", "tray-2", etc., which *will* be localized by CUPS.

The "printer-resolution" attribute/option provides the printer's hardware resolution, but that is typically overridden by "print-quality" (CUPS_PRINT_QUALITY) when processing a job.  And there are other resolution attributes that get used for raster printers that tell the Client what resolutions are supported in image data sent to the printer (typically lower than the hardware resolution).


> On Oct 6, 2017, at 1:07 AM, My Sadhukhan <psadhukhan at gmail.com> wrote:
> 
> I could find a way to get the media source via cupsFindDestSupported()
> ------------
> ipp_attribute_t *mediasource = cupsFindDestSupported(http, dest, info, CUPS_MEDIA_SOURCE);
>     count = ippGetCount(mediasource);
>     printf("media source count %d %s\n", count, cupsLastErrorString());
>     for (int i = 0; i < count; i++) {
>         const char *tray = ippGetString(mediasource, i, NULL);
>         printf("%s:\n", tray);
>         printf("%s:\n", cupsLocalizeDestValue(http, dest, info, CUPS_MEDIA_SOURCE, tray));
>     }
> -------
> but it gave (ie ippGetString and cupsLocalizeDestValue give same name)
> multi-tray:
> multi-tray:
> 1-tray:
> 1-tray:
> 2-tray:
> 2-tray:
> 3-tray:
> 3-tray:
> 4-tray:
> 4-tray:
> 5-tray:
> 5-tray:
> auto:
> auto:
> 
> whereas from ppd, we used to get (where 1st is human-readable name, 2nd is machine readable name). Is there anyway, we could obtain the same via cups API?
> Bypass Tray
> MultiTray
> Tray 1
> 1Tray
> Tray 2
> 2Tray
> Tray 3
> 3Tray
> Tray 4
> 4Tray
> Large Capacity Tray
> 5Tray
> Auto Select
> Auto
> 
> Also, is there any way to find the printer supported resolution (like 600 dpi or 300x300 dpi)?  I tried the following but it gave only CUPS_PRINT_QUALITY_NORMAL and not a "dpi" value.
> 
>     ipp_attribute_t *resolution = cupsFindDestSupported(http, dest, info, CUPS_PRINT_QUALITY);
>     count = ippGetCount(resolution);
>     printf("resolution count %d %s\n", count, cupsLastErrorString());
>     for (int i = 0; i < count; i++) {
>         int quality = ippGetInteger(resolution, i);
>         printf("%d:\n", quality);
>         //printf("%s:\n", cupsLocalizeDestValue(http, dest, info, CUPS_PRINT_QUALITY, quality));
>     }
> 
> On Thu, Oct 5, 2017 at 10:49 AM, My Sadhukhan <psadhukhan at gmail.com <mailto:psadhukhan at gmail.com>> wrote:
> 
> 
> 
> On Thu, Oct 5, 2017 at 5:40 AM, Michael Sweet <msweet at apple.com <mailto:msweet at apple.com>> wrote:
> 
> > On Oct 4, 2017, at 5:59 AM, My Sadhukhan <psadhukhan at gmail.com <mailto:psadhukhan at gmail.com>> wrote:
> >
> > Thanks for the info.
> > It seems, I need to use CUPS_DEST_FLAGS_NONE for cupsConnectDest() where the connection is made to the CUPS scheduler
> > and not CUPS_DEST_FLAGS_DEVICE which connect directly to the device associated with the destination (as CUPS_DEST_FLAGS_DEVICE is not supported prior to 2.2.4)
> 
> Right, connecting to the device is a new feature.
> 
> > Also, when I use cupsGetDestMediaCount(http, dest, info, CUPS_MEDIA_FLAGS_READY); I was getting "media count" as 0
> 
> This is because CUPS currently does not track ready media (values are typically stale), which is why CUPS_DEST_FLAGS_DEVICE was added.
> 
> > and it only works if I specify CUPS_MEDIA_FLAGS_DEFAULT (or CUPS_MEDIA_FLAGS_EXACT) and the obtained media count is 2580 as can be seen here
> > http://cr.openjdk.java.net/~psadhukhan/cups-media-log.txt <http://cr.openjdk.java.net/%7Epsadhukhan/cups-media-log.txt>
> >
> > It seems most of the media information is duplicated around 100 times.
> 
> That depends on the printer, but basically the full list of media describes all of the different supported combinations of size, source, type, and margins.
> 
> I could only get size & margins
> struct cups_size_s {
>     char media[128];
>     int width, length, bottom, left, right, top;
> }; 
> How to get source & type?
> 
> 
> > 1.
> > Is there anyway we could get unique media size entry?
> 
> Media information goes well beyond size.  If you want to limit your UI to media sizes only (not recommended!), you'll need to make your own unique list from the full one.
> 
> For many media like Letter/A4/A3 etc, we get same localized name via cupsLocalizeDestMedia even though margins are different (as seen below) whereas via ppd, we used to get 
> 
> Letter and Letter.FullBleed media names, so if user would like to print in borderless letter, there is no way to specify this now via CUPS, is that so?
> 
> Letter:
> na_letter_8.5x11in:
>    Width: 8.50in
>    Length: 10.99in
>    Bottom: 0.00in
>    Left: 0.00in
>    Right: 0.00in
>    Top: 0.00in
> 
> Letter:
> na_letter_8.5x11in:
>    Width: 8.50in
>    Length: 11.00in
>    Bottom: 0.17in
>    Left: 0.17in
>    Right: 0.17in
>    Top: 0.17in
> 
> 
>  
> 
> >  From ppd file below, I could get that we support around 60 media size(s) [30 normal, 30 fullbleed] so I would expect cups api also would give around 60 media information (and not 2500+)
> 
> Keep in mind that CUPS is an IPP implementation and exposes the flexibility of IPP wherever possible.  The current use of PPD files is an implementation artifact, and you shouldn't expect CUPS to be limited to what is supported in PPD files.
> 
> > 2.
> > By using
> > ppd_option_t *ppdFindOption("PageSize"); and
> > then from ppd_option_t*, using ppd_choice_t->text.
> > we could get the user-understandable media name
> >
> > A3  A4  A5 A6  B4 (JIS) B5 (JIS) B6 (JIS)  Legal
> >  8.25x14 8x10  8x10.5  Letter etc
> > which normal user can use to specify which media he wants to print
> >
> > but from cups api using cups_size_t->media, we are getting
> > iso_a3_297x420mm
> > iso_a4_210x297mm
> > Is there anyway, we can get the same human understandable media name from cups?
> 
> The cupsLocalizeDestMedia function will give you a human-readable media size name.
> 
> _________________________________________________________
> Michael Sweet, Senior Printing System Engineer
> 
> 
> 

_________________________________________________________
Michael Sweet, Senior Printing System Engineer



More information about the cups-devel mailing list