Skip to content

Instantly share code, notes, and snippets.

@mxcd
Created November 7, 2015 12:28
Show Gist options
  • Save mxcd/90254afa3cfa5222e5a0 to your computer and use it in GitHub Desktop.
Save mxcd/90254afa3cfa5222e5a0 to your computer and use it in GitHub Desktop.
//
// main.m
// LeitzUnixPrinitgExample
//
// Created by Olga Fedorechko on 11/3/15.
// Copyright © 2015 Esseslte IPR AB. All rights reserved.
//
#include <cups/cups.h>
#include <cups/ppd.h>
#include <stdio.h>
#define FILE_PATH "../Resources/test.pdf"
int main(int argc, char** argv)
{
char printer_name[256]={0};
// show printers list
cups_dest_t *dests;
int num_dests = cupsGetDests(&dests);
for (int i=0; i<num_dests; ++i)
{
cups_dest_t *dest = dests + i;
if (dest->instance)
{
printf("#%d: %s/%s\n", i, dest->name, dest->instance);
}
else
{
printf("#%d: %s\n", i, dest->name);
}
}
if (num_dests < 1)
{
printf("no printers discovered. exit.\n");
return 0;
}
// choose printer
int prn_number = 0;
if (num_dests != 1)
{
printf("Choose number of printer: \n");
int ch = 0;
ch = getchar();
prn_number = ch - '0';
if (prn_number < 0 || prn_number >= num_dests)
{
printf("exit.");
return 0;
}
}
cups_dest_t *dest = dests + prn_number;
strcpy(printer_name, dest->name);
for (int i=0; i<dest->num_options; ++i)
{
printf("#%02d: '%s'='%s'\n", i, dest->options[i].name, dest->options[i].value);
}
int num_options = 0;
cups_option_t* options = NULL;
/*
orientation-requested=3 - portrait orientation (no rotation)
orientation-requested=4 - landscape orientati
on (90 degrees)
orientation-requested=5 - reverse landscape or seascape orientation (270 degrees)
orientation-requested=6 - reverse portrait or upside-down orientation (180 degrees)
*/
num_options = cupsAddOption("orientation-requested", "3", num_options, &options);
num_options = cupsAddOption("PageSize", "StandardAddressLabel", num_options, &options);
// uncomment this to print on continuous
/*
num_options = cupsAddOption("PageSize", "Continuous70030001", num_options, &options);
num_options = cupsAddOption("ContinuousMedia", "ON", num_options, &options);
num_options = cupsAddOption("ContinuousPaperLength", "331", num_options, &options); width in points / 72 * 300
*/
cupsPrintFile(printer_name, FILE_PATH, "Job name", num_options, options);
cupsFreeOptions(num_options, options);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment