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

My Sadhukhan psadhukhan at gmail.com
Wed Oct 4 02:59:12 PDT 2017


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)
Also, when I use cupsGetDestMediaCount(http, dest, info,
CUPS_MEDIA_FLAGS_READY); I was getting "media count" as 0
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

It seems most of the media information is duplicated around 100 times.

1.
Is there anyway we could get unique media size entry?

 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+)

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
<https://www.cups.org/doc/cupspm.html#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?

[obtained from Ricoh.ppd]
*%========== Information About Media Sizes ==========

*DefaultImageableArea: A4
*ImageableArea A3/A3: "12 12 830 1179"
*ImageableArea A4/A4: "12 12 583 830"
*ImageableArea A5/A5: "12 12 408 583"
*ImageableArea A6/A6: "12 12 285 408"
*ImageableArea B4/B4 (JIS): "12 12 717 1020"
*ImageableArea B5/B5 (JIS): "12 12 504 717"
*ImageableArea B6/B6 (JIS): "12 12 351 504"
*ImageableArea Legal/Legal: "12 12 600 996"
*ImageableArea GovernmentLG/8.25x14: "12 12 582 996"
*ImageableArea EngQuatro/8x10: "12 12 564 708"
*ImageableArea GLT/8x10.5: "12 12 564 744"
*ImageableArea Letter/Letter: "12 12 600 780"
*ImageableArea Statement/5.5x8.5: "12 12 384 600"
*ImageableArea F/8x13: "12 12 564 924"
*ImageableArea Folio/8.25x13: "12 12 583 923"
*ImageableArea FanFoldGermanLegal/8.5x13: "12 12 600 924"
*ImageableArea Tabloid/11x17: "12 12 780 1212"
*ImageableArea 12x18/12x18: "12 12 852 1284"
*ImageableArea 11x15/11x15: "12 12 780 1068"
*ImageableArea 10x14/10x14: "12 12 708 996"
*ImageableArea 10x15/10x15: "12 12 708 1068"
*ImageableArea 11x14/11x14: "12 12 780 996"
*ImageableArea Executive/Executive: "12 12 510 744"
*ImageableArea Env10/Com10 Env.: "12 12 285 672"
*ImageableArea EnvMonarch/Monarch Env.: "12 12 267 528"
*ImageableArea EnvC5/C5 Env.: "12 12 447 637"
*ImageableArea EnvC6/C6 Env.: "12 12 311 447"
*ImageableArea DLEnv/DL Env.: "12 12 299 611"
*ImageableArea 8Kai/8K: "12 12 745 1094"
*ImageableArea 16Kai/16K: "12 12 541 745"

