Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Get the amount of pages that needs to print



Hello List,

I successfully managed to count the printed pages with Cups:ipp.

Now I need the amaount of pages before the get printed. E.g. spool a job to queue that is in hold state.
And then I need to count the pages that are spooled to that job.


Thanks for any help.

Jürgen


Attached the code snippet for counting printed pages:

static const char *				/* O - Password or NULL */
cups_passwd_cb(const char *prompt)	/* I - Prompt */
{
//Always return NULL to indicate that no password is available...
  return (NULL);
}

- (UInt32) getPageCount:(NSString*)printerName
{
http_t *http; /* HTTP connection to server */
ipp_t *request, /* IPP Request */
*response; /* IPP Response */
ipp_attribute_t *attr; /* Current attribute */
cups_lang_t *language; /* Default language */
char uri[HTTP_MAX_URI],*job_name; /* printer-uri attribute */
int job_id; /* job-id attribute */


static const char *jattrs[] = /* Requested job attributes */
{
"job-id",
"job-name",
"job-media-sheets-completed",
};

cupsSetPasswordCB(cups_passwd_cb); //set allback, Make sure we don't ask for passwords...

//Try to connect to the server...
if ((http = httpConnect(cupsServer(), ippPort())) == NULL){
return 0;
}

snprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s";, [printerName cStringUsingEncoding:NSUTF8StringEncoding]);
//Build an IPP_GET_JOBS request, which requires the following
// * attributes:
// * attributes-charset
// * attributes-natural-language
// * requested-attributes
// * printer-uri
request = ippNew();

request->request.op.operation_id = IPP_GET_JOBS;
request->request.op.request_id = 1;

language = cupsLangDefault();
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, "attributes- charset", NULL, cupsLangEncoding(language));
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,"attributes- natural-language", NULL, language->language);
ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,"requested- attributes",(sizeof(jattrs) / sizeof(jattrs[0])), NULL, jattrs);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,"printer-uri", NULL, uri);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,"which- jobs", NULL, "completed");

//Do the request and get back a response...

if ((response = cupsDoRequest(http, request, "/")) == NULL){
httpClose(http);
return 0;
}

if (response->request.status.status_code >= IPP_OK_CONFLICT){
ippDelete(response);
httpClose(http);
return 0;
}
// Process the jobs...

long pagecount=0;
for (attr = response->attrs; attr != NULL; attr = attr->next){
// Skip leading attributes until we hit a job...
while (attr != NULL && attr->group_tag != IPP_TAG_JOB){
attr = attr->next;
}
if (attr == NULL)
break;
//job-media-sheets-completed
while (attr != NULL && attr->group_tag == IPP_TAG_JOB){
if (attr->name == NULL){
attr = attr->next;
break;
}


if (strcmp(attr->name, "job-id") == 0 && attr->value_tag == IPP_TAG_INTEGER)
job_id = attr->values[0].integer;

if (strcmp(attr->name, "job-name") == 0 && attr->value_tag == IPP_TAG_NAME)
job_name = attr->values[0].string.text;

if (strcmp(attr->name, "job-media-sheets-completed") == 0 && attr- >value_tag == IPP_TAG_INTEGER)
pagecount += attr->values[0].integer;

attr = attr->next;
}

if (attr == NULL)
break;
}

ippDelete(response);
return pagecount;
}


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Printing mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/printing/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.