Here is a little snippet that shows how to use Cairo module, to output pdf files. It is basically the same as the demo script which comes with the module, but the output is pdf instead of png. (The docs don't show how to do it, because it is still a new feature and the API may change). But here it is. :-)
#!/usr/bin/perl use strict; use warnings; use Cairo; # requires you have the latest Cairo c-libs # built with --enable-pdf use constant { IMG_WIDTH => 640, IMG_HEIGHT => 480, M_PI => 3.14159265, }; die "pdf backend not supported" unless (Cairo::HAS_PDF_SURFACE); my $pdf_out = "$0.pdf"; my $surf = Cairo::PdfSurface->create ($pdf_out, IMG_WIDTH, IMG_HEIGHT) +; my $cr = Cairo::Context->create ($surf); $cr->rectangle (0, 0, IMG_WIDTH, IMG_HEIGHT); $cr->set_source_rgba (1, 1, 1, 0.5); $cr->fill; # black $cr->save; $cr->set_source_rgba (0, 0, 0, 0.5); $cr->translate (IMG_WIDTH / 2, IMG_HEIGHT - (IMG_HEIGHT / 4)); do_star (); $cr->restore; # red $cr->save; $cr->set_source_rgba (1, 0, 0, 0.5); $cr->translate (IMG_WIDTH / 2, IMG_HEIGHT / 4); do_star (); $cr->restore; # green $cr->save; $cr->set_source_rgba (0, 1, 0, 0.5); $cr->translate (IMG_WIDTH / 4, IMG_HEIGHT / 2); do_star (); $cr->restore; # blue $cr->save; $cr->set_source_rgba (0, 0, 1, 0.5); $cr->translate (IMG_WIDTH - (IMG_WIDTH / 4), IMG_HEIGHT / 2); do_star (); $cr->restore; $cr->show_page; ############################################################### sub do_star { my $mx = IMG_WIDTH / 3.0; my $count = 100; foreach (0..$count-1) { $cr->new_path; $cr->move_to (0, 0); $cr->rel_line_to (-$mx, 0); $cr->stroke; $cr->rotate ((M_PI * 2) / $count); } }

In reply to Gtk2-Cairo-pdf output by zentara

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.