*ImageableArea A3.FullBleed/A3 (Full Bleed): "0 0 842 1190"
*ImageableArea A4.FullBleed/A4 (Full Bleed): "0 0 595 841"
*ImageableArea A5.FullBleed/A5 (Full Bleed): "0 0 420 594"
*ImageableArea A6.FullBleed/A6 (Full Bleed): "0 0 297 419"
*ImageableArea B4.FullBleed/B4 (JIS) (Full Bleed): "0 0 729 1031"
*ImageableArea B5.FullBleed/B5 (JIS) (Full Bleed): "0 0 516 728"
*ImageableArea B6.FullBleed/B6 (JIS) (Full Bleed): "0 0 363 515"
*ImageableArea Legal.FullBleed/Legal (Full Bleed): "0 0 612 1007"
*ImageableArea GovernmentLG.FullBleed/8.25x14 (Full Bleed): "0 0 594 1007"
*ImageableArea EngQuatro.FullBleed/8x10 (Full Bleed): "0 0 576 719"
*ImageableArea GLT.FullBleed/8x10.5 (Full Bleed): "0 0 576 755"
*ImageableArea Letter.FullBleed/Letter (Full Bleed): "0 0 612 791"
*ImageableArea Statement.FullBleed/5.5x8.5 (Full Bleed): "0 0 396 611"
*ImageableArea F.FullBleed/8x13 (Full Bleed): "0 0 576 935"
*ImageableArea Folio.FullBleed/8.25x13 (Full Bleed): "0 0 595 934"
*ImageableArea FanFoldGermanLegal.FullBleed/8.5x13 (Full Bleed): "0 0 612
935"
*ImageableArea Tabloid.FullBleed/11x17 (Full Bleed): "0 0 792 1223"
*ImageableArea 12x18.FullBleed/12x18 (Full Bleed): "0 0 864 1295"
*ImageableArea 11x15.FullBleed/11x15 (Full Bleed): "0 0 792 1079"
*ImageableArea 10x14.FullBleed/10x14 (Full Bleed): "0 0 720 1007"
*ImageableArea 10x15.FullBleed/10x15 (Full Bleed): "0 0 720 1079"
*ImageableArea 11x14.FullBleed/11x14 (Full Bleed): "0 0 792 1007"
*ImageableArea Executive.FullBleed/Executive (Full Bleed): "0 0 522 755"
*ImageableArea Env10.FullBleed/Com10 Env. (Full Bleed): "0 0 297 683"
*ImageableArea EnvMonarch.FullBleed/Monarch Env. (Full Bleed): "0 0 279 539"
*ImageableArea EnvC5.FullBleed/C5 Env. (Full Bleed): "0 0 459 648"
*ImageableArea EnvC6.FullBleed/C6 Env. (Full Bleed): "0 0 323 458"
*ImageableArea DLEnv.FullBleed/DL Env. (Full Bleed): "0 0 311 622"
*ImageableArea 8Kai.FullBleed/8K (Full Bleed): "0 0 757 1105"
*ImageableArea 16Kai.FullBleed/16K (Full Bleed): "0 0 553 756"


On Tue, Oct 3, 2017 at 7:48 PM, Michael Sweet <msweet at apple.com> wrote:

