Hi all.

Despite making some decent progress in other areas, I'm banging my head against a brick wall on something simple: rendering text over a solid rectange.

my $pdf = PDF::API2->new;

$self->{fonts} = {
Helvetica => {
Bold => $self->{pdf}->corefont('Helvetica-Bold', -encoding => 'latin1'),
Roman => $self->{pdf}->corefont('Helvetica', -encoding => 'latin1'),
Italic => $self->{pdf}->corefont('Helvetica-Oblique', -encoding => 'latin1'),
},
Times => {
Bold => $self->{pdf}->corefont('Times-Bold', -encoding => 'latin1'),
Roman => $self->{pdf}->corefont('Times', -encoding => 'latin1'),
Italic => $self->{pdf}->corefont('Times-Italic', -encoding => 'latin1'),
}
};


my $page = $pdf->page;

$page->mediabox(A4_x, A4_y); # from constants for A4 size

# The blue box
my $blue_box = $page->gfx;
$blue_box->fillcolor('blue');
$blue_box->rect(
               20 * mm,            # left
               A4_y - (100 * mm),    # bottom
               A4_x - (40 * mm),        # width
               80 * mm                # height
          );

$blue_box->fill;

# The text in the blue box
$txt = $page->text;
$txt->translate( $self->{report}->{header}->{x} * mm, A4_y - ( $self->{report}->{header}->{y} * mm ) );
$txt->font( $self->{fonts}->{Times}->{Bold}, 18 );
$txt->fillcolor("green");
$txt->text($self->{report}->{header}->{text});


$self->{pdf}->saveas("test.pdf");
$self->{pdf}->end();

---

If I run the above code, I get a blue box at the top of the page, and nothing else.

If I comment out the 'blue box' part ( down to $blue_box->fill ) and run the code, I get the correct text ( coming from $self->{report}->{header}->{text} ).

Why does my text only appear if I *don't* create the blue box? Is it being rendered underneath the box or something? I was under the impression that anything you render gets placed on *top* of anything that currently exists in the PDF.

Dan

--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: [EMAIL PROTECTED]
website: http://www.nusconsulting.com.au

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to