[cairo] printing text on to a PDF/PS document using cairo

rush ta anjutagtk at gmail.com
Fri Oct 28 18:47:16 PDT 2005


hi...

I know this is a repeat question but have been stuck on this for 4-5 days...
pls b considerate...

I have been trying to print text on to a PDF/PS document using cairo..(Have
attached my code below...)

Am using the code from the example of pdf-surface create..
I have only substituted the arc code with text one...
My code compiles & runs fine..

But the pdf doc created doesn't display any text...(its just plain white)...

Where am I going wrong...

Also I have to print a lot of text on the pdf (table of 6 col X 30 rows), do
I have to use cairo_glyph_t ,cairo_show_glyphs() .... ??

And for printing the text onto the PDF/PS do I have to use
cairo_pdf_surface_create_for _stream ()......

pls reply I have had only one answer to my previous mail.

bye
rushi

//basket.c
/* Author: Carl D. Worth <cworth at isi.edu> */

#include <cairo.h>
#include <cairo-ps.h>
#include <math.h>

void
draw (cairo_t *cr);

#define X_INCHES 8
#define Y_INCHES 3

#define FILENAME "basket.ps <http://basket.ps/>"

int
main (void)
{
cairo_surface_t *surface;
cairo_t *cr;
FILE *file;

file = fopen (FILENAME, "w");
if (file == NULL) {
fprintf (stderr, "Failed to open file %s for writing.\n", FILENAME);
return 1;
}

surface = cairo_ps_surface_create (FILENAME,
X_INCHES * 72.0,
Y_INCHES * 72.0);

cr = cairo_create (surface);

draw (cr);
cairo_show_page (cr);

cairo_destroy (cr);

cairo_surface_destroy(surface);

fclose (file);

return 0;
}

void
draw (cairo_t *cr)
{
cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size(cr,72) ;
cairo_set_source_rgb(cr,0,0,0) ;
cairo_move_to(cr,20,100) ;
cairo_show_text(cr,"Hello world !") ;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/cairo/attachments/20051029/ef30599a/attachment.html


More information about the cairo mailing list