| | 116 | |
| | 117 | Printed successfully but rotated and enlarged |
| | 118 | |
| | 119 | Found an example of cups printing on stackoverflow.com. After compile the example for the 825 and after making several changing get it to work to programatically print a ticket. |
| | 120 | |
| | 121 | {{{ |
| | 122 | #include <stdio.h> |
| | 123 | #include <cairo.h> |
| | 124 | #include <cairo-ps.h> |
| | 125 | #include <cups/cups.h> |
| | 126 | |
| | 127 | #include "cairobmp.h" |
| | 128 | |
| | 129 | #define WIDTH 320 |
| | 130 | #define HEIGHT 500 |
| | 131 | |
| | 132 | |
| | 133 | #define TEST_BMP_FILENAME "/tmp/tkt9.bmp" |
| | 134 | |
| | 135 | |
| | 136 | int main(int argc, char** argv) { |
| | 137 | |
| | 138 | int n; |
| | 139 | |
| | 140 | char tmpFilepath[] = "/tmp/tktprtXXXXXX"; |
| | 141 | |
| | 142 | mkstemp(tmpFilepath); |
| | 143 | printf("tmpFilename [%s]\n", tmpFilepath); |
| | 144 | |
| | 145 | |
| | 146 | // cairo_surface_t* surface = cairo_ps_surface_create(tmpfilename, WIDTH, HEIGHT); |
| | 147 | cairo_surface_t* surface = cairo_image_surface_create(/*CAIRO_FORMAT_ARGB32*/ /*CAIRO_FORMAT_RGB24*/ CAIRO_FORMAT_A1, WIDTH, HEIGHT); |
| | 148 | printf("after surface create %d\n", cairo_surface_get_type(surface)); |
| | 149 | cairo_t *context = cairo_create(surface); |
| | 150 | |
| | 151 | |
| | 152 | LoadBMPToSurface("/usr/images/bird.bmp", surface, 0, 0); |
| | 153 | |
| | 154 | // draw some text |
| | 155 | cairo_select_font_face(context, "Arial Black", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); |
| | 156 | cairo_set_font_size(context, 30); |
| | 157 | int x = 20; |
| | 158 | int y = 140; |
| | 159 | cairo_move_to(context, x, y); |
| | 160 | cairo_show_text(context, "Item 1"); // the text we got as a parameter |
| | 161 | y += 30; |
| | 162 | cairo_move_to(context, x, y); |
| | 163 | cairo_show_text(context, "Item 2"); // the text we got as a parameter |
| | 164 | y += 30; |
| | 165 | cairo_move_to(context, x, y); |
| | 166 | cairo_show_text(context, "Item 3"); // the text we got as a parameter |
| | 167 | |
| | 168 | // draw a dotted box |
| | 169 | const double pattern[] = {15.0, 10.0}; |
| | 170 | cairo_set_dash(context, pattern, 2, 0); |
| | 171 | cairo_set_line_width(context, 5); |
| | 172 | cairo_rectangle(context, 5, 105, 280, 300); |
| | 173 | cairo_stroke(context); |
| | 174 | |
| | 175 | // finish up |
| | 176 | cairo_show_page(context); |
| | 177 | cairo_destroy(context); |
| | 178 | cairo_surface_flush(surface); |
| | 179 | |
| | 180 | CairoSurfaceToBMP(surface, /*"/tmp/tkt9.bmp"*/ tmpFilepath); |
| | 181 | |
| | 182 | // n = cairo_surface_write_to_png (surface, "/tmp/tkt.png"); |
| | 183 | // printf("write_to_png result %d\n", n); |
| | 184 | |
| | 185 | |
| | 186 | cairo_surface_destroy(surface); |
| | 187 | |
| | 188 | const char* printerName = cupsGetDefault(); |
| | 189 | printf("printer [%s]\n", printerName); |
| | 190 | |
| | 191 | // cupsGetDefault is returning NULL |
| | 192 | printerName = "STARSK1_311"; |
| | 193 | n = cupsPrintFile(printerName, tmpFilepath, "cairo PS", 0, NULL); |
| | 194 | // return value is job ID |
| | 195 | printf("cupsPrintFile result %d\n", n); |
| | 196 | |
| | 197 | //unlink(tmpFilepath); |
| | 198 | |
| | 199 | return 0; |
| | 200 | } |
| | 201 | |
| | 202 | }}} |
| | 203 | |
| | 204 | |
| | 205 | |