> Some versions of CUPS did not support CUPS_HTTP_DEFAULT for the connection
> argument to the media APIs (bug).
>
> After you call cupsGetNamedDest, call cupsConnectDest to get a http_t for
> the destination and then cupsCopyDestInfo, etc.
>
>
> > On Oct 3, 2017, at 6:03 AM, My Sadhukhan <psadhukhan at gmail.com> wrote:
> >
> > As told, it seems we need to use media-specific APIs like
> cupsGetDestMediaCount to find out how many media-size the printer supports.
> > I tried in that route following the example described in
> https://www.cups.org/doc/cupspm.html#cupsGetDestMediaCount, but still
> finding a problem in ubuntu16.04.
> > It returns supported media count as 0 and when I tried to see if there
> is any error, it says "Invalid argument" for cupsGetDestMediaCount. Any
> idea why?
> >
> >
> > void getMedia(char *name)
> > {
> >     cups_dest_t *dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, name, NULL);
> >     if (dest == NULL) {
> >         printf("cupsGetNamedDest failed %s\n", cupsLastErrorString());
> >         return;
> >     } else {
> >         printf("dest name %s\n", dest->name);
> >     }
> >     cups_dinfo_t *info = cupsCopyDestInfo(CUPS_HTTP_DEFAULT, dest);
> >     if (info == NULL) {
> >         printf("CopyDestInfo Request failed %s\n",
> cupsLastErrorString());
> >     }
> >     int count = cupsGetDestMediaCount(CUPS_HTTP_DEFAULT, dest, info,
> CUPS_MEDIA_FLAGS_READY);
> >     printf("media count %d %s\n", count, cupsLastErrorString());
> >     cups_size_t size;
> >     for (int i = 0; i < count; i++) {
> >         if (cupsGetDestMediaByIndex(CUPS_HTTP_DEFAULT, dest, info,
> >                               i, CUPS_MEDIA_FLAGS_READY,
> >                               &size))
> >         {
> >             printf("%s:\n", size.media);
> >             printf("   Width: %.2fin\n", size.width / 2540.0);
> >             printf("  Length: %.2fin\n", size.length / 2540.0);
> >             printf("  Bottom: %.2fin\n", size.bottom / 2540.0);
> >             printf("    Left: %.2fin\n", size.left / 2540.0);
> >             printf("   Right: %.2fin\n", size.right / 2540.0);
> >             printf("     Top: %.2fin\n", size.top / 2540.0);
> >         }
> >     }
> > }
> >
> > int main(void)
> > {
> >     getMedia("Ricoh-Aficio-MP-5002");
> > }
> >
> > Regards
> > Prasanta
> > On Sun, Aug 20, 2017 at 11:45 PM, Philip Race <philip.race at oracle.com>
> wrote:
> > It seems that the problem with cupsCheckDestSupported was a long
> standing bug
> > that was fixed just 2 months ago .. not supporting a  NULL value !
> > https://github.com/apple/cups/commit/49b6c6af7674e4d37d5cb14385c196
> 18d9c1b668
> > ..
> >
> > What would be the recommended way to workaround that in shipping
> versions of 2.X
> > found on current OSes like Ubuntu 16.10 ?
> >
> >
> > -phil
> >
> > [1] https://www.cups.org/doc/cupspm.html#cupsCheckDestSupported
> >
> >
> > On 8/2/17, 11:18 PM, My Sadhukhan wrote:
> > I also tried with cups 2.2.0 with ubuntu16.10 and there also the
> > cupsCheckDestSupported returns false for all options.
> >
> > On Thu, Aug 3, 2017 at 11:41 AM, My Sadhukhan<psadhukhan at gmail.com>
> wrote:
> >
> > I am using cups 2.1.3 that comes with ubuntu16.04. It should support the
> > non-ppd APIs, I guess, as that was deprecated from 1.6 onwards.
> > Please let me know if this version has any problem regarding the APIs I
> am
> > using.
> >
> > Regards
> > Prasanta
> >
> > On Wed, Aug 2, 2017 at 6:45 PM, Michael Sweet<msweet at apple.com>  wrote:
> >
> > What version of CUPS are you using?
> >
> > (there have been a number of bug fixes over the years...)
> >
> > On Aug 2, 2017, at 1:17 AM, My Sadhukhan<psadhukhan at gmail.com>  wrote:
> >
> > I checked cupsCheckDestSupported() before calling
> > cupsFIndDestSupported()
> > for options like CUPS_COPIES,CUPS_FINISHINGS,CU
> > PS_MEDIA,CUPS_ORIENTATION,
> > CUPS_SIDES etc and all of them return false,
> > although the printer being queried is a MFP and supports duplex,
> > orientation etc and I can print a test-page out of it.
> > Is it a bug in cups or am I missing calling/initialising something?
> >
> > Regards
> > Prasanta
> >
> > On Tue, Aug 1, 2017 at 10:56 AM, My Sadhukhan<psadhukhan at gmail.com>
> > wrote:
> > Thanks Michael.
> > I used cupsGetNamedDest to initialise cups_dest_t but it still fails in
> > cupsFindDestSupported().
> > ----------
> > void getMedia(char *name)
> > {
> >     cups_dest_t *dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, name,
> > NULL);
> >     if (dest == NULL) {
> >         printf("cupsGetNamedDest failed %s\n", cupsLastErrorString());
> >         return;
> >     } else {
> >         printf("dest name %s\n", dest->name);
> >     }
> >     cups_dinfo_t *info = cupsCopyDestInfo(CUPS_HTTP_DEFAULT, dest);
> >     if (info == NULL) {
> >         printf("CopyDestInfo Request failed %s\n",
> > cupsLastErrorString());
> >     }
> >     ipp_attribute_t *media = cupsFindDestSupported(CUPS_HTTP_DEFAULT,
> >                               dest, info, CUPS_MEDIA);
> >     if (media != NULL) {
> >         int i, count = ippGetCount(media);
> >         printf("count %d\n", count);
> >         for (i = 0; i<  count; i++)
> >             printf(" %s\n", ippGetString(media, i, NULL));
> >     } else {
> >         printf("FindDestSupported Request failed %s\n",
> > cupsLastErrorString());
> >     }
> > }
> >
> > ----------------------------citing----------
> > dest name Ricoh-Aficio-MP-5002
> > CopyDestInfo Request failed successful-ok
> > FindDestSupported Request failed Invalid argument
> > ----------------
> > I am not sure if cupsCopyDestInfo() failed or not . The manual does not
> > say the return value if there is error. cupsGetLastErrorString()
> > conveys
> > there is no error yet "info" is NULL.
> >
> > Could you please suggest as to what else is going wrong?
> > I could not find "_cups_dinfo_s" structure definition in
> > https://www.cups.org/doc/cupspm.html#cups_dinfo_t.
> > Also, cupsFindDestSupported() manual shows "Find the default value(s)
> > for
> > the given option." which is same as cupsFindDestDefault(). I think the
> > former should be texted as "Find supported value(s) for the given
> > option".
> > Regards
> > Prasanta
> >
> > On Mon, Jul 31, 2017 at 7:11 PM, Michael Sweet<msweet at apple.com>
> > wrote:
> > You can't initialize a cups_dest_t structure directly like that and
> > have
> > it work.
> >
> > Use:
> >
> >     cups_dest_t *dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, name,
> > NULL);
> > Then cupsCopyDestInfo will have the information it needs to get the
> > supported media for you...
> >
> >
> > On Jul 31, 2017, at 6:01 AM, My Sadhukhan<psadhukhan at gmail.com>
> > wrote:
> > Hi All,
> >
> > I was trying to find the supported media for a particular printer
> > using
> > non-ppd based API but am encountering a problem.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > *void getMedia(char *name){    cups_dest_t dest;    dest.name
> > <http://dest.name>  = name;    dest.instance = name;
> > dest.is_default
> > =
> > 0;    cups_dinfo_t *info = cupsCopyDestInfo(CUPS_HTTP_DEFAULT,
> > &dest);;
> > if (info == NULL) {        printf("CopyDestInfo Request failed %s\n",
> > cupsLastErrorString());    }    ipp_attribute_t *media =
> > cupsFindDestSupported(CUPS_HTTP_DEFAULT,
> > &dest, info, CUPS_MEDIA);    if (media != NULL) {        int i,
> > count =
> > ippGetCount(media);        printf("count %d\n", count);        for
> > (i =
> > 0;
> > i<  count; i++)            printf(" %s\n", ippGetString(media, i,
> > NULL));    } else {        printf("FindDestSupported Request failed
> > %s\n",
> > cupsLastErrorString());    }}int main(void){
> > getMedia("Ricoh-Aficio-MP-5002");*
> > *}*
> >
> > I am getting
> > -----------
> > CopyDestInfo Request failed (null)
> > FindDestSupported Request failed Invalid argument
> > -----------
> >
> > Earlier, I was using
> > char filename = cupsGetPPD("Ricoh-Aficio-MP-5002");
> > ppd_file_t *ppd = ppdOpenFile(filename);
> > ppd_option_t *optionPage = ppdFindOption(ppd, "PageSize") and get
> > optionPage->choices->text
> > to get the below supported media size information obtained from that
> > printer ppd.
> > That is, in* /etc/cups/ppd/Ricoh-Aficio-MP-5002.ppd*,
> > I have this and I am interested in getting "A3", "A4", "A5", "A6",
> > "B4",
> > "B5"..."EngQuatro.FullBleed" etc.
> >
> > but now, since ppd API is deprecated, I want to use the new IPP-based
> > api.
> > Could anyone suggest what I need to use in above code?
> >
> > *%========== Information About Media Sizes ==========
> >
> > *DefaultImageableArea: A4
> > *ImageableArea A3/A3: "12 12 830 1179"
> > *ImageableArea A4/A4: "12 12 583 830"
> > *ImageableArea A5/A5: "12 12 408 583"
> > *ImageableArea A6/A6: "12 12 285 408"
> > *ImageableArea B4/B4 (JIS): "12 12 717 1020"
> > *ImageableArea B5/B5 (JIS): "12 12 504 717"
> > *ImageableArea B6/B6 (JIS): "12 12 351 504"
> > *ImageableArea Legal/Legal: "12 12 600 996"
> > *ImageableArea GovernmentLG/8.25x14: "12 12 582 996"
> > *ImageableArea EngQuatro/8x10: "12 12 564 708"
> > *ImageableArea GLT/8x10.5: "12 12 564 744"
> > *ImageableArea Letter/Letter: "12 12 600 780"
> > *ImageableArea Statement/5.5x8.5: "12 12 384 600"
> > *ImageableArea F/8x13: "12 12 564 924"
> > *ImageableArea Folio/8.25x13: "12 12 583 923"
> > *ImageableArea FanFoldGermanLegal/8.5x13: "12 12 600 924"
> > *ImageableArea Tabloid/11x17: "12 12 780 1212"
> > *ImageableArea 12x18/12x18: "12 12 852 1284"
> > *ImageableArea 11x15/11x15: "12 12 780 1068"
> > *ImageableArea 10x14/10x14: "12 12 708 996"
> > *ImageableArea 10x15/10x15: "12 12 708 1068"
> > *ImageableArea 11x14/11x14: "12 12 780 996"
> > *ImageableArea Executive/Executive: "12 12 510 744"
> > *ImageableArea Env10/Com10 Env.: "12 12 285 672"
> > *ImageableArea EnvMonarch/Monarch Env.: "12 12 267 528"
> > *ImageableArea EnvC5/C5 Env.: "12 12 447 637"
> > *ImageableArea EnvC6/C6 Env.: "12 12 311 447"
> > *ImageableArea DLEnv/DL Env.: "12 12 299 611"
> > *ImageableArea 8Kai/8K: "12 12 745 1094"
> > *ImageableArea 16Kai/16K: "12 12 541 745"
> > *ImageableArea A3.FullBleed/A3 (Full Bleed): "0 0 842 1190"
> > *ImageableArea A4.FullBleed/A4 (Full Bleed): "0 0 595 841"
> > *ImageableArea A5.FullBleed/A5 (Full Bleed): "0 0 420 594"
> > *ImageableArea A6.FullBleed/A6 (Full Bleed): "0 0 297 419"
> > *ImageableArea B4.FullBleed/B4 (JIS) (Full Bleed): "0 0 729 1031"
> > *ImageableArea B5.FullBleed/B5 (JIS) (Full Bleed): "0 0 516 728"
> > *ImageableArea B6.FullBleed/B6 (JIS) (Full Bleed): "0 0 363 515"
> > *ImageableArea Legal.FullBleed/Legal (Full Bleed): "0 0 612 1007"
> > *ImageableArea GovernmentLG.FullBleed/8.25x14 (Full Bleed): "0 0 594
> > 1007"
> > *ImageableArea EngQuatro.FullBleed/8x10 (Full Bleed): "0 0 576 719"
> > ...
> > ..
> >
> > Thanks&  Regards
> >
> > Prasanta
> > _______________________________________________
> > cups-devel mailing list
> > cups-devel at cups.org
> > https://lists.cups.org/mailman/listinfo/cups-devel
> > _________________________________________________________
> > Michael Sweet, Senior Printing System Engineer
> >
> > _______________________________________________
> > cups-devel mailing list
> > cups-devel at cups.org
> > https://lists.cups.org/mailman/listinfo/cups-devel
> >
> >
> > _______________________________________________
> > cups-devel mailing list
> > cups-devel at cups.org
> > https://lists.cups.org/mailman/listinfo/cups-devel
> > _________________________________________________________
> > Michael Sweet, Senior Printing System Engineer
> >
> > _______________________________________________
> > cups-devel mailing list
> > cups-devel at cups.org
> > https://lists.cups.org/mailman/listinfo/cups-devel
> >
> >
> > _______________________________________________
> > cups-devel mailing list
> > cups-devel at cups.org
> > https://lists.cups.org/mailman/listinfo/cups-devel
> >
>
> _________________________________________________________
> Michael Sweet, Senior Printing System Engineer
>
>


More information about the cups-devel mailing list