-
Notifications
You must be signed in to change notification settings - Fork 6
/
PrintLabel.cpp
73 lines (61 loc) · 1.92 KB
/
PrintLabel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <cups/cups.h>
#include <cups/ppd.h>
#include <string>
#include <stdio.h>
#include <map>
#include <exception>
using namespace std;
const char* PrinterName = "DYMO_LabelWriter_450";
class Error: public exception
{
public:
Error(const string& Message): exception(), Message_(Message) {}
virtual ~Error() throw() {}
virtual const char* what() const throw() { return Message_.c_str(); }
private:
string Message_;
};
map <string, string> gPaperNames;
typedef pair<string, string> str_pair;
void print_printers(){
int i;
cups_dest_t *dests, *dest;
int num_dests = cupsGetDests(&dests);
for (i = num_dests, dest = dests; i > 0; i --, dest ++)
{
if (dest->instance)
printf("%s/%s\n", dest->name, dest->instance);
else
puts(dest->name);
}
}
int main(int argc, char** argv)
{
try
{
if (argc < 2)
throw Error("Usage: PrintLabel <ImageName> [<ImageName> ...]");
cout << "Printers:" << endl;
print_printers();
int num_options = 0;
cups_option_t* options = NULL;
//num_options = cupsAddOption("PageSize", "w162h90", num_options, &options); //11354 Multi-Purpose
num_options = cupsAddOption("PageSize", "w102h252", num_options, &options); //99012 Large address
//num_options = cupsAddOption("scaling", "100", num_options, &options);
//num_options = cupsAddOption("orientation-requested", "4", num_options, &options);
//num_options = cupsAddOption("DymoHalftoning", "ErrorDiffusion", num_options, &options);
//num_options = cupsAddOption("DymoPrintQuality", "Graphics", num_options, &options);
for (int i=1; i<argc; i++) {
cupsPrintFile(PrinterName, argv[i], "Label", num_options, options);
}
cupsFreeOptions(num_options, options);
return 0;
}
catch(std::exception& e)
{
fprintf(stderr, "%s", e.what());
fprintf(stderr, "\n");
return 1;
}
}