OrangeDrink has asked for the wisdom of the Perl Monks concerning the following question:

I have been using PDF::API2 to generate PDFs, and it has been a pleasent experience. My next step is to make different text in the PDF be different colors. I cannot figure out how to do this. The documentation on this module seems to be incomplete (or maybe I can't find it?).

Should I be using a different module to do this? If not, how can I do it with this one?

Replies are listed 'Best First'.
Re: Using PDF::API2 to create Colored Text
by Beatnik (Parson) on Aug 03, 2002 at 06:48 UTC
    Something like
    use strict; use PDF::API2; use PDF::API2::Util; my $pdf = PDF::API2->new('pagesize' => 'a4','compression'=>1); my $page = $pdf->page; my $font=$pdf->corefont('Helvetica',1); $font->encode('latin1'); my $txt=$page->text; $txt->compress; $txt->font($font,16); $txt->translate($x,$y); #Define coords here $txt->fillcolor(namecolor("darkorange")); #Define some other color her +e $txt->text("The quick brown fox jumps over the lazy dog"); $pdf->saveas('empty.pdf'); $pdf->end();
    should work... At least, it did for me :)

    Greetz
    Beatnik
    ...Perl is like sex: if you're doing it wrong, there's no fun to it.
Re: Using PDF::API2 to create Colored Text
by aseidas (Beadle) on Aug 03, 2002 at 01:03 UTC
    Hello, Take a look at PDF::API2::Color on CPAN, I have not used it but it looks like it might serve your needs.
    Aseidas