#include #include #include cairo_status_t stream_cairo_write (void *closure, const unsigned char *data, unsigned int length) { FILE *fp = closure; int i; for (i = 0; i < length; i++) fputc (data[i], fp); return CAIRO_STATUS_SUCCESS; } int main (void) { cairo_surface_t *surface; cairo_t *cr; cairo_status_t status; FILE *fp; fp = fopen ("test.pdf", "w"); surface = cairo_pdf_surface_create_for_stream (stream_cairo_write, fp, 792, 612); cr = cairo_create (surface); cairo_set_source_rgb (cr, 1.000000, 0.000000, 0.000000 ); cairo_move_to(cr,158.000000,487.000000); cairo_line_to(cr,158.000000,50.000000); cairo_line_to(cr,712.000000,50.000000); cairo_line_to(cr,712.000000,487.000000); cairo_close_path (cr); cairo_fill(cr); cairo_set_source_rgb (cr, 0.000000, 0.000000, 0.000000 ); cairo_move_to(cr,396.000000, 303.506000); cairo_show_text (cr, "h"); cairo_show_text (cr, "i"); status = cairo_status (cr); cairo_destroy (cr); if (status) { printf ("context reported an error: %s\n", cairo_status_to_string (status)); return 1; } cairo_surface_flush(surface); cairo_surface_finish(surface); status = cairo_surface_status (surface); cairo_surface_destroy (surface); if (status) { printf ("surface reported an error: %s\n", cairo_status_to_string (status)); return 1; } fclose (fp); return 0; }